fix(parser): parse postfix updates of sloppy let identifiers (#28060)

The Annex B fixtures added in #28057 expose that `let-- > 0` and `let /* comment */ --> 0` are incorrectly parsed as lexical declarations. In sloppy scripts, `let` can be an identifier followed by a postfix update.

Include `++` and `--` in the expression lookahead, preserving normal postfix and line-terminator handling. Regression coverage comes from the upstream fixtures now merged into `main`.

Rebased onto the merged submodule update. `just submodules` and `just coverage` completed on the rebased branch; Babel parser positives improve from 2257/2280 to 2259/2280, and the corresponding semantic failures disappear. The existing HTML-comment formatter failures now report an AST mismatch instead of a parse error; their separate fix is being prepared. Parser lint, formatting, and allocation tracking also completed.
This commit is contained in:
camc314 committed 2026-10-22 17:41:22 +00:00
1 parent f1d90329e2
commit 90c58ac971
4 files changed
+14 -35

No files matched your search

+5 -2
View File
@@ -21,8 +21,11 @@ impl<'a, C: Config> ParserImpl<'a, C> {
if peeked.is_assignment_operator() || peeked.is_binary_operator() {
let expr = self.parse_assignment_expression_or_higher();
self.parse_expression_statement(start, expr)
// let.a = 1, let?.a = 1, let()[a] = 1
} else if matches!(peeked, Kind::Dot | Kind::QuestionDot | Kind::LParen) {
// let.a = 1, let?.a = 1, let()[a] = 1, let++, let--
} else if matches!(
peeked,
Kind::Dot | Kind::QuestionDot | Kind::LParen | Kind::Plus2 | Kind::Minus2
) {
let expr = self.parse_expr();
self.parse_expression_statement(start, expr)
// single statement let declaration: while (0) let
@@ -3,12 +3,12 @@ commit: a56fe4a4
formatter_babel Summary:
AST Parsed : 2280/2280 (100.00%)
Positive Passed: 2271/2280 (99.61%)
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-let-declaration/input.js
Unexpected token
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-let-declaration-cr/input.js
Unexpected token
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-let-declaration-line-separator/input.js
Unexpected token
Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-let-declaration/input.js
Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-let-declaration-cr/input.js
Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-let-declaration-line-separator/input.js
Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/basic/class-method/input.js
Mismatch: tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/basic/class-private-method/input.js
+2 -20
View File
@@ -1,8 +1,8 @@
commit: a56fe4a4
parser_babel Summary:
AST Parsed : 2276/2280 (99.82%)
Positive Passed: 2257/2280 (98.99%)
AST Parsed : 2278/2280 (99.91%)
Positive Passed: 2259/2280 (99.08%)
Negative Passed: 1789/1804 (99.17%)
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/cast/unparenthesized-assert-and-assign/input.ts
@@ -34,15 +34,6 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/ty
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/module-namespace/module-identifier-invalid/input.ts
Fatal error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-same-line-let/input.js
× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-same-line-let/input.js:1:13]
1 │ let /* a */ --> c
· ──
2 │ x = 1;
╰────
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-open-export-default-from/input.js
× Cannot use export statement outside a module
@@ -52,15 +43,6 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-
2 │ "x";
╰────
Fatal error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-let-postfix-decrement-greater-than/input.js
× Unexpected token
╭─[babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-let-postfix-decrement-greater-than/input.js:1:5]
1 │ let --> 0
· ──
2 │ x = 1
╰────
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/3.3-function-in-if-body-lexical-redeclaration/input.js
× Identifier `f` has already been declared
+1 -7
View File
@@ -2,16 +2,10 @@ commit: a56fe4a4
semantic_babel Summary:
AST Parsed : 2280/2280 (100.00%)
Positive Passed: 2183/2280 (95.75%)
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-close-same-line-let/input.js
Unexpected token
Positive Passed: 2185/2280 (95.83%)
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-html-comments-open-export-default-from/input.js
Cannot use export statement outside a module
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/1.1-let-postfix-decrement-greater-than/input.js
Unexpected token
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/3.3-function-in-if-body-lexical-redeclaration/input.js
Identifier `f` has already been declared
Identifier `g` has already been declared