fix(transformer/object-rest-spread): use hoisted scope for for-of temp refs#22347
Conversation
for-of temp refs
There was a problem hiding this comment.
Pull request overview
This PR fixes scope hoisting for the temporary ref binding introduced when transforming for-in / for-of statement left-hand patterns that contain nested object rest/spread, ensuring the generated temp variable is bound in the correct hoist (function) scope for semantic consistency.
Changes:
- Hoist the generated
refbinding toctx.current_hoist_scope_id()when rewritingfor-in/for-ofleft-hand targets containing object rest. - Update semantic coverage snapshots reflecting improved pass counts and removal of several prior scope/binding mismatch errors.
Reviewed changes
Copilot reviewed 1 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/oxc_transformer/src/es2018/object_rest_spread.rs | Generates the temp ref binding in the current hoist scope during for-statement left rewrites. |
| tasks/coverage/snapshots/semantic_typescript.snap | Snapshot update reflecting improved semantic results (fewer transformer/rebuild mismatches). |
| tasks/coverage/snapshots/semantic_test262.snap | Snapshot update reflecting improved semantic results (fewer transformer/rebuild mismatches). |
Merging this PR will not alter performance
Comparing Footnotes
|
Merge activity
|
…emp refs (#22347) The transform rewrites cases like: ```js for ({ ...rest } of [{}]) {} ``` to use a generated `var` binding in the loop head: ```js for (var _ref of [{}]) { // ... } ``` Previously, the generated `_ref` binding was being created in the loop statment scope (`current_scope_id`), this is incorrect because it is being emitted as `var`. The rebuilt semantic correctly shows it being hoisted into the current var-hoist scope.
e6b029f to
c3ceb4a
Compare
### 🚀 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]>
The transform rewrites cases like:
to use a generated
varbinding in the loop head:Previously, the generated
_refbinding was being created in the loop statment scope (current_scope_id), this is incorrect because it is being emitted asvar. The rebuilt semantic correctly shows it being hoisted into the current var-hoist scope.