-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(es/transformer): Merge async_to_generator
#11358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 7e752ea The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Code Review for PR #11358: Merge
|
Binary Sizes
Commit: cdac0ff |
CodSpeed Performance ReportMerging #11358 will improve performances by 2.43%Comparing Summary
Benchmarks breakdown
Footnotes |
85328f7 to
d98434d
Compare
Pull Request Review: feat(es/transformer): Merge
|
This implements the async-to-generator transformation using the new VisitMutHook system in swc_ecma_transformer, replacing the old VisitMut-based implementation. Key changes: - Implemented AsyncToGeneratorPass using VisitMutHook<TraverseCtx> - Added function state stack to properly handle nested async functions - Transforms async functions/arrow functions to generator functions wrapped in asyncToGenerator helper - Handles for-await-of loops - Properly tracks `this`, `arguments`, and `super` usage - Supports async generators with wrapAsyncGenerator helper Test results: 146 out of 150 tests passing (4 known edge cases with constructor hoisting remain) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Pull Request ReviewThis PR merges the transformation from into to align with the new hook-based architecture. Overall, the refactoring is well-structured, but there are several issues that need attention. Critical Issues1. Missing
|
Removed performance overhead from should_work checks in async-to-generator transformation. The hook-based architecture already handles traversal efficiently, making pre-checking unnecessary. Changes: - Removed should_work usage from exit_expr and exit_stmt - Removed ShouldWork visitor struct and Check trait impl - Simplified enter_constructor by removing should_work check - All tests still pass (146/150) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Code Review for PR #11358: Merge
|
This commit fixes the handling of async arrow expressions that use `this` inside subclass constructors. The key changes are: 1. Track `in_constructor` state in FnState to know when we're inside a constructor 2. For async arrows in constructors that use `this`, run FnEnvHoister on the arrow body to replace `this` with `_this` 3. Don't use `.call(this)` for arrows in constructor context since `this` has been replaced with `_this` 4. In exit_constructor, run FnEnvHoister on the entire constructor body to add the `var _this; _this = this` hoisting pattern 5. Fix bug in enter_class that was immediately reverting the in_subclass flag 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…cement Replace FnEnvHoister usage with direct `this` to `_this` replacement for async arrows in constructors. This approach is simpler and more reliable: - Add `this_var` field to track the `_this` identifier - Implement `replace_this_in_*` helper functions to recursively replace `this` expressions with `_this` in arrow body - In exit_constructor, directly create `var _this;` declaration and add `_this = this` after super() call - Remove FnEnvHoister usage for constructor context This fixes issue_8452 and issue_9432 where async arrows using `this` in constructors were not properly transformed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Pull Request Review: feat(es/transformer): Merge
|
PR Review: feat(es/transformer): Merge
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Pull Request Review: Merge async_to_generator into swc_ecma_transformerI've reviewed this PR which migrates the ✅ Strengths
|
Updated package versions for swc dependencies to patch.
There was a problem hiding this 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 refactors the async_to_generator transform by merging it into the unified transformer architecture. The transform is moved from a standalone visitor-based implementation to a hook-based system that integrates with the new swc_ecma_transformer infrastructure.
Key Changes
- Reimplemented
async_to_generatoras aVisitMutHookinstead of aVisitMutvisitor - Integrated the transform into the unified options and hook chain system
- Added support for tracking constructor context to properly handle
thisin async arrows within class constructors - Migrated from the old compat API to the new transformer API
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
crates/swc_ecma_transformer/src/lib.rs |
Updated es2017::hook() call to pass additional parameters (unresolved_ctxt and ignore_function_length) |
crates/swc_ecma_transformer/src/hook_utils.rs |
Added optional hook methods for function, arrow expression, class, constructor, getter/setter properties, and super |
crates/swc_ecma_transformer/src/es2017/mod.rs |
Refactored to conditionally return async_to_generator hook based on options instead of empty pass |
crates/swc_ecma_transformer/src/es2017/async_to_generator.rs |
New implementation with hook-based visitor, enhanced constructor context tracking, and this replacement logic |
crates/swc_ecma_preset_env/src/lib.rs |
Simplified to set options.env.es2017.async_to_generator = true instead of directly instantiating the transform |
crates/swc_ecma_compat_es2017/src/async_to_generator.rs |
Converted to thin wrapper that delegates to swc_ecma_transformer::Options |
crates/swc_ecma_compat_es2017/Cargo.toml |
Updated dependencies to include swc_ecma_transformer and removed swc_ecma_visit and swc_trace_macro |
crates/swc/tests/fixture/issues-4xxx/4208/1/output/index.ts |
Test output shows improved this binding with .call(_this) for proper context preservation |
Cargo.lock |
Reflects the dependency changes in swc_ecma_compat_es2017 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fn replace_this_in_expr_or_spread(expr: &mut ExprOrSpread, this_var: &Ident) { | ||
| replace_this_in_expr(&mut expr.expr, this_var); | ||
| } |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function replace_this_in_expr_or_spread is defined but never used. Consider removing it or using it where appropriate.
| fn replace_this_in_expr_or_spread(expr: &mut ExprOrSpread, this_var: &Ident) { | |
| replace_this_in_expr(&mut expr.expr, this_var); | |
| } |
Pull Request Review: Merge
|
Co-authored-by: Claude <[email protected]>
No description provided.