Skip to content

Commit 1747d41

Browse files
committed
test(parser): cover Astro shorthand attribute spans with interleaved comments
1 parent 7640500 commit 1747d41

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

  • crates/oxc_parser/src/astro

crates/oxc_parser/src/astro/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,30 @@ const name = "World";
14051405
assert_eq!(name.span.source_text(source), "prop");
14061406
}
14071407

1408+
// Comments inside the braces must not drag the name span across them.
1409+
#[test]
1410+
fn parse_astro_attribute_shorthand_with_comments_spans() {
1411+
let allocator = Allocator::default();
1412+
let source_type = SourceType::astro();
1413+
let source = r"<Component {/* c1 */ prop /* c2 */} />";
1414+
let ret = Parser::new(&allocator, source, source_type).parse_astro();
1415+
assert!(!ret.panicked, "parser panicked: {:?}", ret.errors);
1416+
assert!(ret.errors.is_empty(), "errors: {:?}", ret.errors);
1417+
1418+
let JSXChild::Element(element) = &ret.root.body[0] else {
1419+
panic!("Expected JSXChild::Element");
1420+
};
1421+
let JSXAttributeItem::Attribute(attr) = &element.opening_element.attributes[0] else {
1422+
panic!("Expected Attribute, got SpreadAttribute");
1423+
};
1424+
let JSXAttributeName::Identifier(name) = &attr.name else {
1425+
panic!("expected ident name");
1426+
};
1427+
1428+
assert_eq!(attr.span.source_text(source), "{/* c1 */ prop /* c2 */}");
1429+
assert_eq!(name.span.source_text(source), "prop");
1430+
}
1431+
14081432
/// Shorthand is desugared away, so this span relationship is all consumers have to detect it.
14091433
#[test]
14101434
fn parse_astro_attribute_shorthand_is_distinguishable_by_span() {

0 commit comments

Comments
 (0)