feat(parsr): parse let.a = 1 with error recovery (#1587)

This commit is contained in:
Boshen 2023-11-29 23:21:39 +08:00 committed by GitHub
parent fd6a3ed918
commit 1554f7c0d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View file

@ -31,6 +31,10 @@ impl<'a> Parser<'a> {
if peeked.is_assignment_operator() || peeked.is_binary_operator() { if peeked.is_assignment_operator() || peeked.is_binary_operator() {
let expr = self.parse_assignment_expression_base()?; let expr = self.parse_assignment_expression_base()?;
self.parse_expression_statement(span, expr) 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 // single statement let declaration: while (0) let
} else if (stmt_ctx.is_single_statement() && peeked != Kind::LBrack) } else if (stmt_ctx.is_single_statement() && peeked != Kind::LBrack)
|| peeked == Kind::Semicolon || peeked == Kind::Semicolon

View file

@ -0,0 +1,2 @@
let.a = 1;
let()[a] = 1;

View file

@ -1,7 +1,7 @@
parser_misc Summary: parser_misc Summary:
AST Parsed : 8/8 (100.00%) AST Parsed : 8/8 (100.00%)
Positive Passed: 8/8 (100.00%) Positive Passed: 8/8 (100.00%)
Negative Passed: 2/2 (100.00%) Negative Passed: 3/3 (100.00%)
× Unexpected token × Unexpected token
╭─[fail/oxc-169.js:1:1] ╭─[fail/oxc-169.js:1:1]
1 │ 1<(V=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V=uIV=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V<II> 1 │ 1<(V=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V=uIV=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V<II>
@ -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;
· ───
╰────