Skip to content

fix(transformer/object-rest-spread): correct scope id when moving bindings#22419

Merged
graphite-app[bot] merged 1 commit into
mainfrom
c/05-14-fix_transformer_object-rest-spread_correct_scope_id_when_moving_bindings
May 14, 2026
Merged

fix(transformer/object-rest-spread): correct scope id when moving bindings#22419
graphite-app[bot] merged 1 commit into
mainfrom
c/05-14-fix_transformer_object-rest-spread_correct_scope_id_when_moving_bindings

Conversation

@camc314

@camc314 camc314 commented May 14, 2026

Copy link
Copy Markdown
Contributor

Previously, given:

for (var { x, ...rest } of iterable) {}

The destructuring pattern appears in the for head, but var bindings are not owned by that scope - x and rest are hoisted into the current hoist scope.

After transform:

for (var _ref of iterable) {
  var x = _ref.x;
  var rest = _objectWithoutProperties(_ref, _excluded);
}

The bindings moved into the loop scope, but since we were passing the for loop's scope, move_binding_by_symbol_id was a no-op as the var decls were not defined in the for loop's scope.

This PR get's the declared scope of the symbol and uses it rather than assuming that the var is scoped to the function

@github-actions github-actions Bot added the A-transformer Area - Transformer / Transpiler label May 14, 2026

camc314 commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@camc314 camc314 marked this pull request as ready for review May 14, 2026 11:00
Copilot AI review requested due to automatic review settings May 14, 2026 11:00

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 incorrect semantic scoping updates performed by the ES2018 object rest/spread transformer when it rewrites for-init destructuring patterns into the loop body, ensuring bindings are moved from their actual owning scope.

Changes:

  • Use ctx.scoping().symbol_scope_id(symbol_id) as the source scope when calling move_binding_by_symbol_id, instead of assuming the for init scope.
  • Update semantic_test262 snapshot showing improved pass counts and removal of several previously failing binding-mismatch cases.

Reviewed changes

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

File Description
tasks/coverage/snapshots/semantic_test262.snap Snapshot update reflecting improved semantic equivalence after transform (fewer mismatches, slightly higher pass rate).
crates/oxc_transformer/src/es2018/object_rest_spread.rs Fix binding moves to use the symbol’s true current scope when relocating bindings into the loop body scope.

@codspeed-hq

codspeed-hq Bot commented May 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing c/05-14-fix_transformer_object-rest-spread_correct_scope_id_when_moving_bindings (f969770) with main (8b2f4f9)

Open in CodSpeed

Footnotes

  1. 7 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 draft May 14, 2026 11:11
@camc314 camc314 marked this pull request as ready for review May 14, 2026 11:12
@camc314 camc314 requested a review from Copilot May 14, 2026 11:12

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

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

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label May 14, 2026
@camc314 camc314 self-assigned this May 14, 2026

camc314 commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

  • May 14, 11:51 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • May 14, 11:51 AM UTC: camc314 added this pull request to the Graphite merge queue.
  • May 14, 11:55 AM UTC: The Graphite merge queue couldn't merge this PR because it had merge conflicts.
  • May 14, 12:03 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • May 14, 12:06 PM UTC: camc314 added this pull request to the Graphite merge queue.
  • May 14, 12:11 PM UTC: Merged by the Graphite merge queue.

@graphite-app graphite-app Bot changed the base branch from c/05-14-perf_transformer_object-rest-spread_collect_vec_symbolid_over_vec_ident_ to graphite-base/22419 May 14, 2026 11:51
@graphite-app graphite-app Bot changed the base branch from graphite-base/22419 to main May 14, 2026 11:55
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 14, 2026
@camc314 camc314 force-pushed the c/05-14-fix_transformer_object-rest-spread_correct_scope_id_when_moving_bindings branch from fa3e662 to f969770 Compare May 14, 2026 12:03
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label May 14, 2026
…dings (#22419)

Previously, given:
```
for (var { x, ...rest } of iterable) {}
```

The destructuring pattern appears in the `for` head, but `var` bindings are not owned by that scope - `x` and `rest` are hoisted into the current hoist scope.

After transform:

```
for (var _ref of iterable) {
  var x = _ref.x;
  var rest = _objectWithoutProperties(_ref, _excluded);
}
```

The bindings moved into the loop scope, but since we were passing the `for` loop's scope, `move_binding_by_symbol_id` was a no-op as the var decls were not defined in the `for` loop's scope.

This PR get's the declared scope of the symbol and uses it rather than assuming that the var is scoped to the function
@graphite-app graphite-app Bot force-pushed the c/05-14-fix_transformer_object-rest-spread_correct_scope_id_when_moving_bindings branch from f969770 to b8fbc1f Compare May 14, 2026 12:07
@graphite-app graphite-app Bot merged commit b8fbc1f into main May 14, 2026
28 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 14, 2026
@graphite-app graphite-app Bot deleted the c/05-14-fix_transformer_object-rest-spread_correct_scope_id_when_moving_bindings branch May 14, 2026 12:11
overlookmotel added a commit that referenced this pull request May 15, 2026
### 🚀 Features

- bc91a17 codegen: Expose `Codegen::with_source_type` method (#22432)
(camc314)

### 🐛 Bug Fixes

- 5ac7e79 minifier: Drop unused-var-init pure IIFEs and preserve
annotation for downstream (#22349) (Dunqing)
- 4ab57eb allocator: Fixed-size allocators use `VirtualAlloc` on Windows
(#22124) (overlookmotel)
- 66d77eb allocator: Fix segfault on Linux MUSL with fixed-size
allocators (#22388) (overlookmotel)
- b8fbc1f transformer/object-rest-spread: Correct scope id when moving
bindings (#22419) (camc314)
- 18edc2c codegen: Keep `Object.defineProperty` property name as plain
string in minify (#22400) (Dunqing)
- dda33de transformer/explicit-resource-management: Align lexical
binding scopes (#22320) (camc314)
- 8e79de8 transformer: Preserve for-await statement bodies (#22361)
(camc314)
- 0cba210 transformer/class: Replace `new.target` in static blocks
(#22360) (camc314)
- 67ab1c9 transformer/es2018/for-await: Hoist for-await generated
bindings (#22355) (camc314)
- c3ceb4a transformer/object-rest-spread: Use hoisted scope for `for-of`
temp refs (#22347) (camc314)

### ⚡ Performance

- 73a9043 allocator/bitset: Avoid temp heap `String` allocation (#22403)
(camc314)
- 8b2f4f9 transformer/object-rest-spread: Collect `Vec<SymbolId` over
`Vec<BindingIdentifier>` (#22418) (camc314)
- 83679ea parser: Split TriviaBuilder::handle_token hot/cold paths
(#22415) (Boshen)
- 2c7d781 codegen: Inline identifier-name accessors (#22411) (Boshen)
- 618bc76 diagnostics: Inline `OxcDiagnosticInner` to avoid heap
allocation (#22406) (Boshen)
- 0b4e158 parser: Reserve cap `2` for sequence expressions vec (#22374)
(camc314)
- 5f3bdd0 codegen: Add `#[inline]` to `code`, `code_len` (#22373)
(camc314)

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

Labels

A-transformer Area - Transformer / Transpiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants