Pull requests Create short-walls-perform.md magic-akari:fix/issue-11142 CodSpeed Performance Gauge 0%
Create little-grapes-attend.md magic-akari:fix/issue-9198 CodSpeed Performance Gauge 0%
fix(es2015): prevent injecting this binding inside arrow body
- Only set cur_stmt_address if not already set in current scope
- This ensures we inject 'var _this = this' before the statement containing the arrow
- Prevents injection inside arrow body (e.g., inside if blocks)
Fixes issue where _this declaration was being injected inside conditional blocks
instead of at the beginning of the enclosing function. devbird/arrow-functions-transform CodSpeed Performance Gauge 0%
feat(es2017): Migrate async/await to generator transform to hook-based architecture
## Summary
Implement async/await to generator transformation in the new hook-based transformer architecture, migrating from the legacy `swc_ecma_compat_es2017` crate.
## Changes
### New Implementation
- Add `crates/swc_ecma_transformer/src/es2017/async_to_generator.rs`
- Implements `VisitMutHook<TraverseCtx>` trait for hook-based traversal
- Transforms async functions to generator functions wrapped with helper
- Transforms await expressions to yield expressions
- Handles for-await-of loops with proper iterator protocol
- Supports async arrow functions and async methods
- Handles `this`, `arguments`, and `super` references correctly
### ES2017 Module Integration
- Update `crates/swc_ecma_transformer/src/es2017/mod.rs`
- Wire up `async_to_generator` hook to `Es2017Pass`
- Add `Config` option to enable/disable the transform
- Delegate all relevant hook methods to the transform
### Hook Utilities
- Update `crates/swc_ecma_transformer/src/hook_utils.rs`
- Add missing hook methods to `OptionalHook`:
- `enter/exit_function`, `enter/exit_arrow_expr`
- `enter/exit_class`, `enter/exit_constructor`
- `enter/exit_getter_prop`, `enter/exit_setter_prop`
- `enter/exit_super`
### Transformer Module
- Update `crates/swc_ecma_transformer/src/lib.rs`
- Make `es2017` module public for external access
### Preset Environment Integration
- Update `crates/swc_ecma_preset_env/src/lib.rs`
- Replace legacy `es2017::async_to_generator` with new hook-based version
- Set `options.env.es2017.async_to_generator` when feature not supported
- Pass `unresolved_ctxt` to the transform config
## Technical Details
### Transform Rules
The implementation follows the Babel spec for async/await transformation:
```javascript
// Input
async function foo() {
const result = await bar();
return result;
}
// Output
function foo() {
return _asyncToGenerator(function* () {
const result = yield bar();
return result;
}).apply(this, arguments);
}
```
Key behaviors:
- Convert async functions to generator functions wrapped with `_asyncToGenerator` helper
- Transform await expressions to yield expressions
- Preserve `this`, `arguments`, and `super` bindings
- Handle function parameter evaluation errors
- Transform for-await-of loops to try-catch-finally with iterator protocol
### Compatibility
- Legacy `swc_ecma_compat_es2017` crate unchanged for backward compatibility
- New implementation used by `swc_ecma_preset_env` for single-pass compilation
- Config stores `unresolved_ctxt` for proper scope handling
## References
- Babel plugin: https://github.com/babel/babel/tree/main/packages/babel-plugin-transform-async-to-generator
- Oxc implementation: https://github.com/oxc-project/oxc/blob/main/crates/oxc_transformer/src/es2017/async_to_generator.rs
- Previous migrations: PR #11310, PR #11313
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com> devbird/async-to-generator-transform CodSpeed Performance Gauge 0%
© 2025 CodSpeed Technology