Skip to content

fix(parser): parse array computed class keys#22159

Merged
graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-array-computed-class-key
May 5, 2026
Merged

fix(parser): parse array computed class keys#22159
graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-array-computed-class-key

Conversation

@camc314

@camc314 camc314 commented May 5, 2026

Copy link
Copy Markdown
Contributor

Fixes parser recovery for class computed property names whose expression starts with an array literal, such as class C { [[]]() {} }.

The TypeScript index-signature lookahead previously treated a nested [ after the opening computed-name bracket as an unambiguous index signature. That caused valid class computed keys containing array literals to be parsed through the wrong branch and rejected.

This changes the lookahead so only ... remains an early unambiguous index-signature signal, allowing nested arrays and other assignment expressions to parse as computed property names.

fixes: #22157

@codspeed-hq

codspeed-hq Bot commented May 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing codex/fix-array-computed-class-key (408986e) with main (07f03cc)

Open in CodSpeed

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.

@camc314 camc314 marked this pull request as ready for review May 5, 2026 20:13
Copilot AI review requested due to automatic review settings May 5, 2026 20:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a parser misclassification where class computed property names starting with an array literal (e.g. class C { [[]]() {} }) were incorrectly routed into the TypeScript index-signature parsing path, causing valid syntax to be rejected.

Changes:

  • Adjusts TypeScript index-signature lookahead to treat only ... as an early unambiguous index-signature signal (no longer treating a nested [ as such).
  • Adds a new misc “pass” coverage case reproducing #22157 (and related variants like [[1]] and [[...x]]).
  • Updates coverage snapshots to reflect the added coverage case and the corrected parsing behavior.

Reviewed changes

Copilot reviewed 1 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/oxc_parser/src/ts/statement.rs Narrows index-signature lookahead so nested [ doesn’t preempt valid computed property name parsing in class bodies.
tasks/coverage/misc/pass/oxc-22157.js Adds coverage inputs covering computed class keys whose expressions start with array literals (and a few nearby edge cases).
tasks/coverage/snapshots/parser_typescript.snap Snapshot updates reflecting the parsing change in the TS corpus output.
tasks/coverage/snapshots/parser_misc.snap Snapshot count update due to the added misc pass case.
tasks/coverage/snapshots/semantic_misc.snap Snapshot count update due to the added misc pass case.
tasks/coverage/snapshots/transformer_misc.snap Snapshot count update due to the added misc pass case.
tasks/coverage/snapshots/formatter_misc.snap Snapshot count update due to the added misc pass case.
tasks/coverage/snapshots/codegen_misc.snap Snapshot count update due to the added misc pass case.

@camc314 camc314 self-assigned this May 5, 2026
@camc314 camc314 added A-parser Area - Parser 0-merge Merge with Graphite Merge Queue labels May 5, 2026

camc314 commented May 5, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

Fixes parser recovery for class computed property names whose expression starts with an array literal, such as `class C { [[]]() {} }`.

The TypeScript index-signature lookahead previously treated a nested `[` after the opening computed-name bracket as an unambiguous index signature. That caused valid class computed keys containing array literals to be parsed through the wrong branch and rejected.

This changes the lookahead so only `...` remains an early unambiguous index-signature signal, allowing nested arrays and other assignment expressions to parse as computed property names.

fixes: #22157
@graphite-app graphite-app Bot force-pushed the codex/fix-array-computed-class-key branch from 408986e to 9fa2122 Compare May 5, 2026 20:46
@graphite-app graphite-app Bot merged commit 9fa2122 into main May 5, 2026
28 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 5, 2026
@graphite-app graphite-app Bot deleted the codex/fix-array-computed-class-key branch May 5, 2026 20:50
camc314 added a commit that referenced this pull request May 11, 2026
### 🚀 Features

- 66c9b01 transformer/typescript: Debug_assert that `enum_eval` ran in
semantic (#22252) (Dunqing)
- ffe6475 minifier: Fold `Array` constructor with safe spreads (#22215)
(camc314)

### 🐛 Bug Fixes

- d3d0b18 traverse: Handle `ChainElement::TSNonNullExpression` in
`GatherNodeParts` (#22247) (leaysgur)
- 4e880de transformer/object-rest-spread: Declare temp vars for computed
keys (#22284) (camc314)
- a7c3e22 semantic: Clear member write target for computed keys (#22302)
(camc314)
- 6a8852d codegen: Emit newline after legal-comment orphan flush
(#22304) (Dunqing)
- 5da9fda transformer/explicit-resource-management: Preserve class names
(#22306) (Dunqing)
- b5d970f transformer/explicit-resource-management: Preserve class names
(#22290) (camc314)
- bc54fd4 minifier: Keep function / class names if direct eval is
present in the scope (#22241) (sapphi-red)
- 7a810c0 minifier: Refresh direct eval flags after DCE (#21787)
(Dunqing)
- dd88726 transformer/legacy-decorator: Preserve accessor type
annotation for emitDecoratorMetadata (#21966) (Dunqing)
- 29a3cd7 codegen: Swap mapping/indent order for top-level decls
(#22206) (Dunqing)
- 73b4f40 minifier: Preserve catch binding with direct eval (#22221)
(camc314)
- 0e13d17 minifier: Preserve optional chain base side effects (#22219)
(camc314)
- 0c7c01c transformer/typescript: Inline optional-chain enum member
access (#21834) (Dunqing)
- a6aff7e codegen: Emit block/array/object end mapping at close char
(#22200) (Dunqing)
- a099b03 codegen: Emit call end mapping at `)` position, not past it
(#22199) (Dunqing)
- 5753774 minifier: Cap if-return ternary collapse for firefox (#21841)
(Gurupungav Narayanan)
- 2493bdd codegen: Correct sourcemap end mappings for closing delimiters
(#22001) (Mark Dalgleish)
- 3b385e2 minifier: Bail optimizing `Array` with unknown arg count
(#22188) (camc314)
- 9fa2122 parser: Parse array computed class keys (#22159) (camc314)

### 📚 Documentation

- a4a6892 napi/parser: Correct code comment (#22278) (overlookmotel)
- 9305373 oxc: Update README (#22178) (camc314)

Co-authored-by: Cameron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parser: ArrayLiteral as computed property key rejected in class bodies

2 participants