From 2b4d1bf1425a4eeabf2bc36cb8383bdd33fba47b Mon Sep 17 00:00:00 2001 From: Boshen Date: Tue, 19 Dec 2023 20:21:02 +0800 Subject: [PATCH] fix(parser): await in jsx expression closes #1740 --- crates/oxc_parser/src/jsx/mod.rs | 2 +- tasks/coverage/codegen_misc.snap | 4 ++-- tasks/coverage/misc/pass/oxc-1740.tsx | 9 +++++++++ tasks/coverage/parser_misc.snap | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 tasks/coverage/misc/pass/oxc-1740.tsx diff --git a/crates/oxc_parser/src/jsx/mod.rs b/crates/oxc_parser/src/jsx/mod.rs index a5fbff60f..ed6ae2a7a 100644 --- a/crates/oxc_parser/src/jsx/mod.rs +++ b/crates/oxc_parser/src/jsx/mod.rs @@ -250,7 +250,7 @@ impl<'a> Parser<'a> { fn parse_jsx_assignment_expression(&mut self) -> Result> { let ctx = self.ctx; - self.ctx = Context::default(); + self.ctx = Context::default().and_await(ctx.has_await()); let expr = self.parse_expression(); if let Ok(Expression::SequenceExpression(seq)) = &expr { return Err(diagnostics::JSXExpressionsMayNotUseTheCommaOperator(seq.span).into()); diff --git a/tasks/coverage/codegen_misc.snap b/tasks/coverage/codegen_misc.snap index 8e7578721..38972628e 100644 --- a/tasks/coverage/codegen_misc.snap +++ b/tasks/coverage/codegen_misc.snap @@ -1,3 +1,3 @@ codegen_misc Summary: -AST Parsed : 8/8 (100.00%) -Positive Passed: 8/8 (100.00%) +AST Parsed : 9/9 (100.00%) +Positive Passed: 9/9 (100.00%) diff --git a/tasks/coverage/misc/pass/oxc-1740.tsx b/tasks/coverage/misc/pass/oxc-1740.tsx new file mode 100644 index 000000000..a49573f0f --- /dev/null +++ b/tasks/coverage/misc/pass/oxc-1740.tsx @@ -0,0 +1,9 @@ +export const foo = () => ({ + render: async () => { + ReactDOM.render( + , + domNode, + () => {} + ); + }, +}); diff --git a/tasks/coverage/parser_misc.snap b/tasks/coverage/parser_misc.snap index 3b3c72da0..9d35285c9 100644 --- a/tasks/coverage/parser_misc.snap +++ b/tasks/coverage/parser_misc.snap @@ -1,6 +1,6 @@ parser_misc Summary: -AST Parsed : 8/8 (100.00%) -Positive Passed: 8/8 (100.00%) +AST Parsed : 9/9 (100.00%) +Positive Passed: 9/9 (100.00%) Negative Passed: 3/3 (100.00%) × Unexpected token ╭─[fail/oxc-169.js:1:1]