feat(parser): add syntax error for hyphen in JSXMemberExpression <Foo.bar-baz /> (#5440)

closes #5355
This commit is contained in:
Boshen 2024-09-04 14:09:06 +00:00
parent fdb8857630
commit 10279f55d9
3 changed files with 14 additions and 2 deletions

View file

@ -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);
}

View file

@ -0,0 +1 @@
<Foo.bar-baz />

View file

@ -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]
@ -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]
1 │ let.a = 1;