diff --git a/bundler/Cargo.toml b/bundler/Cargo.toml index a9dfabaed5d..0b6becf96ad 100644 --- a/bundler/Cargo.toml +++ b/bundler/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_bundler" repository = "https://github.com/swc-project/swc.git" -version = "0.9.1" +version = "0.9.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] diff --git a/bundler/src/bundler/chunk/plan/mod.rs b/bundler/src/bundler/chunk/plan/mod.rs index 8f22649f76e..ac3fe9bf8ed 100644 --- a/bundler/src/bundler/chunk/plan/mod.rs +++ b/bundler/src/bundler/chunk/plan/mod.rs @@ -107,7 +107,12 @@ pub(super) struct Plan { impl Plan { pub fn entry_as_circular(&self, entry: ModuleId) -> Option<&CircularPlan> { - self.circular.get(&entry) + let plan = self.circular.get(&entry)?; + if plan.chunks.is_empty() { + return None; + } + + Some(plan) } } diff --git a/bundler/src/bundler/chunk/remark.rs b/bundler/src/bundler/chunk/remark.rs index 322ae7d605c..e8248169c8c 100644 --- a/bundler/src/bundler/chunk/remark.rs +++ b/bundler/src/bundler/chunk/remark.rs @@ -299,6 +299,8 @@ impl Fold for ExportRenamer<'_> { (s.orig.sym.clone(), self.dep_ctxt), s.orig.to_id(), ); + self.remark_map + .insert((id.0.clone(), ctxt), self.dep_ctxt); Some((id.0, ctxt)) } diff --git a/bundler/src/bundler/import/mod.rs b/bundler/src/bundler/import/mod.rs index 739a0543173..1918ac2e2bf 100644 --- a/bundler/src/bundler/import/mod.rs +++ b/bundler/src/bundler/import/mod.rs @@ -370,7 +370,8 @@ where match s { ImportSpecifier::Namespace(n) => { return i.sym == n.local.sym - && i.span.ctxt() == self.module_ctxt + && (i.span.ctxt == self.module_ctxt + || i.span.ctxt == n.local.span.ctxt) } _ => {} } diff --git a/spack/tests/pass/issue-1138/example-1/input/.swcrc b/spack/tests/pass/issue-1138/example-1/input/.swcrc new file mode 100644 index 00000000000..6c50a1d2171 --- /dev/null +++ b/spack/tests/pass/issue-1138/example-1/input/.swcrc @@ -0,0 +1,7 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + } + } +} diff --git a/spack/tests/pass/issue-1138/example-1/input/a.ts b/spack/tests/pass/issue-1138/example-1/input/a.ts new file mode 100644 index 00000000000..9233cce2f0e --- /dev/null +++ b/spack/tests/pass/issue-1138/example-1/input/a.ts @@ -0,0 +1 @@ +export const a = "a"; diff --git a/spack/tests/pass/issue-1138/example-1/input/entry.js b/spack/tests/pass/issue-1138/example-1/input/entry.js new file mode 100644 index 00000000000..6ae243b2530 --- /dev/null +++ b/spack/tests/pass/issue-1138/example-1/input/entry.js @@ -0,0 +1,7 @@ +import { a as defaultA } from "./l.ts"; + +const o: { a?: string } = {}; + +const { a = defaultA } = o; + +console.log(a); \ No newline at end of file diff --git a/spack/tests/pass/issue-1138/example-1/input/l.ts b/spack/tests/pass/issue-1138/example-1/input/l.ts new file mode 100644 index 00000000000..d767e6ad090 --- /dev/null +++ b/spack/tests/pass/issue-1138/example-1/input/l.ts @@ -0,0 +1 @@ +export { a } from "./a.ts"; diff --git a/spack/tests/pass/issue-1138/example-1/output/entry.js b/spack/tests/pass/issue-1138/example-1/output/entry.js new file mode 100644 index 00000000000..6346f0b153e --- /dev/null +++ b/spack/tests/pass/issue-1138/example-1/output/entry.js @@ -0,0 +1,6 @@ +var a = "a"; +const defaultA = a; +var o = { +}; +var _a = o.a, a1 = _a === void 0 ? defaultA : _a; +console.log(a1); diff --git a/spack/tests/pass/issue-1138/example-2/input/.swcrc b/spack/tests/pass/issue-1138/example-2/input/.swcrc new file mode 100644 index 00000000000..6c50a1d2171 --- /dev/null +++ b/spack/tests/pass/issue-1138/example-2/input/.swcrc @@ -0,0 +1,7 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + } + } +} diff --git a/spack/tests/pass/issue-1138/example-2/input/a.ts b/spack/tests/pass/issue-1138/example-2/input/a.ts new file mode 100644 index 00000000000..7aa95742fe7 --- /dev/null +++ b/spack/tests/pass/issue-1138/example-2/input/a.ts @@ -0,0 +1 @@ +export const defaultA = "a"; diff --git a/spack/tests/pass/issue-1138/example-2/input/entry.js b/spack/tests/pass/issue-1138/example-2/input/entry.js new file mode 100644 index 00000000000..8b0053d8e80 --- /dev/null +++ b/spack/tests/pass/issue-1138/example-2/input/entry.js @@ -0,0 +1,7 @@ +import { defaultA } from "./l.ts"; + +const o: { a?: string } = {}; + +const { a = defaultA } = o; + +console.log(a); \ No newline at end of file diff --git a/spack/tests/pass/issue-1138/example-2/input/l.ts b/spack/tests/pass/issue-1138/example-2/input/l.ts new file mode 100644 index 00000000000..30fa694b8f1 --- /dev/null +++ b/spack/tests/pass/issue-1138/example-2/input/l.ts @@ -0,0 +1 @@ +export { defaultA } from "./a.ts"; diff --git a/spack/tests/pass/issue-1138/example-2/output/entry.js b/spack/tests/pass/issue-1138/example-2/output/entry.js new file mode 100644 index 00000000000..6fc850915b1 --- /dev/null +++ b/spack/tests/pass/issue-1138/example-2/output/entry.js @@ -0,0 +1,6 @@ +var defaultA = "a"; +const defaultA1 = defaultA; +var o = { +}; +var _a = o.a, a = _a === void 0 ? defaultA1 : _a; +console.log(a); diff --git a/spack/tests/pass/issue-1139/example-1/input/a.js b/spack/tests/pass/issue-1139/example-1/input/a.js new file mode 100644 index 00000000000..bf898d57eaf --- /dev/null +++ b/spack/tests/pass/issue-1139/example-1/input/a.js @@ -0,0 +1,7 @@ +import * as circular1 from "./entry"; + +export function f2() { + console.log("f2"); +} + +circular1.f1(); \ No newline at end of file diff --git a/spack/tests/pass/issue-1139/example-1/input/entry.js b/spack/tests/pass/issue-1139/example-1/input/entry.js new file mode 100644 index 00000000000..3dc8335cc66 --- /dev/null +++ b/spack/tests/pass/issue-1139/example-1/input/entry.js @@ -0,0 +1,7 @@ +import * as circular2 from "./a"; + +export function f1() { + console.log("f1"); +} + +circular2.f2(); \ No newline at end of file diff --git a/spack/tests/pass/issue-1139/example-1/output/entry.js b/spack/tests/pass/issue-1139/example-1/output/entry.js new file mode 100644 index 00000000000..02bb6f0e0b1 --- /dev/null +++ b/spack/tests/pass/issue-1139/example-1/output/entry.js @@ -0,0 +1,8 @@ +export function f1() { + console.log("f1"); +} +f2(); +function f2() { + console.log("f2"); +} +f1(); diff --git a/spack/tests/pass/issue-1139/example-2/input/a.js b/spack/tests/pass/issue-1139/example-2/input/a.js new file mode 100644 index 00000000000..a33b71de1d9 --- /dev/null +++ b/spack/tests/pass/issue-1139/example-2/input/a.js @@ -0,0 +1,7 @@ +import * as circular2 from "./b"; + +export function f1() { + console.log("f1"); +} + +circular2.f2(); \ No newline at end of file diff --git a/spack/tests/pass/issue-1139/example-2/input/b.js b/spack/tests/pass/issue-1139/example-2/input/b.js new file mode 100644 index 00000000000..2f99b023b49 --- /dev/null +++ b/spack/tests/pass/issue-1139/example-2/input/b.js @@ -0,0 +1,7 @@ +import * as circular1 from "./a"; + +export function f2() { + console.log("f2"); +} + +circular1.f1(); \ No newline at end of file diff --git a/spack/tests/pass/issue-1139/example-2/input/entry.js b/spack/tests/pass/issue-1139/example-2/input/entry.js new file mode 100644 index 00000000000..674450f7dfe --- /dev/null +++ b/spack/tests/pass/issue-1139/example-2/input/entry.js @@ -0,0 +1 @@ +import './a'; \ No newline at end of file diff --git a/spack/tests/pass/issue-1139/example-2/output/entry.js b/spack/tests/pass/issue-1139/example-2/output/entry.js new file mode 100644 index 00000000000..dba2debb467 --- /dev/null +++ b/spack/tests/pass/issue-1139/example-2/output/entry.js @@ -0,0 +1,8 @@ +function f1() { + console.log("f1"); +} +f2(); +function f2() { + console.log("f2"); +} +f1();