From 10279f55d92df80d9d5ce6b034a230e2a8a89e19 Mon Sep 17 00:00:00 2001
From: Boshen <1430279+Boshen@users.noreply.github.com>
Date: Wed, 4 Sep 2024 14:09:06 +0000
Subject: [PATCH] feat(parser): add syntax error for hyphen in
`JSXMemberExpression` `` (#5440)
closes #5355
---
crates/oxc_parser/src/jsx/mod.rs | 7 ++++++-
tasks/coverage/misc/fail/oxc-5355.jsx | 1 +
tasks/coverage/parser_misc.snap | 8 +++++++-
3 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 tasks/coverage/misc/fail/oxc-5355.jsx
diff --git a/crates/oxc_parser/src/jsx/mod.rs b/crates/oxc_parser/src/jsx/mod.rs
index 748480f5b..c666686a0 100644
--- a/crates/oxc_parser/src/jsx/mod.rs
+++ b/crates/oxc_parser/src/jsx/mod.rs
@@ -198,7 +198,12 @@ impl<'a> ParserImpl<'a> {
}
//
- property = Some(self.parse_jsx_identifier()?);
+ let ident = self.parse_jsx_identifier()?;
+ // `` is a syntax error.
+ if ident.name.contains('-') {
+ return Err(diagnostics::unexpected_token(ident.span));
+ }
+ property = Some(ident);
span = self.end_span(span);
}
diff --git a/tasks/coverage/misc/fail/oxc-5355.jsx b/tasks/coverage/misc/fail/oxc-5355.jsx
new file mode 100644
index 000000000..bbf550bea
--- /dev/null
+++ b/tasks/coverage/misc/fail/oxc-5355.jsx
@@ -0,0 +1 @@
+
diff --git a/tasks/coverage/parser_misc.snap b/tasks/coverage/parser_misc.snap
index 6ee26030e..5365b6458 100644
--- a/tasks/coverage/parser_misc.snap
+++ b/tasks/coverage/parser_misc.snap
@@ -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 │
+ · ───────
+ ╰────
+
× The keyword 'let' is reserved
╭─[misc/fail/oxc.js:1:1]
1 │ let.a = 1;