From 072bd130239579566d319a47156c570277cebb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 18 Nov 2022 15:35:49 +0900 Subject: [PATCH] fix(es/modules): Remove wrong check for `jsc.paths` (#6470) **Related issue:** - Closes https://github.com/swc-project/swc/issues/6466. --- crates/swc_ecma_transforms_module/src/path.rs | 8 ++++++-- .../tests/paths/issue-4532/output/index.ts | 2 +- .../tests/paths/issue-4585/output/index.ts | 2 +- .../tests/paths/issue-4605/1/output/index.ts | 2 +- .../tests/paths/issue-4605/2/output/index.ts | 2 +- .../tests/paths/issue-4619/1/output/index.ts | 2 +- .../tests/paths/issue-4619/2/output/index.ts | 2 +- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_transforms_module/src/path.rs b/crates/swc_ecma_transforms_module/src/path.rs index 75637e87322..67378f5fe56 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 7cc1229f0a6..a6dad7b1a7b 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 c1a93de2a8e..6c84f6bfbe5 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 c15108b16ba..37dcc5d213e 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 c15108b16ba..2061bc75225 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 c15108b16ba..37dcc5d213e 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 c15108b16ba..2061bc75225 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";