swc-project
swc
BlogDocsChangelog

Performance History

Latest Results

feat(swc_ecma_transformer): Add common utilities infrastructure Implements common utilities and helper infrastructure needed by all transformers, following the design from oxc_transformer but adapted for SWC's AST and patterns. ## Changes ### New Files **src/common/mod.rs** - Module organization and re-exports for all common utilities **src/common/helper_loader.rs** - Helper function management with three modes: Runtime, External, and Inline (not yet implemented) - `HelperLoader` for managing helper function expressions - Support for creating helper calls with proper AST nodes - Comprehensive tests covering all helper modes **src/common/statement_injector.rs** - Statement injection utilities for inserting statements before/after AST nodes - `StatementInjector` for managing positional statement insertions - Position-based approach adapted from oxc's address-based system - Full test coverage for injection ordering and edge cases **src/common/var_declarations.rs** - Variable declaration management for inserting at top of scopes - `VarDeclarations` for collecting and building var/let/const declarations - Support for both simple identifiers and complex patterns - Tests for all declaration types and building scenarios **src/common/module_imports.rs** - Import statement management and deduplication - `ModuleImports` for tracking default and named imports - Preserves source order for predictable output - Full test suite for import generation and ordering ### Modified Files **src/lib.rs** - Added public export of `common` module ## Implementation Notes - All utilities work with SWC's AST types (not oxc's) - Uses `swc_common::DUMMY_SP` for spans where appropriate - Follows CLAUDE.md guidelines: performance-focused, well-documented - String-based API for flexibility (converted to Atom internally) - All modules have comprehensive unit tests (43 tests total) - cargo fmt and cargo clippy pass with -D warnings ## Testing All tests pass: ``` cargo test -p swc_ecma_transformer ``` Clippy passes with no warnings: ``` cargo clippy -p swc_ecma_transformer -- -D warnings ``` ## Related - Follow-up to PR #11273 (hook-based transformer architecture) - Based on oxc_transformer/src/common but adapted for SWC patterns πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
devbird/common-utilities
12 hours ago
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>
dev/pass
14 hours ago
feat: Add OXC transformer adapter infrastructure for VisitMutHook pattern This commit sets up the foundational infrastructure for porting OXC transformers to SWC's VisitMutHook API pattern. ## Changes - Created `oxc_adapter` module in `swc_ecma_transforms` - Implemented `TraverseCtx` type compatible with VisitMutHook pattern - Implemented `Transformer<H, C>` base type that bridges VisitMut and VisitMutHook - Added comprehensive documentation and README explaining the architecture - Included example transformer demonstrating the pattern - All tests passing (11/11) ## Architecture The adapter enables composable transformers using the hook pattern: - Transformers implement `VisitMutHook<TraverseCtx>` - `Transformer<H, C>` implements `VisitMut` by delegating to hooks - Supports enter/exit methods for AST nodes with context management ## Example ```rust struct MyTransform; impl VisitMutHook<TraverseCtx> for MyTransform { fn enter_expr(&mut self, node: &mut Expr, ctx: &mut TraverseCtx) { // Transform logic } } let mut transformer = Transformer::new(MyTransform, TraverseCtx::new()); program.visit_mut_with(&mut transformer); ``` ## References - OXC Transformer: https://oxc.rs/docs/guide/usage/transformer.html - SWC VisitMutHook: crates/swc_ecma_hooks/src/generated.rs - Detailed architecture: crates/swc_ecma_transforms/src/oxc_adapter/README.md πŸ€– Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
devbird/oxc-transformer-infrastructure
23 hours ago

Active Branches

feat(swc_ecma_transformer): Add common utilities infrastructure
last run
12 hours ago
#11275
CodSpeed Performance Gauge
0%
#11274
CodSpeed Performance Gauge
0%
#11240
CodSpeed Performance Gauge
-9%
Β© 2025 CodSpeed Technology
Home Terms Privacy Docs