Skip to content

Commit

Permalink
feat(parser): add syntax error for hyphen in JSXMemberExpression `<…
Browse files Browse the repository at this point in the history
…Foo.bar-baz />` (#5440)

closes #5355
  • Loading branch information
Boshen committed Sep 4, 2024
1 parent fdb8857 commit 10279f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion crates/oxc_parser/src/jsx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,12 @@ impl<'a> ParserImpl<'a> {
}

// <foo.bar>
property = Some(self.parse_jsx_identifier()?);
let ident = self.parse_jsx_identifier()?;
// `<foo.bar- />` is a syntax error.
if ident.name.contains('-') {
return Err(diagnostics::unexpected_token(ident.span));
}
property = Some(ident);
span = self.end_span(span);
}

Expand Down
1 change: 1 addition & 0 deletions tasks/coverage/misc/fail/oxc-5355.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Foo.bar-baz />
8 changes: 7 additions & 1 deletion tasks/coverage/parser_misc.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parser_misc Summary:
AST Parsed : 27/27 (100.00%)
Positive Passed: 27/27 (100.00%)
Negative Passed: 16/16 (100.00%)
Negative Passed: 17/17 (100.00%)

× Unexpected token
╭─[misc/fail/oxc-169.js:2:1]
Expand Down Expand Up @@ -238,6 +238,12 @@ Negative Passed: 16/16 (100.00%)
5 │ }
╰────

× Unexpected token
╭─[misc/fail/oxc-5355.jsx:1:6]
1<Foo.bar-baz />
· ───────
╰────

× The keyword 'let' is reserved
╭─[misc/fail/oxc.js:1:1]
1let.a = 1;
Expand Down

0 comments on commit 10279f5

Please sign in to comment.