diff --git a/crates/swc_ecma_transforms_module/src/path.rs b/crates/swc_ecma_transforms_module/src/path.rs index 75637e87322d..67378f5fe563 100644 --- a/crates/swc_ecma_transforms_module/src/path.rs +++ b/crates/swc_ecma_transforms_module/src/path.rs @@ -121,13 +121,17 @@ where if let Some(orig_ext) = orig_ext { let use_orig = if let Some(ext) = p.extension() { - (ext == "ts" || ext == "tsx") && p.is_file() + ext == "ts" || ext == "tsx" } else { false }; if use_orig { - p.set_extension(orig_ext); + if matches!(orig_ext, "js" | "mjs" | "cjs" | "jsx") { + p.set_extension(orig_ext); + } else { + p.set_extension(""); + } } } else { p.set_extension(""); diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-4532/output/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-4532/output/index.ts index 7cc1229f0a67..a6dad7b1a7bd 100644 --- a/crates/swc_ecma_transforms_module/tests/paths/issue-4532/output/index.ts +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-4532/output/index.ts @@ -1 +1 @@ -import "./rel.ts"; +import "./rel.js"; diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-4585/output/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-4585/output/index.ts index c1a93de2a8ee..6c84f6bfbe5d 100644 --- a/crates/swc_ecma_transforms_module/tests/paths/issue-4585/output/index.ts +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-4585/output/index.ts @@ -1 +1 @@ -import "./src/feat.ts"; +import "./src/feat.js"; diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-4605/1/output/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-4605/1/output/index.ts index c15108b16ba7..37dcc5d213e8 100644 --- a/crates/swc_ecma_transforms_module/tests/paths/issue-4605/1/output/index.ts +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-4605/1/output/index.ts @@ -1 +1 @@ -import "./src/rel.decorator.ts"; +import "./src/rel.decorator.js"; diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-4605/2/output/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-4605/2/output/index.ts index c15108b16ba7..2061bc752252 100644 --- a/crates/swc_ecma_transforms_module/tests/paths/issue-4605/2/output/index.ts +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-4605/2/output/index.ts @@ -1 +1 @@ -import "./src/rel.decorator.ts"; +import "./src/rel.decorator"; diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-4619/1/output/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-4619/1/output/index.ts index c15108b16ba7..37dcc5d213e8 100644 --- a/crates/swc_ecma_transforms_module/tests/paths/issue-4619/1/output/index.ts +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-4619/1/output/index.ts @@ -1 +1 @@ -import "./src/rel.decorator.ts"; +import "./src/rel.decorator.js"; diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-4619/2/output/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-4619/2/output/index.ts index c15108b16ba7..2061bc752252 100644 --- a/crates/swc_ecma_transforms_module/tests/paths/issue-4619/2/output/index.ts +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-4619/2/output/index.ts @@ -1 +1 @@ -import "./src/rel.decorator.ts"; +import "./src/rel.decorator";