mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
fix(parser): allow parenthesized JSX comma expressions with preserve_parens=false (#26524)
Allow parenthesized comma expressions such as `<A>{(a, b)}</A>` and `<A x={(a, b)} />` when `preserve_parens` is false.
Compare the sequence expression's start with the first token's start to retain the grouping distinction after parentheses are omitted from the AST. Ungrouped comma expressions such as `{a, b}` and `{(a, b), c}` remain invalid.
This commit is contained in:
@@ -382,9 +382,11 @@ impl<'a, C: Config> ParserImpl<'a, C> {
|
||||
// ^^^^^^^^^^^^^ span
|
||||
JSXExpression::new_empty_expression(Span::new(span.start + 1, span.end - 1), self)
|
||||
} else {
|
||||
let expr_start = self.cur_start();
|
||||
let expr = JSXExpression::from(self.parse_expr());
|
||||
// JSX expressions may not use the comma operator.
|
||||
if matches!(expr, JSXExpression::SequenceExpression(_)) {
|
||||
// JSX expressions may not use an unparenthesized comma operator.
|
||||
if matches!(&expr, JSXExpression::SequenceExpression(sequence) if sequence.span.start == expr_start)
|
||||
{
|
||||
self.error(diagnostics::jsx_expressions_may_not_use_the_comma_operator(
|
||||
expr.span(),
|
||||
));
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<A>{a, b}</A>;
|
||||
<A x={a, b} />;
|
||||
<A>{(a, b), c}</A>;
|
||||
<A x={(a, b), c} />;
|
||||
@@ -0,0 +1,6 @@
|
||||
<A>{(a, b)}</A>;
|
||||
<A x={(a, b)} />;
|
||||
<A>{((a, b))}</A>;
|
||||
<A x={((a, b))} />;
|
||||
<A>{((a, b), c)}</A>;
|
||||
<A x={((a, b), c)} />;
|
||||
@@ -1,3 +1,3 @@
|
||||
codegen_misc Summary:
|
||||
AST Parsed : 98/98 (100.00%)
|
||||
Positive Passed: 98/98 (100.00%)
|
||||
AST Parsed : 99/99 (100.00%)
|
||||
Positive Passed: 99/99 (100.00%)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
formatter_misc Summary:
|
||||
AST Parsed : 98/98 (100.00%)
|
||||
Positive Passed: 98/98 (100.00%)
|
||||
AST Parsed : 99/99 (100.00%)
|
||||
Positive Passed: 99/99 (100.00%)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
lexer_misc Summary:
|
||||
AST Parsed : 300/300 (100.00%)
|
||||
Positive Passed: 300/300 (100.00%)
|
||||
AST Parsed : 302/302 (100.00%)
|
||||
Positive Passed: 302/302 (100.00%)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
parser_misc Summary:
|
||||
AST Parsed : 98/98 (100.00%)
|
||||
Positive Passed: 98/98 (100.00%)
|
||||
Negative Passed: 202/202 (100.00%)
|
||||
AST Parsed : 99/99 (100.00%)
|
||||
Positive Passed: 99/99 (100.00%)
|
||||
Negative Passed: 203/203 (100.00%)
|
||||
|
||||
× Cannot assign to 'arguments' in strict mode
|
||||
╭─[misc/fail/arguments-eval-ambient.ts:2:13]
|
||||
@@ -939,6 +939,40 @@ Negative Passed: 202/202 (100.00%)
|
||||
╰────
|
||||
help: JSX syntax is disabled and should be enabled via the parser options
|
||||
|
||||
× TS(18007): JSX expressions may not use the comma operator
|
||||
╭─[misc/fail/jsx-unparenthesized-comma.jsx:1:5]
|
||||
1 │ <A>{a, b}</A>;
|
||||
· ────
|
||||
2 │ <A x={a, b} />;
|
||||
╰────
|
||||
help: Did you mean to write an array?
|
||||
|
||||
× TS(18007): JSX expressions may not use the comma operator
|
||||
╭─[misc/fail/jsx-unparenthesized-comma.jsx:2:7]
|
||||
1 │ <A>{a, b}</A>;
|
||||
2 │ <A x={a, b} />;
|
||||
· ────
|
||||
3 │ <A>{(a, b), c}</A>;
|
||||
╰────
|
||||
help: Did you mean to write an array?
|
||||
|
||||
× TS(18007): JSX expressions may not use the comma operator
|
||||
╭─[misc/fail/jsx-unparenthesized-comma.jsx:3:5]
|
||||
2 │ <A x={a, b} />;
|
||||
3 │ <A>{(a, b), c}</A>;
|
||||
· ─────────
|
||||
4 │ <A x={(a, b), c} />;
|
||||
╰────
|
||||
help: Did you mean to write an array?
|
||||
|
||||
× TS(18007): JSX expressions may not use the comma operator
|
||||
╭─[misc/fail/jsx-unparenthesized-comma.jsx:4:7]
|
||||
3 │ <A>{(a, b), c}</A>;
|
||||
4 │ <A x={(a, b), c} />;
|
||||
· ─────────
|
||||
╰────
|
||||
help: Did you mean to write an array?
|
||||
|
||||
× The keyword 'let' is reserved
|
||||
╭─[misc/fail/let-member-expression.js:4:1]
|
||||
3 │
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
semantic_misc Summary:
|
||||
AST Parsed : 98/98 (100.00%)
|
||||
Positive Passed: 94/98 (95.92%)
|
||||
AST Parsed : 99/99 (100.00%)
|
||||
Positive Passed: 95/99 (95.96%)
|
||||
semantic Error: tasks/coverage/misc/pass/declare-let-private.ts
|
||||
Bindings mismatch:
|
||||
after transform: ScopeId(0): ["private"]
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
transformer_misc Summary:
|
||||
AST Parsed : 98/98 (100.00%)
|
||||
Positive Passed: 98/98 (100.00%)
|
||||
AST Parsed : 99/99 (100.00%)
|
||||
Positive Passed: 99/99 (100.00%)
|
||||
|
||||
Reference in New Issue
Block a user