No successful run was found on main (f150275) during the generation of this report, so 707026b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.
feat(es/transformer): Implement hook-based transformer architecture (#11273)
## Summary
Implements the foundational structure for `swc_ecma_transformer`, a new
crate that provides a hook-based transformer architecture using the
`swc_ecma_hooks` API.
This PR sets up the basic infrastructure for porting oxc_transformer
functionality to SWC's API.
## Changes
### Cargo.toml
- Added `swc_ecma_hooks` as a dependency
### src/lib.rs
- Implemented `Transformer` struct that implements `VisitMut` trait
- Provides architecture for composable hook-based transformation passes
- Includes comprehensive documentation with examples
- Added 5 unit tests covering core functionality
- Re-exports necessary types from dependencies
### src/context.rs
- Implemented `TransformCtx` for passing state between hooks
- Holds:
- `source_path`: PathBuf to the source file
- `source_text`: Arc<String> of file contents
- `source_map`: Arc<SourceMap> for location tracking
- `handler`: Arc<Handler> for error reporting
- Provides error reporting methods: `emit_error()` and
`struct_span_err()`
### src/options.rs
- Implemented `TransformOptions` using bitflags
- Allows fine-grained control over enabled transforms
- Supports:
- ES2015-ES2022 transform passes
- TypeScript transforms
- React/JSX transforms
- Optimization passes
- Provides convenience methods to check which transforms are enabled
## Architecture
The transformer follows a pattern similar to oxc_transformer but adapted
for SWC:
1. **Main Transformer**: Implements `VisitMut` trait and orchestrates
all passes
2. **TransformCtx**: Provides shared state accessible to all hooks
3. **Sub-transformers**: Will implement `VisitMutHook<TransformCtx>` (to
be added in future PRs)
4. **TransformOptions**: Controls which transformation passes execute
## Design Decisions
- Uses `Arc<SourceMap>` and `Arc<Handler>` for thread-safe sharing
across hooks
- Follows CLAUDE.md guidelines:
- Performance-focused (minimal allocations, efficient visitor patterns)
- No nightly-only features
- Prefers `&str` and `Cow<str>` for `Atom` instances
- Includes unit tests
- Comprehensive documentation
- Clear module structure for future extensibility
## Testing
All tests pass:
```
cargo test -p swc_ecma_transformer
```
Clippy passes with no warnings:
```
cargo clippy -p swc_ecma_transformer -- -D warnings
```
## Next Steps
Future PRs will add:
- Individual transform hooks implementing `VisitMutHook<TransformCtx>`
- Integration with existing SWC transform passes
- Performance benchmarks
- Additional transform passes ported from oxc_transformer
## Related
- Based on:
https://github.com/oxc-project/oxc/tree/main/crates/oxc_transformer
- Uses: `swc_ecma_hooks` API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>