From 82cca674e34022212b507f7cbbe3e903b7591f95 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Sun, 16 Oct 2022 08:25:55 +0800 Subject: [PATCH] fix(es/modules): Resolve `jsc.paths` for export alls (#6170) --- crates/swc_ecma_transforms_module/src/rewriter.rs | 13 +++++++++++++ .../tests/paths/issue-6159/input/index.ts | 3 +++ .../tests/paths/issue-6159/input/paths.json | 5 +++++ .../tests/paths/issue-6159/output/index.ts | 3 +++ 4 files changed, 24 insertions(+) create mode 100644 crates/swc_ecma_transforms_module/tests/paths/issue-6159/input/index.ts create mode 100644 crates/swc_ecma_transforms_module/tests/paths/issue-6159/input/paths.json create mode 100644 crates/swc_ecma_transforms_module/tests/paths/issue-6159/output/index.ts diff --git a/crates/swc_ecma_transforms_module/src/rewriter.rs b/crates/swc_ecma_transforms_module/src/rewriter.rs index 0149f9d13b2..631e3c2ad64 100644 --- a/crates/swc_ecma_transforms_module/src/rewriter.rs +++ b/crates/swc_ecma_transforms_module/src/rewriter.rs @@ -69,4 +69,17 @@ where src.value = new; } } + + fn visit_mut_export_all(&mut self, n: &mut ExportAll) { + let mut src = &mut n.src; + + let new = self + .resolver + .resolve_import(&self.base, &src.value) + .with_context(|| format!("failed to resolve import `{}`", src.value)) + .unwrap(); + + src.raw = None; + src.value = new; + } } diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-6159/input/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-6159/input/index.ts new file mode 100644 index 00000000000..95fb7eaefee --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-6159/input/index.ts @@ -0,0 +1,3 @@ +import "@/a.js"; +export {} from "@/a.js"; +export * from "@/a.js"; diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-6159/input/paths.json b/crates/swc_ecma_transforms_module/tests/paths/issue-6159/input/paths.json new file mode 100644 index 00000000000..0550ae42012 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-6159/input/paths.json @@ -0,0 +1,5 @@ +{ + "@/*": [ + "./src/*" + ] +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_module/tests/paths/issue-6159/output/index.ts b/crates/swc_ecma_transforms_module/tests/paths/issue-6159/output/index.ts new file mode 100644 index 00000000000..e8309b1a020 --- /dev/null +++ b/crates/swc_ecma_transforms_module/tests/paths/issue-6159/output/index.ts @@ -0,0 +1,3 @@ +import "./src/a.js"; +export { } from "./src/a.js"; +export * from "./src/a.js";