fix: rewriteRelativeImportExtensions with TypeScript path aliases
Fixes #11143
## Problem
When both `rewriteRelativeImportExtensions: true` and `jsc.paths` were configured,
the extension rewriting would not work for imports using path aliases.
For example:
- Input: `export { a } from "@/util/index.ts";`
- Previous output: `export { a } from "./util/index.ts";` (extension NOT rewritten)
- Fixed output: `export { a } from "./util/index.js";` (extension correctly rewritten)
## Root Cause
The transformation passes were executing in the wrong order:
1. `typescript_import_rewriter()` ran first, checking for relative paths (`./` or `../`)
2. Since `@/util/index.ts` doesn't start with `./` or `../`, it skipped rewriting
3. `import_rewriter()` ran second and resolved `@/util/index.ts` → `./util/index.ts`
4. But the extension rewriter had already run, so `.ts` was never rewritten to `.js`
## Solution
Integrated extension rewriting directly into `NodeImportResolver`:
1. Added `rewrite_import_extensions: bool` field to `Config` in `path.rs`
2. Implemented `rewrite_extension()` method that applies the same logic as TypeScript's
`rewriteRelativeImportExtensions` after path resolution
3. Updated the main config to pass this flag through to the resolver
4. Modified the pass logic to skip the separate `typescript_import_rewriter` pass
when using a resolver with extension rewriting enabled
This ensures extension rewriting happens AFTER path alias resolution, fixing the issue.
## Changes
- `crates/swc_ecma_transforms_module/src/path.rs`:
- Added `rewrite_import_extensions` field to `Config` struct
- Implemented `rewrite_extension()` helper method
- Applied extension rewriting in `to_specifier()` after path resolution
- `crates/swc/src/config/mod.rs`:
- Updated `build_resolver()` to accept `rewrite_import_extensions` parameter
- Updated `get_resolver()` to accept and pass through the flag
- Modified resolver cache key to include `rewrite_import_extensions`
- Updated pass logic to conditionally use separate rewriter only when needed
## Tests
Added comprehensive test in `crates/swc/tests/fixture/issues-11xxx/11143/` covering:
- Path aliases with `.ts` → `.js`
- Path aliases with `.tsx` → `.jsx`
- Path aliases with `.mts` → `.mjs`
- Path aliases with `.cts` → `.cjs`
- Regular relative imports (regression test)
- Export all statements
- Dynamic imports
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>