From 23f248ecf12af71dea08e8194baa06810a0c01b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 3 Nov 2022 12:21:25 +0900 Subject: [PATCH 1/7] Add a test --- .../fixture/issues-6xxx/6209/1/input/.swcrc | 17 +++++++++++++++++ .../fixture/issues-6xxx/6209/1/input/index.js | 2 ++ 2 files changed, 19 insertions(+) create mode 100644 crates/swc/tests/fixture/issues-6xxx/6209/1/input/.swcrc create mode 100644 crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js diff --git a/crates/swc/tests/fixture/issues-6xxx/6209/1/input/.swcrc b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/.swcrc new file mode 100644 index 000000000000..6667bf9adf99 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/.swcrc @@ -0,0 +1,17 @@ +{ + "jsc": { + "baseUrl": "./src", + "paths": { + "@modules/*": [ + "./modules/*" + ] + }, + "target": "es2020", + "parser": { + "syntax": "typescript" + } + }, + "module": { + "type": "es6" + } +} \ No newline at end of file diff --git a/crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js new file mode 100644 index 000000000000..c590629eb56e --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js @@ -0,0 +1,2 @@ +import { modulo } from '@modules/style.module.less' +import { sum } from './sum.js' \ No newline at end of file From b8a9a6ad2b4081d255cfd3790790cd536229b138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 3 Nov 2022 12:29:48 +0900 Subject: [PATCH 2/7] Add a test --- .../issues-6xxx/6209/1/input/src/modules/style.module.less | 0 crates/swc/tests/fixture/issues-6xxx/6209/1/input/src/sum.ts | 5 +++++ 2 files changed, 5 insertions(+) create mode 100644 crates/swc/tests/fixture/issues-6xxx/6209/1/input/src/modules/style.module.less create mode 100644 crates/swc/tests/fixture/issues-6xxx/6209/1/input/src/sum.ts diff --git a/crates/swc/tests/fixture/issues-6xxx/6209/1/input/src/modules/style.module.less b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/src/modules/style.module.less new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/crates/swc/tests/fixture/issues-6xxx/6209/1/input/src/sum.ts b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/src/sum.ts new file mode 100644 index 000000000000..dc49d21f7793 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/src/sum.ts @@ -0,0 +1,5 @@ + + +export function sum(a: number, b: number) { + return a + b; +} \ No newline at end of file From bbb49b64f79a4029d28fc51ac7e6b409cea68b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 3 Nov 2022 12:30:13 +0900 Subject: [PATCH 3/7] fixup --- crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js index c590629eb56e..8b88c85e2edf 100644 --- a/crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js +++ b/crates/swc/tests/fixture/issues-6xxx/6209/1/input/index.js @@ -1,2 +1,5 @@ import { modulo } from '@modules/style.module.less' -import { sum } from './sum.js' \ No newline at end of file +import { sum } from './sum.js' + +console.log(modulo) +console.log(sum) \ No newline at end of file From 29f3ab20ab46f0b749f45f4ce383bac242e8b232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 3 Nov 2022 12:35:40 +0900 Subject: [PATCH 4/7] Don't touch ext --- crates/swc_ecma_transforms_module/src/path.rs | 58 ++----------------- 1 file changed, 6 insertions(+), 52 deletions(-) diff --git a/crates/swc_ecma_transforms_module/src/path.rs b/crates/swc_ecma_transforms_module/src/path.rs index a2dab8ccf6f3..f987931f8a12 100644 --- a/crates/swc_ecma_transforms_module/src/path.rs +++ b/crates/swc_ecma_transforms_module/src/path.rs @@ -112,51 +112,13 @@ where R: Resolve, { fn resolve_import(&self, base: &FileName, module_specifier: &str) -> Result { - fn to_specifier( - target_path: &str, - is_file: Option, - orig_ext: Option<&str>, - ) -> JsWord { - let mut p = PathBuf::from(target_path); + fn to_specifier(target_path: &str, orig_ext: Option<&str>) -> JsWord { + let p = PathBuf::from(target_path); if cfg!(debug_assertions) { trace!("to_specifier: orig_ext={:?}", orig_ext); } - let dot_count = p - .file_name() - .map(|s| s.to_string_lossy()) - .map(|v| v.as_bytes().iter().filter(|&&c| c == b'.').count()) - .unwrap_or(0); - - match orig_ext { - Some(orig_ext) => { - if is_file.unwrap_or_else(|| p.is_file()) { - if let Some(..) = p.extension() { - if orig_ext == "ts" - || orig_ext == "tsx" - || orig_ext == "js" - || orig_ext == "jsx" - || dot_count == 1 - { - p.set_extension(orig_ext); - } else { - p.set_extension(""); - } - } - } - } - _ => { - if is_file.unwrap_or_else(|| p.is_file()) { - if let Some(v) = p.extension() { - if v == "ts" || v == "tsx" || v == "js" || v == "jsx" { - p.set_extension(""); - } - } - } - } - } - p.display().to_string().into() } @@ -197,7 +159,7 @@ where let mut target = match target { FileName::Real(v) => v, - FileName::Custom(s) => return Ok(to_specifier(&s, None, orig_ext)), + FileName::Custom(s) => return Ok(to_specifier(&s, orig_ext)), _ => { unreachable!( "Node path provider does not support using `{:?}` as a target file name", @@ -222,8 +184,6 @@ where } }; - let is_file = target.is_file(); - if base.is_absolute() != target.is_absolute() { base = Cow::Owned(absolute_path(&base)?); target = absolute_path(&target)?; @@ -239,13 +199,7 @@ where let rel_path = match rel_path { Some(v) => v, - None => { - return Ok(to_specifier( - &target.display().to_string(), - Some(is_file), - orig_ext, - )) - } + None => return Ok(to_specifier(&target.display().to_string(), orig_ext)), }; { @@ -273,9 +227,9 @@ where Cow::Owned(format!("./{}", s)) }; if cfg!(target_os = "windows") { - Ok(to_specifier(&s.replace('\\', "/"), Some(is_file), orig_ext)) + Ok(to_specifier(&s.replace('\\', "/"), orig_ext)) } else { - Ok(to_specifier(&s, Some(is_file), orig_ext)) + Ok(to_specifier(&s, orig_ext)) } } } From c8226e703bc0bf34e9ac0e20b0921e49fa9c4272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 3 Nov 2022 12:36:27 +0900 Subject: [PATCH 5/7] Update test refs --- crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts | 4 ++-- crates/swc/tests/fixture/deno/paths/ext/002/output/index.js | 2 +- .../tests/fixture/deno/paths/issue-2126/output/src/index.ts | 2 +- .../tests/fixture/deno/paths/issue-2724/output/src/index.ts | 2 +- .../tests/fixture/deno/paths/issue-2844/output/src/index.ts | 2 +- .../tests/fixture/deno/paths/issue-3447/output/src/index.ts | 2 +- crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts | 2 +- crates/swc/tests/fixture/issues-5xxx/5214/1/output/input1.js | 2 +- crates/swc/tests/fixture/issues-6xxx/6209/1/output/index.js | 4 ++++ crates/swc/tests/fixture/issues-6xxx/6209/1/output/src/sum.ts | 3 +++ 10 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 crates/swc/tests/fixture/issues-6xxx/6209/1/output/index.js create mode 100644 crates/swc/tests/fixture/issues-6xxx/6209/1/output/src/sum.ts diff --git a/crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts b/crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts index 9f255ccd22b9..11591cb3a0be 100644 --- a/crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts +++ b/crates/swc/tests/fixture/deno/paths/cjs-001/output/index.ts @@ -2,5 +2,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); -require("./src/dep"); -require("./src2/dep-2"); +require("./src/dep.ts"); +require("./src2/dep-2.ts"); diff --git a/crates/swc/tests/fixture/deno/paths/ext/002/output/index.js b/crates/swc/tests/fixture/deno/paths/ext/002/output/index.js index 507538549ede..1d68a591e3a7 100644 --- a/crates/swc/tests/fixture/deno/paths/ext/002/output/index.js +++ b/crates/swc/tests/fixture/deno/paths/ext/002/output/index.js @@ -1,2 +1,2 @@ -import styles from "./foo.ts/index"; +import styles from "./foo.ts/index.js"; console.log(styles); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts index 758fa00b7554..b024100feb55 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2126/output/src/index.ts @@ -2,5 +2,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); -const _a = require("../packages/a/src/index"); +const _a = require("../packages/a/src/index.ts"); console.log(`${(0, _a.displayA)()}`); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts index 74bb44625548..2726f8072753 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2724/output/src/index.ts @@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", { }); const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default; (async function() { - const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("../packages/a/src/index"))); + const { displayA } = await Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("../packages/a/src/index.ts"))); console.log(displayA()); })(); diff --git a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts index 347a167bd2a8..421163deab5b 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-2844/output/src/index.ts @@ -2,7 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); -require("./core/module/moduleFile"); +require("./core/module/moduleFile.ts"); require("./core/utils"); require("./core/utilFile"); require("./utils"); diff --git a/crates/swc/tests/fixture/deno/paths/issue-3447/output/src/index.ts b/crates/swc/tests/fixture/deno/paths/issue-3447/output/src/index.ts index 15e2d82f6423..a0e940e3c15d 100644 --- a/crates/swc/tests/fixture/deno/paths/issue-3447/output/src/index.ts +++ b/crates/swc/tests/fixture/deno/paths/issue-3447/output/src/index.ts @@ -1,3 +1,3 @@ -import { sum } from "./modules/01-moduleA/utils"; +import { sum } from "./modules/01-moduleA/utils.ts"; export { multiply } from "./modules/03-moduleB/utils"; console.log(sum(1, 2)); diff --git a/crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts b/crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts index bd701c668316..0a38545ffb9f 100644 --- a/crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts +++ b/crates/swc/tests/fixture/issues-2xxx/2050/output/index.ts @@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); const _interopRequireDefault = require("@swc/helpers/lib/_interop_require_default.js").default; -const _a = /*#__PURE__*/ _interopRequireDefault(require("./subfolder/A")); +const _a = /*#__PURE__*/ _interopRequireDefault(require("./subfolder/A.ts")); console.log(_a.default); diff --git a/crates/swc/tests/fixture/issues-5xxx/5214/1/output/input1.js b/crates/swc/tests/fixture/issues-5xxx/5214/1/output/input1.js index b8705cb5fcb5..bb6c4dec6fa9 100644 --- a/crates/swc/tests/fixture/issues-5xxx/5214/1/output/input1.js +++ b/crates/swc/tests/fixture/issues-5xxx/5214/1/output/input1.js @@ -1,2 +1,2 @@ -import styles from "./src/foo.bar.baz"; +import styles from "./src/foo.bar.baz.js"; console.log(styles); diff --git a/crates/swc/tests/fixture/issues-6xxx/6209/1/output/index.js b/crates/swc/tests/fixture/issues-6xxx/6209/1/output/index.js new file mode 100644 index 000000000000..4335b6246e60 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6209/1/output/index.js @@ -0,0 +1,4 @@ +import { modulo } from "./src/modules/style.module.less"; +import { sum } from "./sum.js"; +console.log(modulo); +console.log(sum); diff --git a/crates/swc/tests/fixture/issues-6xxx/6209/1/output/src/sum.ts b/crates/swc/tests/fixture/issues-6xxx/6209/1/output/src/sum.ts new file mode 100644 index 000000000000..41e8b3d65986 --- /dev/null +++ b/crates/swc/tests/fixture/issues-6xxx/6209/1/output/src/sum.ts @@ -0,0 +1,3 @@ +export function sum(a, b) { + return a + b; +} From 7dc20092f0dd3be2cb1c6b0ec686a134f533f9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 3 Nov 2022 12:40:35 +0900 Subject: [PATCH 6/7] Dep --- packages/swc-helpers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/swc-helpers/package.json b/packages/swc-helpers/package.json index 07b697ed40e6..011b98a426d2 100644 --- a/packages/swc-helpers/package.json +++ b/packages/swc-helpers/package.json @@ -30,7 +30,7 @@ "homepage": "https://swc.rs", "devDependencies": { "@swc/cli": "^0.1.36", - "@swc/core": "^1.2.196" + "@swc/core": "=1.3.3" }, "dependencies": { "tslib": "^2.4.0" From 6bae86d85021c1af5cb72441fa869b24b35b3b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 3 Nov 2022 14:06:27 +0900 Subject: [PATCH 7/7] Update test refs --- .../tests/fixture-manual/issue-4730/output/index.js | 4 ++-- .../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, 8 insertions(+), 8 deletions(-) diff --git a/crates/swc_ecma_transforms_module/tests/fixture-manual/issue-4730/output/index.js b/crates/swc_ecma_transforms_module/tests/fixture-manual/issue-4730/output/index.js index ec142a77c1d7..0db54e228032 100644 --- a/crates/swc_ecma_transforms_module/tests/fixture-manual/issue-4730/output/index.js +++ b/crates/swc_ecma_transforms_module/tests/fixture-manual/issue-4730/output/index.js @@ -1,6 +1,6 @@ -import { displayB } from "../packages/b/src/index"; +import { displayB } from "../packages/b/src/index.ts"; async function display() { - const displayA = await import("../packages/a/src/index").then((c)=>c.displayA); + const displayA = await import("../packages/a/src/index.ts").then((c)=>c.displayA); console.log(displayA()); console.log(displayB()); } 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 a6dad7b1a7bd..7cc1229f0a67 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.js"; +import "./rel.ts"; 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 6c84f6bfbe5d..c1a93de2a8ee 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.js"; +import "./src/feat.ts"; 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 37dcc5d213e8..c15108b16ba7 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.js"; +import "./src/rel.decorator.ts"; 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 2061bc752252..c15108b16ba7 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"; +import "./src/rel.decorator.ts"; 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 37dcc5d213e8..c15108b16ba7 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.js"; +import "./src/rel.decorator.ts"; 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 2061bc752252..c15108b16ba7 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"; +import "./src/rel.decorator.ts";