fix(parser): consume semicolon after let.x and let?.x#16857
fix(parser): consume semicolon after let.x and let?.x#16857overlookmotel merged 3 commits intomainfrom
let.x and let?.x#16857Conversation
let.x and let?.x
Co-authored-by: overlookmotel <557937+overlookmotel@users.noreply.github.com>
56170d7 to
c8426ed
Compare
There was a problem hiding this comment.
No issues found in the modified lines. The change correctly routes the let member/optional-chain/call branch through parse_expression_statement(...), aligning it with other branches and fixing the semicolon/ASI consumption bug described in the PR context.
Summary of changes
What changed
-
Parser fix in
crates/oxc_parser/src/js/declaration.rs:- In the
parse_let()branch for member access / optional chaining / calls (e.g.let.x,let?.x,let()), replaced direct construction of anExpressionStatementviaself.ast.statement_expression(self.end_span(span), expr)withself.parse_expression_statement(span, expr). - This ensures the statement is finalized using the shared expression-statement path (including semicolon consumption / ASI behavior), preventing
let.x;/let?.x;from being split into anExpressionStatement+EmptyStatement.
- In the
-
Snapshot update in
tasks/coverage/snapshots/codegen_misc.snap:codegen_miscpositive pass count moved from52/53to53/53and removed the previously failinglet-optional-chaining.cjsentry.
There was a problem hiding this comment.
Pull request overview
This PR fixes a parser bug where let.x; and let?.x; were incorrectly parsed as two separate statements (ExpressionStatement + EmptyStatement) instead of a single ExpressionStatement. The fix ensures proper Automatic Semicolon Insertion (ASI) by using parse_expression_statement() instead of directly constructing the statement.
Key changes:
- Modified
parse_let()to callparse_expression_statement()for member access and optional chaining onlet, ensuring semicolons are properly consumed - Resolved codegen idempotency test failure for
let-optional-chaining.cjs
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/oxc_parser/src/js/declaration.rs |
Changed line 30 to use parse_expression_statement() instead of ast.statement_expression() to properly consume semicolons via ASI |
tasks/coverage/snapshots/codegen_misc.snap |
Updated test results showing the idempotency test now passes (53/53 instead of 52/53) |
The implementation is correct and consistent with the other branches in the same function. All expression statement branches in parse_let() now properly handle semicolon consumption through parse_expression_statement(), which internally calls self.asi().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging #16857 will not alter performanceComparing Summary
Footnotes
|
let.x;andlet?.x;were parsed as two statements (ExpressionStatement + EmptyStatement) instead of one. This caused codegen idempotency failures.Root cause: In
parse_let(), the branch handling member access and optional chaining onletdirectly constructed the statement without consuming the semicolon:Fix: Call
parse_expression_statement()to apply ASI:This matches the pattern used in other branches of the same function.
Original prompt
let.x;orlet?.x;is parsed as 2 statements #16856💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.