diff --git a/crates/angular_conformance/README.md b/crates/angular_conformance/README.md index d44d7d17c..295bd347f 100644 --- a/crates/angular_conformance/README.md +++ b/crates/angular_conformance/README.md @@ -4,7 +4,7 @@ A conformance testing framework that validates the oxc Angular compiler implemen ## Overview -This crate extracts test cases from Angular's TypeScript spec files and runs them against the Rust implementation to ensure compatibility. It currently passes **1,430** of **1,456** extracted test assertions (the rest cover other new 22.3 features not yet ported) against Angular **v22.3.0-next.4**. +This crate extracts test cases from Angular's TypeScript spec files and runs them against the Rust implementation to ensure compatibility. It currently passes **1,432** of **1,456** extracted test assertions (the rest cover other new 22.3 features not yet ported) against Angular **v22.3.0-next.4**. ## Architecture diff --git a/crates/angular_conformance/snapshots/angular.snap.md b/crates/angular_conformance/snapshots/angular.snap.md index 812e9a991..c3a1c91bf 100644 --- a/crates/angular_conformance/snapshots/angular.snap.md +++ b/crates/angular_conformance/snapshots/angular.snap.md @@ -7,7 +7,7 @@ | ast_serializer | 6 | 0 | 0 | 0 | 6 | 100.0% | | ast_spans | 55 | 0 | 0 | 0 | 55 | 100.0% | | expression_lexer | 154 | 0 | 0 | 0 | 154 | 100.0% | -| expression_parser | 390 | 10 | 3 | 0 | 403 | 96.8% | +| expression_parser | 392 | 10 | 1 | 0 | 403 | 97.3% | | expression_serializer | 44 | 0 | 0 | 0 | 44 | 100.0% | | html_lexer | 291 | 6 | 0 | 0 | 297 | 98.0% | | html_parser | 89 | 1 | 0 | 0 | 90 | 98.9% | @@ -15,7 +15,7 @@ | r3_transform | 180 | 4 | 0 | 0 | 184 | 97.8% | | shadow_css | 185 | 2 | 0 | 0 | 187 | 98.9% | | style_parser | 15 | 0 | 0 | 0 | 15 | 100.0% | -| **Total** | **1430** | **23** | **3** | **0** | **1456** | **98.2%** | +| **Total** | **1432** | **23** | **1** | **0** | **1456** | **98.4%** | ## Failed Tests @@ -159,22 +159,6 @@ Error containing: Unterminated template literal No errors ``` -#### should parse a regular expression literal that ends with an escaped slash: CheckBinding { input: "/^https?:\\/\\//", expected: None } -Path: `parser/parseAction/regular expression literals/should parse a regular expression literal that ends with an escaped slash` - -**Error:** -``` -Unexpected parse errors: ["Lexer Error: Unterminated regular expression at column 12 in expression [/^https?:\\/\\]", "Unexpected token 'Lexer Error: Unterminated regular expression at column 12 in expression [/^https?:\\/\\]' at column 13 in [/^https?:\\/\\//]"] -``` - -#### should parse a regular expression literal that ends with an escaped slash: CheckBinding { input: "url.replace(/^\\//, \"\") //comment", expected: Some("url.replace(/^\\//, \"\")") } -Path: `parser/parseAction/regular expression literals/should parse a regular expression literal that ends with an escaped slash` - -**Error:** -``` -Unexpected parse errors: ["Lexer Error: Unterminated regular expression at column 15 in expression [url.replace(/^\\]", "Missing expected ) at column 16"] -``` - ### html_lexer #### should parse a processing instruction: HtmlLexerTest { input: "", test_type: HumanizeParts, expected: [Array [String("TokenType.PROCESSING_INSTRUCTION"), String("xml version=\"1.0\" encoding=\"UTF-8\"")], Array [String("TokenType.EOF")]], options: None } diff --git a/crates/angular_conformance/src/subsystems/ast_spans.rs b/crates/angular_conformance/src/subsystems/ast_spans.rs index 31677fe45..08edf248c 100644 --- a/crates/angular_conformance/src/subsystems/ast_spans.rs +++ b/crates/angular_conformance/src/subsystems/ast_spans.rs @@ -1,7 +1,5 @@ use oxc_allocator::Allocator; -use oxc_angular_compiler::ast::expression::{ - AbsoluteSourceSpan, AngularExpression, BinaryOperator, -}; +use oxc_angular_compiler::ast::expression::{AngularExpression, BinaryOperator}; use oxc_angular_compiler::ast::r3::{ R3BoundText, R3BoundaryErrorBlock, R3DeferredBlock, R3Element, R3ForLoopBlock, R3IfBlock, R3SwitchBlock, R3Template, R3TemplateAttr, R3Visitor, visit_all, @@ -174,19 +172,32 @@ impl<'a> ExpressionSourceCollector<'a> { } } - /// Extract source text from an absolute span - fn extract_source(&self, span: AbsoluteSourceSpan) -> Option { - let start = span.start as usize; - let end = span.end as usize; - if start <= end && end <= self.source.len() { - Some(self.source[start..end].to_string()) + fn record_expression(&mut self, expr: &AngularExpression<'_>) { + self.sources.push(vec![unparse_expression(expr)]); + } + + fn record_source(&mut self, expr: &AngularExpression<'_>) { + if let Some(source) = self.extract_expression_source(expr) { + self.sources.push(vec![source]); + } + } + + // Event expressions are parsed from decoded attribute values, so their offsets + // cannot be used to slice the original HTML when it contains character references. + fn visit_event_handler(&mut self, handler: &AngularExpression<'_>) { + if self.extract_sub_expressions { + self.collect_sub_expressions(handler, Self::record_expression); } else { - None + self.record_expression(handler); } } /// Collect sub-expressions from an expression based on its type - fn collect_sub_expressions(&mut self, expr: &AngularExpression<'_>) { + fn collect_sub_expressions( + &mut self, + expr: &AngularExpression<'_>, + record: fn(&mut Self, &AngularExpression<'_>), + ) { match expr { // Binary: for assignments, only collect from right side; for others, both sides AngularExpression::Binary(bin) => { @@ -194,169 +205,120 @@ impl<'a> ExpressionSourceCollector<'a> { // For assignment expressions (property write), only collect the value (right side) // unless left is a keyed expression which has interesting sub-expressions if let AngularExpression::KeyedRead(_) = &bin.left { - self.collect_sub_expressions(&bin.left); + self.collect_sub_expressions(&bin.left, record); } - self.collect_sub_expressions(&bin.right); + self.collect_sub_expressions(&bin.right, record); } else { // For other binary operators, collect from both sides - self.collect_sub_expressions(&bin.left); - self.collect_sub_expressions(&bin.right); + self.collect_sub_expressions(&bin.left, record); + self.collect_sub_expressions(&bin.right, record); } } // Conditional: collect condition, true, and false expressions AngularExpression::Conditional(cond) => { - if let Some(s) = self.extract_source(cond.condition.source_span()) { - self.sources.push(vec![s]); - } - if let Some(s) = self.extract_source(cond.true_exp.source_span()) { - self.sources.push(vec![s]); - } - if let Some(s) = self.extract_source(cond.false_exp.source_span()) { - self.sources.push(vec![s]); - } + record(self, &cond.condition); + record(self, &cond.true_exp); + record(self, &cond.false_exp); } // Chain: collect each expression in the chain AngularExpression::Chain(chain) => { for child in &chain.expressions { - if let Some(s) = self.extract_source(child.source_span()) { - self.sources.push(vec![s]); - } + record(self, child); } } // PropertyRead: output the receiver's source or recurse to find ImplicitReceiver AngularExpression::PropertyRead(prop) => { if self.find_implicit_receiver { // Recurse to find ImplicitReceiver and output its (empty) span - self.collect_sub_expressions(&prop.receiver); + self.collect_sub_expressions(&prop.receiver, record); } else { - // Output the receiver's span directly - match &prop.receiver { - AngularExpression::ImplicitReceiver(_) => { - // For ImplicitReceiver, output empty string - self.sources.push(vec![String::new()]); - } - receiver => { - if let Some(s) = self.extract_source(receiver.source_span()) { - self.sources.push(vec![s]); - } - } + if matches!(&prop.receiver, AngularExpression::ImplicitReceiver(_)) { + self.sources.push(vec![String::new()]); + } else { + record(self, &prop.receiver); } } } // SafePropertyRead: output the receiver's source (for safe method call tests) AngularExpression::SafePropertyRead(prop) => { - if let Some(s) = self.extract_source(prop.receiver.source_span()) { - self.sources.push(vec![s]); - } + record(self, &prop.receiver); } // KeyedRead: collect the key AngularExpression::KeyedRead(keyed) => { - if let Some(s) = self.extract_source(keyed.key.source_span()) { - self.sources.push(vec![s]); - } + record(self, &keyed.key); } // SafeKeyedRead: collect the key AngularExpression::SafeKeyedRead(keyed) => { - if let Some(s) = self.extract_source(keyed.key.source_span()) { - self.sources.push(vec![s]); - } + record(self, &keyed.key); } // Call: collect from SafePropertyRead receiver (for safe method calls), then arguments AngularExpression::Call(call) => { // For safe method calls like prop?.safe(), collect from SafePropertyRead receiver - if let AngularExpression::SafePropertyRead(safe_prop) = &call.receiver - && let Some(s) = self.extract_source(safe_prop.receiver.source_span()) - { - self.sources.push(vec![s]); + if let AngularExpression::SafePropertyRead(safe_prop) = &call.receiver { + record(self, &safe_prop.receiver); } // Collect arguments for arg in &call.args { - if let Some(s) = self.extract_source(arg.source_span()) { - self.sources.push(vec![s]); - } + record(self, arg); } } // SafeCall: collect receiver (for safe method calls) AngularExpression::SafeCall(call) => { // First collect the receiver - if let Some(s) = self.extract_source(call.receiver.source_span()) { - self.sources.push(vec![s]); - } + record(self, &call.receiver); // Then collect arguments for arg in &call.args { - if let Some(s) = self.extract_source(arg.source_span()) { - self.sources.push(vec![s]); - } + record(self, arg); } } // LiteralArray: collect elements AngularExpression::LiteralArray(arr) => { for elem in &arr.expressions { - if let Some(s) = self.extract_source(elem.source_span()) { - self.sources.push(vec![s]); - } + record(self, elem); } } // LiteralMap: collect values AngularExpression::LiteralMap(map) => { for value in &map.values { - if let Some(s) = self.extract_source(value.source_span()) { - self.sources.push(vec![s]); - } + record(self, value); } } // PrefixNot: collect the operand AngularExpression::PrefixNot(not) => { - if let Some(s) = self.extract_source(not.expression.source_span()) { - self.sources.push(vec![s]); - } + record(self, ¬.expression); } // Unary: collect the operand AngularExpression::Unary(unary) => { - if let Some(s) = self.extract_source(unary.expr.source_span()) { - self.sources.push(vec![s]); - } + record(self, &unary.expr); } // NonNullAssert: collect the expression AngularExpression::NonNullAssert(nna) => { - if let Some(s) = self.extract_source(nna.expression.source_span()) { - self.sources.push(vec![s]); - } + record(self, &nna.expression); } // BindingPipe: collect the input expression AngularExpression::BindingPipe(pipe) => { - if let Some(s) = self.extract_source(pipe.exp.source_span()) { - self.sources.push(vec![s]); - } + record(self, &pipe.exp); } // Interpolation: recursively collect from each expression AngularExpression::Interpolation(interp) => { for expr in &interp.expressions { - self.collect_sub_expressions(expr); + self.collect_sub_expressions(expr, record); } } // LiteralPrimitive: output the value (for binary operands, array elements, etc.) - AngularExpression::LiteralPrimitive(lit) => { - if let Some(s) = self.extract_source(lit.source_span) { - self.sources.push(vec![s]); - } - } + AngularExpression::LiteralPrimitive(_) => record(self, expr), // Empty expression or ImplicitReceiver: output empty string AngularExpression::Empty(_) | AngularExpression::ImplicitReceiver(_) => { self.sources.push(vec![String::new()]); } // SpreadElement: collect the expression being spread AngularExpression::SpreadElement(spread) => { - if let Some(s) = self.extract_source(spread.expression.source_span()) { - self.sources.push(vec![s]); - } + record(self, &spread.expression); } // ArrowFunction: collect the body and parameter spans AngularExpression::ArrowFunction(arrow) => { // Collect the body expression - if let Some(s) = self.extract_source(arrow.body.source_span()) { - self.sources.push(vec![s]); - } + record(self, &arrow.body); } // Terminal expressions - no sub-expressions to extract AngularExpression::ThisReceiver(_) @@ -372,12 +334,11 @@ impl<'a> ExpressionSourceCollector<'a> { /// Process an expression - either extract the whole thing or its sub-expressions fn process_expression(&mut self, expr: &AngularExpression<'_>) { if self.extract_sub_expressions { - self.collect_sub_expressions(expr); + self.collect_sub_expressions(expr, Self::record_source); } else if self.use_unparser { - let unparsed = unparse_expression(expr); - self.sources.push(vec![unparsed]); - } else if let Some(source) = self.extract_expression_source(expr) { - self.sources.push(vec![source]); + self.record_expression(expr); + } else { + self.record_source(expr); } } } @@ -420,7 +381,7 @@ impl<'b> R3Visitor<'b> for ExpressionSourceCollector<'b> { self.process_expression(expr); } } else if self.extract_sub_expressions { - self.collect_sub_expressions(&attr.value); + self.collect_sub_expressions(&attr.value, Self::record_source); } else if let Some(ref value_span) = attr.value_span { let start = value_span.start as usize; let end = value_span.end as usize; @@ -431,19 +392,7 @@ impl<'b> R3Visitor<'b> for ExpressionSourceCollector<'b> { } // Visit bound outputs (events) for event in &element.outputs { - if self.extract_sub_expressions { - self.collect_sub_expressions(&event.handler); - } else if self.use_unparser { - // Use unparser for proper formatting (e.g., "foo(); bar();" with space after semicolon) - let unparsed = unparse_expression(&event.handler); - self.sources.push(vec![unparsed]); - } else { - let start = event.handler_span.start as usize; - let end = event.handler_span.end as usize; - if end <= self.source.len() { - self.sources.push(vec![self.source[start..end].to_string()]); - } - } + self.visit_event_handler(&event.handler); } } // Visit children @@ -466,7 +415,7 @@ impl<'b> R3Visitor<'b> for ExpressionSourceCollector<'b> { self.process_expression(expr); } } else if self.extract_sub_expressions { - self.collect_sub_expressions(&attr.value); + self.collect_sub_expressions(&attr.value, Self::record_source); } else if let Some(ref value_span) = attr.value_span { let start = value_span.start as usize; let end = value_span.end as usize; @@ -483,19 +432,7 @@ impl<'b> R3Visitor<'b> for ExpressionSourceCollector<'b> { } // Visit bound outputs for event in &template.outputs { - if self.extract_sub_expressions { - self.collect_sub_expressions(&event.handler); - } else if self.use_unparser { - // Use unparser for proper formatting - let unparsed = unparse_expression(&event.handler); - self.sources.push(vec![unparsed]); - } else { - let start = event.handler_span.start as usize; - let end = event.handler_span.end as usize; - if end <= self.source.len() { - self.sources.push(vec![self.source[start..end].to_string()]); - } - } + self.visit_event_handler(&event.handler); } // Visit children visit_all(self, &template.children); @@ -545,3 +482,27 @@ impl<'b> R3Visitor<'b> for ExpressionSourceCollector<'b> { } } } + +#[cfg(test)] +mod tests { + use super::AstSpansRunner; + + #[test] + fn event_expression_text_uses_decoded_attribute_values() { + for tag in ["button", "ng-template"] { + let html = format!(r#"<{tag} (click)="save("x") // tail">"#); + for (sub_expressions, expected) in [(false, r#"save("x")"#), (true, r#""x""#)] { + let texts = AstSpansRunner::new().extract_expression_sources( + &html, + None, + sub_expressions, + false, + false, + false, + false, + ); + assert_eq!(texts, [vec![expected]], "{html}"); + } + } + } +} diff --git a/crates/oxc_angular_compiler/src/parser/expression/mod.rs b/crates/oxc_angular_compiler/src/parser/expression/mod.rs index f7d65587b..3e2120468 100644 --- a/crates/oxc_angular_compiler/src/parser/expression/mod.rs +++ b/crates/oxc_angular_compiler/src/parser/expression/mod.rs @@ -52,20 +52,17 @@ pub fn find_comment_start(input: &str) -> Option { let bytes = input.as_bytes(); let mut outer_quote: Option = None; - for i in 0..bytes.len().saturating_sub(1) { - let ch = bytes[i]; - let next_ch = bytes[i + 1]; - - // Check for // outside of quotes - if ch == b'/' && next_ch == b'/' && outer_quote.is_none() { - return Some(i); - } - - // Track quote state - if outer_quote == Some(ch) { - outer_quote = None; - } else if outer_quote.is_none() && (ch == b'\'' || ch == b'"' || ch == b'`') { - outer_quote = Some(ch); + let mut chars = bytes.iter().copied().enumerate(); + while let Some((i, ch)) = chars.next() { + match ch { + // Angular's _commentStart skips escaped slashes and quotes alike. + b'\\' => { + chars.next(); + } + b'/' if outer_quote.is_none() && bytes.get(i + 1) == Some(&b'/') => return Some(i), + _ if outer_quote == Some(ch) => outer_quote = None, + b'\'' | b'"' | b'`' if outer_quote.is_none() => outer_quote = Some(ch), + _ => {} } } diff --git a/crates/oxc_angular_compiler/src/parser/expression/parser.rs b/crates/oxc_angular_compiler/src/parser/expression/parser.rs index 8b093708a..7b5aa10f2 100644 --- a/crates/oxc_angular_compiler/src/parser/expression/parser.rs +++ b/crates/oxc_angular_compiler/src/parser/expression/parser.rs @@ -20,8 +20,8 @@ use crate::ast::expression::{ }; use crate::util::ParseError; -use super::TemplateBindingParseResult; use super::lexer::{Lexer, Token}; +use super::{TemplateBindingParseResult, strip_comments}; /// Angular's error for an interpolation with a blank expression (`{{ }}`), raised by /// `splitInterpolation`; `column` is the offset of the `{{` in `input`. @@ -117,7 +117,7 @@ impl<'a> Parser<'a> { pub fn new(allocator: &'a Allocator, source: &'a str) -> Self { // Strip comments from the source before tokenizing. The stripped source is a prefix // of `source`, so it is borrowed rather than copied. - let lexer = Lexer::new(allocator, Self::strip_comments(source)); + let lexer = Lexer::new(allocator, strip_comments(source).stripped); let tokens = lexer.tokenize(); // Collect error tokens from the lexer @@ -171,43 +171,6 @@ impl<'a> Parser<'a> { } } - /// Strips single-line comments (`//`) from the input. - /// - /// Comments are only recognized outside of quoted strings. - /// This matches Angular's behavior in `_stripComments`. - fn strip_comments(input: &str) -> &str { - match Self::find_comment_start(input) { - Some(idx) => &input[..idx], - None => input, - } - } - - /// Finds the start index of a `//` comment, respecting quoted strings. - /// - /// Returns `None` if no comment is found. - fn find_comment_start(input: &str) -> Option { - let bytes = input.as_bytes(); - let mut outer_quote: Option = None; - - for i in 0..input.len().saturating_sub(1) { - let ch = bytes[i]; - let next_ch = bytes[i + 1]; - - // Check for // outside of quotes - if ch == b'/' && next_ch == b'/' && outer_quote.is_none() { - return Some(i); - } - - // Track quote state - if outer_quote == Some(ch) { - outer_quote = None; - } else if outer_quote.is_none() && (ch == b'\'' || ch == b'"' || ch == b'`') { - outer_quote = Some(ch); - } - } - None - } - /// Checks for interpolation syntax (`{{` and `}}`) in the input. /// /// If found, adds an error: "Got interpolation ({{}}) where expression was expected". @@ -1857,7 +1820,6 @@ impl<'a> Parser<'a> { if self.is_assignment_operator(token) { // Clone the operation first to avoid borrow issues let operation = token.str_value.clone(); - let result_span = result.span(); // In binding mode, still parse the full expression but emit an error // This ensures spans cover the entire expression @@ -1878,7 +1840,7 @@ impl<'a> Parser<'a> { // Create Binary expression for assignment let end = self.current_end_index(); - let assign_span = ParseSpan::new(result_span.start, end); + let assign_span = ParseSpan::new(start, end); let assign_source_span = assign_span.to_absolute(self.absolute_offset); let binary_op = self.string_to_binary_operator(&operation); let binary = Binary { diff --git a/crates/oxc_angular_compiler/src/transform/html_to_r3.rs b/crates/oxc_angular_compiler/src/transform/html_to_r3.rs index c21d81ddc..b4cca8b6b 100644 --- a/crates/oxc_angular_compiler/src/transform/html_to_r3.rs +++ b/crates/oxc_angular_compiler/src/transform/html_to_r3.rs @@ -28,7 +28,7 @@ use crate::ast::r3::{ }; use crate::i18n::parser::I18nMessageFactory; use crate::i18n::placeholder::PlaceholderRegistry; -use crate::parser::expression::{BindingParser, blank_interpolation_error, find_comment_start}; +use crate::parser::expression::{BindingParser, blank_interpolation_error}; use crate::parser::html::{decode_entities_in_string, get_html_tag_definition, split_ns_name}; use crate::schema::{ element_security_context_for, is_known_element, is_trusted_types_sink_at, @@ -4066,7 +4066,7 @@ impl<'a> HtmlToR3Transform<'a> { attr: &HtmlAttribute<'a>, key_span: Span, ) -> R3BoundEvent<'a> { - let handler_span = self.calculate_event_handler_span(attr); + let handler_span = attr.value_span.unwrap_or(attr.span); let handler = self.parse_event_expression(&attr.value, handler_span); // Check for animation events (animate.xxx) @@ -4146,7 +4146,7 @@ impl<'a> HtmlToR3Transform<'a> { attr: &HtmlAttribute<'a>, key_span: Span, ) -> R3BoundEvent<'a> { - let handler_span = self.calculate_event_handler_span(attr); + let handler_span = attr.value_span.unwrap_or(attr.span); // Angular parses the handler first, so its errors come before the name errors. let handler = self.parse_event_expression(&attr.value, handler_span); @@ -4203,7 +4203,7 @@ impl<'a> HtmlToR3Transform<'a> { if let Some(anim_name) = name.strip_prefix('@') { return self.create_legacy_animation_event(anim_name, attr, key_span); } - let handler_span = self.calculate_event_handler_span(attr); + let handler_span = attr.value_span.unwrap_or(attr.span); let name_atom = Ident::from(self.allocator.alloc_str(name)); let errors_before = self.errors.len(); @@ -4261,25 +4261,6 @@ impl<'a> HtmlToR3Transform<'a> { result.ast } - /// Calculates the handler span for an event binding, adjusting for comments. - /// - /// Angular strips `//` comments from action bindings before parsing. - /// The handler span should exclude the comment portion and trailing whitespace. - fn calculate_event_handler_span(&self, attr: &HtmlAttribute<'a>) -> Span { - let base_span = attr.value_span.unwrap_or(attr.span); - let value_str = attr.value.as_str(); - - // Check if there's a comment to strip - if let Some(comment_pos) = find_comment_start(value_str) { - // Get the portion before the comment and trim trailing whitespace - let before_comment = &value_str[..comment_pos]; - let trimmed_len = before_comment.trim_end().len(); - Span::new(base_span.start, base_span.start + trimmed_len as u32) - } else { - base_span - } - } - /// Creates a variable with validation. /// Returns None if validation fails (error is reported). fn create_validated_variable( diff --git a/crates/oxc_angular_compiler/tests/r3_template_transform_test.rs b/crates/oxc_angular_compiler/tests/r3_template_transform_test.rs index 68a02bb61..bb030bc27 100644 --- a/crates/oxc_angular_compiler/tests/r3_template_transform_test.rs +++ b/crates/oxc_angular_compiler/tests/r3_template_transform_test.rs @@ -1010,6 +1010,29 @@ mod bound_attributes { mod events { use super::*; + #[test] + fn event_handler_span_includes_regex_ending_with_escaped_slash() { + for (handler, expression) in [ + (r"url.replace(/^\//, '')", r"url.replace(/^\//, '')"), + (r"url.replace(/^\//, '') //comment", r"url.replace(/^\//, '')"), + ("result = save("x") //comment", r#"result = save("x")"#), + ] { + let html = format!(r#""#); + let allocator = Allocator::default(); + let parsed = HtmlParser::new(&allocator, &html, "test.html").parse(); + let result = HtmlToR3Transform::new(&allocator, &html, TransformOptions::default()) + .transform(&parsed.nodes); + let R3Node::Element(button) = &result.nodes[0] else { panic!("expected button") }; + let event = &button.outputs[0]; + let start = html.find(handler).unwrap() as u32; + let attr_span = event.handler_span; + let expr_span = event.handler.source_span(); + assert_eq!((attr_span.start, attr_span.end), (start, start + handler.len() as u32)); + assert_eq!((expr_span.start, expr_span.end), (start, start + expression.len() as u32)); + assert!(result.errors.is_empty(), "{:?}", result.errors); + } + } + #[test] fn should_parse_event_bindings() { // TS: expectFromHtml('
')