From 9c9c3ebd2c9c4141e3449e19926636a77741980a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Mon, 14 Nov 2022 14:30:40 +0900 Subject: [PATCH] fix(es/modules): Fix `jsc.paths` of `.ts` imports (#6431) **Related issue:** - Closes https://github.com/swc-project/swc/issues/6432. --- crates/swc_ecma_transforms_module/src/path.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/swc_ecma_transforms_module/src/path.rs b/crates/swc_ecma_transforms_module/src/path.rs index f987931f8a12..f4edf5b39326 100644 --- a/crates/swc_ecma_transforms_module/src/path.rs +++ b/crates/swc_ecma_transforms_module/src/path.rs @@ -113,12 +113,24 @@ where { fn resolve_import(&self, base: &FileName, module_specifier: &str) -> Result { fn to_specifier(target_path: &str, orig_ext: Option<&str>) -> JsWord { - let p = PathBuf::from(target_path); + let mut p = PathBuf::from(target_path); if cfg!(debug_assertions) { trace!("to_specifier: orig_ext={:?}", orig_ext); } + if let Some(orig_ext) = orig_ext { + let use_orig = if let Some(ext) = p.extension() { + (ext == "ts" || ext == "tsx") && p.is_file() + } else { + false + }; + + if use_orig { + p.set_extension(orig_ext); + } + } + p.display().to_string().into() }