Skip to content

fix(parser): parse let?.x#16840

Merged
overlookmotel merged 1 commit intomainfrom
copilot/fix-parser-let-x
Dec 14, 2025
Merged

fix(parser): parse let?.x#16840
overlookmotel merged 1 commit intomainfrom
copilot/fix-parser-let-x

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

Fixes #16839.

Make parser parse let?.x successfully.

There's a failure in codegen idempotency tests, but that's an unrelated and pre-existing bug, so am leaving that to another PR.

Copilot AI changed the title [WIP] Fix parser issue for let?.x in scripts fix(parser): parse let?.x in script mode Dec 14, 2025
Copilot AI requested a review from overlookmotel December 14, 2025 16:08
Copy link
Member

@overlookmotel overlookmotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot See below comment and action it.

Copilot AI requested a review from overlookmotel December 14, 2025 18:07
Copilot AI changed the title fix(parser): parse let?.x in script mode fix(parser): parse let?.x with optional chaining Dec 14, 2025
@github-actions github-actions bot added A-parser Area - Parser C-bug Category - Bug labels Dec 14, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 14, 2025

CodSpeed Performance Report

Merging #16840 will not alter performance

Comparing copilot/fix-parser-let-x (c7c05ba) with main (b16fe64)

Summary

✅ 42 untouched
⏩ 3 skipped1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@overlookmotel overlookmotel changed the title fix(parser): parse let?.x with optional chaining fix(parser): parse let?.x Dec 14, 2025
@overlookmotel overlookmotel force-pushed the copilot/fix-parser-let-x branch from 99eb172 to c7c05ba Compare December 14, 2025 19:18
@overlookmotel overlookmotel marked this pull request as ready for review December 14, 2025 19:18
Copilot AI review requested due to automatic review settings December 14, 2025 19:18
@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins labels Dec 14, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the parser to correctly handle optional chaining syntax with the let keyword (e.g., let?.x). Previously, the parser would fail to parse such expressions. The fix recognizes that in script mode (non-strict), let can be used as an identifier, and when followed by optional chaining (?.), it should be parsed as a member expression rather than a variable declaration.

Key Changes:

  • Updated parser logic to recognize Kind::QuestionDot after let keyword
  • Added test cases for both valid (script mode) and invalid (module mode) usage
  • Fixed the dot-notation ESLint conformance test that was previously failing

Reviewed changes

Copilot reviewed 2 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/oxc_parser/src/js/declaration.rs Added Kind::QuestionDot to the pattern match that handles let as an identifier with property access
tasks/coverage/misc/pass/let-optional-chaining.cjs Test file demonstrating valid usage of let?.x in script mode (CommonJS)
tasks/coverage/misc/fail/let-optional-chaining.js Test file demonstrating invalid usage of let?.x in module mode (should produce errors)
tasks/coverage/snapshots/parser_misc.snap Updated snapshot showing 4 new error cases for the fail test and incremented test counts
tasks/coverage/snapshots/semantic_misc.snap Updated snapshot with incremented test counts
tasks/coverage/snapshots/transformer_misc.snap Updated snapshot with incremented test counts
tasks/coverage/snapshots/formatter_misc.snap Updated snapshot with incremented test counts
tasks/coverage/snapshots/codegen_misc.snap Updated snapshot showing one expected failure (pre-existing bug per PR description)
apps/oxlint/conformance/snapshot.md Updated conformance metrics showing dot-notation rule now fully passing (69/69 tests)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser tweak is minimal and likely correct, but it changes the declaration-vs-expression routing based on a broader lookahead set and deserves extra regression coverage in statement-sensitive positions. The new module-mode failure fixture produces repetitive diagnostics, making snapshots noisier than necessary. codegen_misc.snap indicates the new fixture lowers codegen positive pass rate, which risks institutionalizing a red/unstable coverage metric even if the underlying idempotency issue is “pre-existing.”

Additional notes (2)
  • Maintainability | crates/oxc_parser/src/js/declaration.rs:24-31
    The change to include Kind::QuestionDot fixes the immediate parse for let?.x, but this branch now routes into parse_expr() based solely on lookahead. That can widen the set of token sequences that stop being treated as let-declaration candidates and instead become expression statements.

Even if the current tests pass, consider adding a focused regression case where let is followed by ?. inside contexts that are sensitive to statement vs declaration parsing (e.g. for (let?.x;;) {} / if (cond) let?.x / label: let?.x) to ensure this early decision doesn’t create new ambiguities.

  • Maintainability | tasks/coverage/misc/fail/let-optional-chaining.js:1-5
    The module-mode failure fixture is currently expecting a reserved-word error at each let?.… line. That’s good for coverage, but it’s somewhat redundant and makes the snapshot noisy (multiple near-identical diagnostics).

Consider reducing to a single representative let?.x; in the fail fixture unless you specifically need to assert multiple optional-chaining forms fail at parse time in module mode.

Summary of changes

What changed

Parser behavior

  • Updated crates/oxc_parser/src/js/declaration.rs to treat let?.… as an expression-statement continuation by including Kind::QuestionDot in the lookahead set (Dot | QuestionDot | LParen).

Test coverage

  • Added script-mode pass fixture: tasks/coverage/misc/pass/let-optional-chaining.cjs.
  • Added module-mode fail fixture: tasks/coverage/misc/fail/let-optional-chaining.js.

Snapshots / conformance

  • Updated various snapshots to reflect the additional fixture and its expected pass/fail outcomes:
    • tasks/coverage/snapshots/{parser_misc,formatter_misc,codegen_misc,semantic_misc,transformer_misc}.snap
  • Updated apps/oxlint/conformance/snapshot.md totals and moved dot-notation into the fully passing set.

@charliecreates charliecreates bot removed the request for review from CharlieHelps December 14, 2025 19:24
@overlookmotel overlookmotel merged commit d3208dc into main Dec 14, 2025
35 checks passed
@overlookmotel overlookmotel deleted the copilot/fix-parser-let-x branch December 14, 2025 19:26
graphite-app bot pushed a commit that referenced this pull request Dec 14, 2025
Follow-on after #16840 and #16857. We had a few test cases relating to the same thing, and one of them called the undescriptive `oxc.js`. Combine them, and rename the test case files with a more accurate name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins A-parser Area - Parser C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser: cannot parse let?.x in script

3 participants