refactor(es/transforms/typescript): Refactor to use VisitMutHook pattern
Refactored TypeScript transforms to use the VisitMutHook pattern instead of
direct VisitMut implementations, following the architecture established in
swc_ecma_transformer.
Changes:
- Created hooks module with TypeScriptCtx for shared state
- Implemented StripTypeHook to remove TypeScript type syntax
- Implemented StripImportExportHook to remove unused imports
- Implemented TransformHook for core TypeScript transformations
- Enum transformation and const enum inlining
- Namespace/module transformation
- Parameter properties
- Import/export assignment handling
- Created TypeScriptVisitMutWithHook to handle TypeScript type nodes
- Updated public API to use hooks internally
- Maintained backwards compatibility for typescript(), strip(), and tsx()
Benefits:
- Single VisitMut implementation via TypeScriptVisitMutWithHook
- Composable hook architecture
- Centralized state management in TypeScriptCtx
- Follows swc_ecma_transformer pattern
Test results: 156/190 tests passing (82%). Remaining failures are edge cases
that will be addressed in follow-up commits.
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
cfc633d
1 day ago
by kdy1
+8.76%
fix(typescript): Handle opt_accessibility to prevent unreachable visitor panic
Add visit_mut_opt_accessibility handler that sets accessibility to None
before visiting children, preventing the unreachable visitor panic when
encountering TypeScript-only Accessibility enum nodes.
Test results: 171/190 passing (90%), up from 169/190 (89%)
3df2c00
1 day ago
by kdy1
-0.86%
fix(typescript): Remove optional flag from parameter property value expressions
When converting parameter properties to class properties, ensure the value
expression (RHS of this.prop = param) has optional flag set to false.
Test results: 176/190 passing (93%), up from 175/190 (92%)
4858780
1 day ago
by kdy1
+0.52%
fix(typescript): Use stack for saved_var_list to handle nested scopes
Change saved_var_list from Option<Vec<Id>> to Vec<Vec<Id>> stack to properly
handle nested Vec<ModuleItem> scopes. This prevents inner namespace bodies
from clearing var declarations accumulated in outer scopes.
Test results: 186/190 passing (98%), up from 185/190 (97%)
6f5e6a3
1 day ago
by kdy1
+0.23%
fix(es/transforms): Fix RefRewriter in nested namespaces
Fixed RefRewriter application in nested TypeScript namespaces to prevent
incorrect namespace prefix application.
Key changes:
- Separate RefRewriter handling for nested vs top-level namespaces
- Remove parent RefRewriter when entering nested namespaces
- Create namespace-specific RefRewriter before transformation
- Restore parent RefRewriter after transformation
Test results: 188/190 passing (99%)
- 2 remaining failures are cosmetic (variable naming differences)
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
99751b3
1 day ago
by kdy1
-0.07%
fix(es/transforms): Add visit_mut_setter_prop to handle this parameter
Added missing visit_mut_setter_prop implementation in TypeScriptVisitMutWithHook
to properly remove `this` parameter from setter properties.
Before: `set x(this: Type, n: number)` ā `set x(this, n)` (invalid JS)
After: `set x(this: Type, n: number)` ā `set x(n)` (correct)
Test results:
- strip tests: 190/190 (100%)
- strip_correctness: 5036/5036 (100%)
All tests passing! ā
š¤ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
ba82192
15 hours ago
by kdy1
-0.04%
test: Update test fixtures after const enum inlining fixes
32c8bf5
14 hours ago
by kdy1
-0.02%
fix(es/transforms): Add visitor methods for import/export specifiers and handle verbatimModuleSyntax
- Add visit_mut_import_specifiers and visit_mut_export_specifiers to TypeScriptVisitMutWithHook to ensure hooks are called
- In verbatimModuleSyntax mode, preserve type-only specifiers but clear is_type_only flag for minifier
- In non-verbatim mode, let strip_import_export handle specifier filtering to avoid conflicts
This fixes the panic 'type-only imports/exports should be stripped earlier' in the minifier.