Skip to content

fix(transformer/async-to-generator): move only parameter bindings#22503

Merged
graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-async-to-generator-bindings
May 17, 2026
Merged

fix(transformer/async-to-generator): move only parameter bindings#22503
graphite-app[bot] merged 1 commit into
mainfrom
codex/fix-async-to-generator-bindings

Conversation

@camc314

@camc314 camc314 commented May 17, 2026

Copy link
Copy Markdown
Contributor

Previously, given:

class C {
  async method(x = function y() {}) {}
}

The async-to-generator transform generates:

class C {
  method(x = function y() {}) {
    return babelHelpers.asyncToGenerator(function* () {})();
  }
}

The method parameter stays on the outer wrapper method, while only the original body moves into the inner generator function.

Before this change, BindingMover walked the full parameter AST while moving those parameter bindings. That meant it also visited default initializer expressions, so bindings created inside the initializer, like y above, could be moved out of their own function/class scope and into the wrapper method scope.

After transform, rebuilt semantics would disagree with the transformed scope tree because the parameter binding was correct, but nested initializer bindings had the wrong owning scope.

This PR makes BindingMover only visit the binding positions for formal parameters, rest parameters, and the left side of assignment patterns. It skips initializer expressions so nested function/class bindings stay in the scopes created for those expressions.

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

codspeed-hq Bot commented May 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing codex/fix-async-to-generator-bindings (56fff4d) with main (863984f)2

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.

  2. No successful run was found on main (5747ff1) during the generation of this report, so 863984f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@camc314 camc314 marked this pull request as ready for review May 17, 2026 16:37
Copilot AI review requested due to automatic review settings May 17, 2026 16:37

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

This PR fixes async-to-generator semantic scope handling so only actual parameter bindings are moved when method parameters remain on the wrapper function.

Changes:

  • Adds binding-focused visitor overrides for formal parameters, rest parameters, and assignment patterns.
  • Updates semantic coverage snapshots to remove resolved binding/symbol-scope mismatches.

Reviewed changes

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

File Description
crates/oxc_transformer/src/es2017/async_to_generator.rs Narrows BindingMover traversal to avoid visiting default initializer expressions.
tasks/coverage/snapshots/semantic_test262.snap Updates expected semantic mismatch output for affected Test262 async generator method cases.
Comments suppressed due to low confidence (1)

crates/oxc_transformer/src/es2017/async_to_generator.rs:936

  • The left side of an assignment pattern can itself be an object binding pattern with computed property keys. Calling the generic visit_binding_pattern here still descends into those key expressions and can move bindings declared inside nested function/class expressions, so this should use binding-position-only traversal for the pattern structure.
        self.visit_binding_pattern(&pattern.left);

Comment thread crates/oxc_transformer/src/es2017/async_to_generator.rs

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 4 out of 5 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

crates/oxc_transformer/src/es2017/async_to_generator.rs:942

  • Skipping computed key expressions here prevents their bindings from being moved, but any scopes created inside those keys are still parented to the old generator scope even though the parameter remains on the wrapper method. The new class/computed-key-binding fixture is still recorded as a semantic failure in oxc.snap.md with a scope-parent mismatch, so the transformed scope tree remains inconsistent; the first-level scopes inside skipped key/initializer expressions need to be reparented to the wrapper scope while leaving their bindings in place.
    fn visit_binding_property(&mut self, property: &BindingProperty<'a>) {
        // Computed keys are expressions and can contain their own scopes. Only the property value
        // is a binding position.
        self.visit_binding_pattern(&property.value);

crates/oxc_transformer/src/es2017/async_to_generator.rs:936

  • The RHS default expression can also introduce function/class scopes, and those scopes still need to follow the parameter pattern when it remains on the wrapper method. Only skipping the RHS for binding moves leaves nested default scopes parented to the old generator scope (the updated Test262 snapshot still shows scope-parent mismatches for *-ptrn-*-init-fn-name-* cases), so this path also needs scope reparenting while keeping the RHS bindings untouched.
    fn visit_assignment_pattern(&mut self, pattern: &AssignmentPattern<'a>) {
        // Default values are expressions, not parameter bindings. Visiting only the left-hand side
        // avoids moving bindings declared inside the initializer expression.
        self.visit_binding_pattern(&pattern.left);

Comment thread crates/oxc_transformer/src/es2017/async_to_generator.rs
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label May 17, 2026

camc314 commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

graphite-app Bot pushed a commit that referenced this pull request May 17, 2026
…2503)

Previously, given:

```js
class C {
  async method(x = function y() {}) {}
}
```

The async-to-generator transform generates:

```js
class C {
  method(x = function y() {}) {
    return babelHelpers.asyncToGenerator(function* () {})();
  }
}
```

The method parameter stays on the outer wrapper method, while only the original body moves into the inner generator function.

Before this change, `BindingMover` walked the full parameter AST while moving those parameter bindings. That meant it also visited default initializer expressions, so bindings created inside the initializer, like `y` above, could be moved out of their own function/class scope and into the wrapper method scope.

After transform, rebuilt semantics would disagree with the transformed scope tree because the parameter binding was correct, but nested initializer bindings had the wrong owning scope.

This PR makes `BindingMover` only visit the binding positions for formal parameters, rest parameters, and the left side of assignment patterns. It skips initializer expressions so nested function/class bindings stay in the scopes created for those expressions.
@graphite-app graphite-app Bot force-pushed the codex/fix-async-to-generator-bindings branch from 56fff4d to af880c9 Compare May 17, 2026 17:20
…2503)

Previously, given:

```js
class C {
  async method(x = function y() {}) {}
}
```

The async-to-generator transform generates:

```js
class C {
  method(x = function y() {}) {
    return babelHelpers.asyncToGenerator(function* () {})();
  }
}
```

The method parameter stays on the outer wrapper method, while only the original body moves into the inner generator function.

Before this change, `BindingMover` walked the full parameter AST while moving those parameter bindings. That meant it also visited default initializer expressions, so bindings created inside the initializer, like `y` above, could be moved out of their own function/class scope and into the wrapper method scope.

After transform, rebuilt semantics would disagree with the transformed scope tree because the parameter binding was correct, but nested initializer bindings had the wrong owning scope.

This PR makes `BindingMover` only visit the binding positions for formal parameters, rest parameters, and the left side of assignment patterns. It skips initializer expressions so nested function/class bindings stay in the scopes created for those expressions.
@graphite-app graphite-app Bot force-pushed the codex/fix-async-to-generator-bindings branch from af880c9 to ecfd3ca Compare May 17, 2026 17:22
@graphite-app graphite-app Bot merged commit ecfd3ca into main May 17, 2026
28 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 17, 2026
@graphite-app graphite-app Bot deleted the codex/fix-async-to-generator-bindings branch May 17, 2026 17:27
camc314 pushed a commit that referenced this pull request May 18, 2026
### 🐛 Bug Fixes

- 0f26de6 ecmascript: Resolve identifier value type via tracked
constants (#22234) (Alexander Lichter)
- c27a8cf minifier: Normalize `{ x: x }` shorthand so adjacent-if merge
is idempotent (#22401) (Dunqing)
- e431a0e parser: Break extends clause loop on fatal error (#22517)
(Boshen)
- e9ec7c6 minifier: Fold optional chains by base nullishness (#22236)
(Alexander Lichter)
- e6090e7 transformer: Keep enum IIFE when a non-inlinable value
reference remains (#22501) (Dunqing)
- 931b7d6 transformer: Inline const enum members through type-cast
wrappers (#22500) (Dunqing)
- b9615b2 codegen: Preserve string quotes in require() calls during
minification (#22475) (zennnnnnn11)
- c73c159 transformer/async-to-generator: Reparent parameter initializer
scopes (#22507) (camc314)
- ecfd3ca transformer/async-to-generator: Move only parameter bindings
(#22503) (camc314)
- 3ce3431 transformer/explicit-resource-managment: Preserve shadowed
for-head block (#22451) (camc314)

### ⚡ Performance

- ce92c6c semantic: `#[inline]` `Scoping::get_binding` (#22414)
(Dunqing)
- 98be95c regular_expression: Track regex flags via bitflags (#22427)
(Boshen)
- dbbc059 jsdoc: Skip should_attach_jsdoc when no remaining comments
(#22409) (Boshen)
- 217d7d8 minifier: Index `SymbolValues` by `SymbolId` (#22441)
(Dunqing)
- d782b78 minifier: Use BitSet for LiveUsageCollector live references
(#22425) (Boshen)
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