diff --git a/crates/oxc_parser/src/diagnostics.rs b/crates/oxc_parser/src/diagnostics.rs index 4def7d94467b0..c592355df8c74 100644 --- a/crates/oxc_parser/src/diagnostics.rs +++ b/crates/oxc_parser/src/diagnostics.rs @@ -426,15 +426,6 @@ pub fn return_statement_only_in_function_body(span: Span) -> OxcDiagnostic { .with_label(span) } -#[cold] -pub fn jsx_expressions_may_not_use_the_comma_operator(span: Span) -> OxcDiagnostic { - // OxcDiagnostic::error("TS18007: JSX expressions may not use the comma - // operator.") - ts_error("18007", "JSX expressions may not use the comma operator") - .with_help("Did you mean to write an array?") - .with_label(span) -} - #[cold] pub fn invalid_identifier_in_using_declaration(span: Span) -> OxcDiagnostic { OxcDiagnostic::error("Using declarations may not have binding patterns.").with_label(span) diff --git a/crates/oxc_parser/src/jsx/mod.rs b/crates/oxc_parser/src/jsx/mod.rs index e429f8501d742..23541bb096e4d 100644 --- a/crates/oxc_parser/src/jsx/mod.rs +++ b/crates/oxc_parser/src/jsx/mod.rs @@ -300,12 +300,7 @@ impl<'a> ParserImpl<'a> { fn parse_jsx_assignment_expression(&mut self) -> Expression<'a> { self.context(Context::default().and_await(self.ctx.has_await()), self.ctx, |p| { - let expr = p.parse_expr(); - if let Expression::SequenceExpression(seq) = &expr { - let error = diagnostics::jsx_expressions_may_not_use_the_comma_operator(seq.span); - return p.fatal_error(error); - } - expr + p.parse_expr() }) } diff --git a/crates/oxc_semantic/src/checker/typescript.rs b/crates/oxc_semantic/src/checker/typescript.rs index 67d04ec6c711c..91810306fd40c 100644 --- a/crates/oxc_semantic/src/checker/typescript.rs +++ b/crates/oxc_semantic/src/checker/typescript.rs @@ -545,6 +545,12 @@ fn invalid_jsx_attribute_value(span: Span) -> OxcDiagnostic { .with_label(span) } +fn jsx_expressions_may_not_use_the_comma_operator(span: Span) -> OxcDiagnostic { + ts_error("18007", "JSX expressions may not use the comma operator") + .with_help("Did you mean to write an array?") + .with_label(span) +} + pub fn check_jsx_expression_container( container: &JSXExpressionContainer, ctx: &SemanticBuilder<'_>, @@ -554,4 +560,8 @@ pub fn check_jsx_expression_container( { ctx.error(invalid_jsx_attribute_value(container.span())); } + + if matches!(container.expression, JSXExpression::SequenceExpression(_)) { + ctx.error(jsx_expressions_may_not_use_the_comma_operator(container.expression.span())); + } } diff --git a/tasks/coverage/snapshots/estree_typescript.snap b/tasks/coverage/snapshots/estree_typescript.snap index a8bfb45ce03de..02457688d2415 100644 --- a/tasks/coverage/snapshots/estree_typescript.snap +++ b/tasks/coverage/snapshots/estree_typescript.snap @@ -1,10 +1,9 @@ commit: 15392346 estree_typescript Summary: -AST Parsed : 6480/6481 (99.98%) +AST Parsed : 6481/6481 (100.00%) Positive Passed: 6478/6481 (99.95%) -Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/jsx/jsxReactTestSuite.tsx -JSX expressions may not use the comma operator +Mismatch: tasks/coverage/typescript/tests/cases/conformance/jsx/jsxReactTestSuite.tsx Mismatch: tasks/coverage/typescript/tests/cases/conformance/jsx/tsxReactEmitEntities.tsx