From 1554f7c0d219acae56c2ee6443715926dd8c3561 Mon Sep 17 00:00:00 2001 From: Boshen Date: Wed, 29 Nov 2023 23:21:39 +0800 Subject: [PATCH] feat(parsr): parse `let.a = 1` with error recovery (#1587) --- crates/oxc_parser/src/js/declaration.rs | 4 ++++ tasks/coverage/misc/fail/oxc.js | 2 ++ tasks/coverage/parser_misc.snap | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tasks/coverage/misc/fail/oxc.js diff --git a/crates/oxc_parser/src/js/declaration.rs b/crates/oxc_parser/src/js/declaration.rs index 4db87c6d0..e2e0e1b25 100644 --- a/crates/oxc_parser/src/js/declaration.rs +++ b/crates/oxc_parser/src/js/declaration.rs @@ -31,6 +31,10 @@ impl<'a> Parser<'a> { if peeked.is_assignment_operator() || peeked.is_binary_operator() { let expr = self.parse_assignment_expression_base()?; self.parse_expression_statement(span, expr) + // let.a = 1, let()[a] = 1 + } else if matches!(peeked, Kind::Dot | Kind::LParen) { + let expr = self.parse_expression()?; + Ok(self.ast.expression_statement(self.end_span(span), expr)) // single statement let declaration: while (0) let } else if (stmt_ctx.is_single_statement() && peeked != Kind::LBrack) || peeked == Kind::Semicolon diff --git a/tasks/coverage/misc/fail/oxc.js b/tasks/coverage/misc/fail/oxc.js new file mode 100644 index 000000000..510f490a0 --- /dev/null +++ b/tasks/coverage/misc/fail/oxc.js @@ -0,0 +1,2 @@ +let.a = 1; +let()[a] = 1; diff --git a/tasks/coverage/parser_misc.snap b/tasks/coverage/parser_misc.snap index 9c50e90e9..3b3c72da0 100644 --- a/tasks/coverage/parser_misc.snap +++ b/tasks/coverage/parser_misc.snap @@ -1,7 +1,7 @@ parser_misc Summary: AST Parsed : 8/8 (100.00%) Positive Passed: 8/8 (100.00%) -Negative Passed: 2/2 (100.00%) +Negative Passed: 3/3 (100.00%) × Unexpected token ╭─[fail/oxc-169.js:1:1] 1 │ 1<(V=82< @@ -13,3 +13,17 @@ Negative Passed: 2/2 (100.00%) · ───────── ╰──── + × The keyword 'let' is reserved + ╭─[fail/oxc.js:1:1] + 1 │ let.a = 1; + · ─── + 2 │ let()[a] = 1; + ╰──── + + × The keyword 'let' is reserved + ╭─[fail/oxc.js:1:1] + 1 │ let.a = 1; + 2 │ let()[a] = 1; + · ─── + ╰──── +