From 4849f4fe8f6609a78782f19c3696f96db1526e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 5 Nov 2020 13:50:07 +0900 Subject: [PATCH 01/18] Add a test for denoland/deno#8246 --- bundler/tests/deno.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bundler/tests/deno.rs b/bundler/tests/deno.rs index 2b81dfcefa79..38981c16f87f 100644 --- a/bundler/tests/deno.rs +++ b/bundler/tests/deno.rs @@ -73,6 +73,11 @@ fn deno_8211() { run("https://unpkg.com/luxon@1.25.0/src/luxon.js", None); } +#[test] +fn deno_8246() { + run("https://raw.githubusercontent.com/nats-io/nats.deno/v1.0.0-11/nats-base-client/internal_mod.ts",None); +} + fn run(url: &str, expeceted_bytes: Option) { let dir = tempfile::tempdir().expect("failed to crate temp file"); let path = dir.path().join("main.js"); From 301622e48d7cabcc466b3556740f04689d8d5827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Thu, 5 Nov 2020 14:22:38 +0900 Subject: [PATCH 02/18] Fix lca --- bundler/src/bundler/chunk/plan/lca.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/src/bundler/chunk/plan/lca.rs b/bundler/src/bundler/chunk/plan/lca.rs index a410790ae76a..a7dc9a7338e7 100644 --- a/bundler/src/bundler/chunk/plan/lca.rs +++ b/bundler/src/bundler/chunk/plan/lca.rs @@ -67,7 +67,7 @@ fn check_itself(b: &PlanBuilder, li: &[ModuleId], ri: &[ModuleId]) -> Option Date: Thu, 5 Nov 2020 14:44:59 +0900 Subject: [PATCH 03/18] Fix detection of circular imports --- bundler/src/bundler/chunk/plan/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bundler/src/bundler/chunk/plan/mod.rs b/bundler/src/bundler/chunk/plan/mod.rs index 9c1ce0a94a61..c38164e27bdf 100644 --- a/bundler/src/bundler/chunk/plan/mod.rs +++ b/bundler/src/bundler/chunk/plan/mod.rs @@ -523,7 +523,12 @@ where } // Prevent dejavu - for (src, _) in &m.imports.specifiers { + for (src, _) in m + .imports + .specifiers + .iter() + .chain(m.exports.reexports.iter()) + { if builder.all_deps.contains_key(&(src.module_id, module_id)) { log::debug!("Circular dep: {:?} => {:?}", module_id, src.module_id); From 099b4b9c04799ca1b90e7dc1fa04df03eb2ec2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 13:58:31 +0900 Subject: [PATCH 04/18] circular: Handle variable usage in deps --- bundler/src/bundler/chunk/circular.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bundler/src/bundler/chunk/circular.rs b/bundler/src/bundler/chunk/circular.rs index 16fe61f9ea10..e9cf04f0c1db 100644 --- a/bundler/src/bundler/chunk/circular.rs +++ b/bundler/src/bundler/chunk/circular.rs @@ -7,6 +7,7 @@ use anyhow::{Context, Error}; use std::borrow::Borrow; use swc_common::DUMMY_SP; use swc_ecma_ast::*; +use swc_ecma_utils::{find_ids, ident::IdentLike, Id, UsageFinder}; use swc_ecma_visit::{noop_visit_type, FoldWith, Node, Visit, VisitMutWith, VisitWith}; #[cfg(test)] @@ -179,9 +180,13 @@ fn dependency_index(item: &ModuleItem, deps: &[T]) -> Option where T: Borrow, { - let mut v = DepFinder { deps, idx: None }; + let mut v = DepFinder { + deps, + idx: None, + last_usage_idx: None, + }; item.visit_with(&Invalid { span: DUMMY_SP }, &mut v); - v.idx + v.idx.or(v.last_usage_idx) } struct DepFinder<'a, T> @@ -189,6 +194,7 @@ where T: Borrow, { deps: &'a [T], + last_usage_idx: Option, idx: Option, } @@ -224,7 +230,11 @@ where } } - _ => {} + dep => { + if UsageFinder::find(i, dep) { + self.last_usage_idx = Some(idx); + } + } } } } From 13a6a8c2bf91dc5de5ac5ef5cb086eea1f1d8a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 13:58:44 +0900 Subject: [PATCH 05/18] lint --- bundler/src/bundler/chunk/circular.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/src/bundler/chunk/circular.rs b/bundler/src/bundler/chunk/circular.rs index e9cf04f0c1db..280b8d349009 100644 --- a/bundler/src/bundler/chunk/circular.rs +++ b/bundler/src/bundler/chunk/circular.rs @@ -7,7 +7,7 @@ use anyhow::{Context, Error}; use std::borrow::Borrow; use swc_common::DUMMY_SP; use swc_ecma_ast::*; -use swc_ecma_utils::{find_ids, ident::IdentLike, Id, UsageFinder}; +use swc_ecma_utils::UsageFinder; use swc_ecma_visit::{noop_visit_type, FoldWith, Node, Visit, VisitMutWith, VisitWith}; #[cfg(test)] From 3235d76ff7fcefcb534ab7c69fc3b7bd9c7a3e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 15:14:57 +0900 Subject: [PATCH 06/18] WIP: Correct sorting --- bundler/src/bundler/chunk/plan/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bundler/src/bundler/chunk/plan/mod.rs b/bundler/src/bundler/chunk/plan/mod.rs index c38164e27bdf..c557c755c988 100644 --- a/bundler/src/bundler/chunk/plan/mod.rs +++ b/bundler/src/bundler/chunk/plan/mod.rs @@ -388,7 +388,7 @@ where for (_, normal_plan) in &mut plans.normal { normal_plan .transitive_chunks - .sort_by(|a, b| toposort(&builder, *a, *b)); + .sort_by(|a, b| topo_compare(&builder, *a, *b)); } // Handle circular imports @@ -553,8 +553,10 @@ where } } +fn toposort(b: &PlanBuilder, module_ids: &mut Vec) {} + /// Compare topology of `i` and `k`. -fn toposort(b: &PlanBuilder, i: ModuleId, j: ModuleId) -> Ordering { +fn topo_compare(b: &PlanBuilder, i: ModuleId, j: ModuleId) -> Ordering { // let higher = least_common_ancestor(b, &[i, j]); From 1c155580d80873dd664f07fd9f4107b3ea71599f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 15:24:25 +0900 Subject: [PATCH 07/18] circular: Swap entry and dep --- bundler/src/bundler/chunk/circular.rs | 3 +-- .../circular/complex-class-function/output/entry.js | 10 +++++----- spack/tests/pass/circular/mixed/output/entry.js | 2 +- .../pass/circular/top-level-idents/output/entry.js | 4 ++-- .../pass/transitive/import/simple-2/output/entry.js | 4 ++-- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/bundler/src/bundler/chunk/circular.rs b/bundler/src/bundler/chunk/circular.rs index 280b8d349009..5cacaee2be1c 100644 --- a/bundler/src/bundler/chunk/circular.rs +++ b/bundler/src/bundler/chunk/circular.rs @@ -114,8 +114,7 @@ where } } -/// Originally, this method should create a dependency graph, but -fn merge_respecting_order(mut dep: Vec, mut entry: Vec) -> Vec { +fn merge_respecting_order(mut entry: Vec, mut dep: Vec) -> Vec { let mut new = Vec::with_capacity(dep.len() + entry.len()); // While looping over items from entry, we check for dependency. diff --git a/spack/tests/pass/circular/complex-class-function/output/entry.js b/spack/tests/pass/circular/complex-class-function/output/entry.js index 5a673b060295..3e20247ffb1b 100644 --- a/spack/tests/pass/circular/complex-class-function/output/entry.js +++ b/spack/tests/pass/circular/complex-class-function/output/entry.js @@ -1,11 +1,11 @@ -function getC() { - return C; -} -class C { -} function a() { return new A(); } +function getC() { + return C; +} class A extends getC() { } +class C { +} console.log(a, a()); diff --git a/spack/tests/pass/circular/mixed/output/entry.js b/spack/tests/pass/circular/mixed/output/entry.js index 33705c0885a2..974142d7b43f 100644 --- a/spack/tests/pass/circular/mixed/output/entry.js +++ b/spack/tests/pass/circular/mixed/output/entry.js @@ -1,9 +1,9 @@ -console.log('c'); class A { method() { return new B(); } } +console.log('c'); class B extends A { } console.log(A, B); diff --git a/spack/tests/pass/circular/top-level-idents/output/entry.js b/spack/tests/pass/circular/top-level-idents/output/entry.js index 291bdc4563aa..3330e73d33de 100644 --- a/spack/tests/pass/circular/top-level-idents/output/entry.js +++ b/spack/tests/pass/circular/top-level-idents/output/entry.js @@ -1,4 +1,4 @@ -console.log('c'); -console.log('b'); console.log('a'); +console.log('b'); +console.log('c'); console.log('entry'); diff --git a/spack/tests/pass/transitive/import/simple-2/output/entry.js b/spack/tests/pass/transitive/import/simple-2/output/entry.js index 7acd39239096..f64baa89887d 100644 --- a/spack/tests/pass/transitive/import/simple-2/output/entry.js +++ b/spack/tests/pass/transitive/import/simple-2/output/entry.js @@ -1,9 +1,9 @@ -const common1 = 1; const common = 2; const common2 = common; -console.log('a', common1, common2); +const common1 = 1; const common3 = 3; const common31 = common3; +console.log('a', common1, common2); console.log('b', common31, common1); var common4; try { From 687cb671271e7005fc1c313593b6593b00178b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 15:44:58 +0900 Subject: [PATCH 08/18] Handole transitive deps explicitly --- bundler/src/bundler/chunk/merge.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/bundler/src/bundler/chunk/merge.rs b/bundler/src/bundler/chunk/merge.rs index fab10d7ced37..8696936ee706 100644 --- a/bundler/src/bundler/chunk/merge.rs +++ b/bundler/src/bundler/chunk/merge.rs @@ -1,6 +1,7 @@ use super::plan::{NormalPlan, Plan}; use crate::{ bundler::load::{Imports, Specifier, TransformedModule}, + debug::print_hygiene, id::ModuleId, load::Load, resolve::Resolve, @@ -299,6 +300,19 @@ where if dep_info.is_es6 { // print_hygiene("entry: before injection", &self.cm, &entry); + if !is_direct { + prepend_stmts(&mut entry.body, take(&mut dep.body).into_iter()); + + log::debug!( + "Merged {} into {} as a transitive es module", + dep_info.fm.name, + info.fm.name, + ); + + // print_hygiene("ES6", &self.cm, &entry); + continue; + } + // Replace import statement / require with module body let mut injector = Es6ModuleInjector { imported: take(&mut dep.body), @@ -323,19 +337,6 @@ where continue; } - if !is_direct { - prepend_stmts(&mut entry.body, injector.imported.into_iter()); - - log::debug!( - "Merged {} into {} as a transitive es module", - dep_info.fm.name, - info.fm.name, - ); - - // print_hygiene("ES6", &self.cm, &entry); - continue; - } - // print_hygiene("entry: failed to inject", &self.cm, &entry); dep.body = take(&mut injector.imported); @@ -384,7 +385,7 @@ where } fn finalize_merging_of_entry(&self, plan: &Plan, entry: &mut Module) { - // print_hygiene("done", &self.cm, &entry); + print_hygiene("done", &self.cm, &entry); entry.body.retain_mut(|item| { match item { From 35e9ebdf88ef4cc872d3c18874be4f66c63f88d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 16:05:05 +0900 Subject: [PATCH 09/18] TMP: Change toposort --- bundler/src/bundler/chunk/plan/mod.rs | 31 +++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/bundler/src/bundler/chunk/plan/mod.rs b/bundler/src/bundler/chunk/plan/mod.rs index c557c755c988..ac90bba6cedc 100644 --- a/bundler/src/bundler/chunk/plan/mod.rs +++ b/bundler/src/bundler/chunk/plan/mod.rs @@ -386,9 +386,7 @@ where // Sort transitive chunks topologically. for (_, normal_plan) in &mut plans.normal { - normal_plan - .transitive_chunks - .sort_by(|a, b| topo_compare(&builder, *a, *b)); + toposort(&builder, &mut normal_plan.transitive_chunks); } // Handle circular imports @@ -553,7 +551,32 @@ where } } -fn toposort(b: &PlanBuilder, module_ids: &mut Vec) {} +fn toposort(b: &PlanBuilder, module_ids: &mut Vec) { + let len = module_ids.len(); + + if module_ids.len() <= 1 { + return; + } + + for i in 0..len { + for j in i..len { + let mi = module_ids[i]; + let mj = module_ids[j]; + if mi == mj { + continue; + } + let res = topo_compare(b, mi, mj); + dbg!(mi, mj, res); + match res { + Ordering::Less => {} + Ordering::Equal => {} + Ordering::Greater => { + module_ids.swap(i, j); + } + } + } + } +} /// Compare topology of `i` and `k`. fn topo_compare(b: &PlanBuilder, i: ModuleId, j: ModuleId) -> Ordering { From 89450c3f924066a370735da2838968fc18ec7e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 16:06:22 +0900 Subject: [PATCH 10/18] Remove wrong merging of imports --- bundler/src/bundler/chunk/export.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bundler/src/bundler/chunk/export.rs b/bundler/src/bundler/chunk/export.rs index cb8fd697b195..4d180518ce82 100644 --- a/bundler/src/bundler/chunk/export.rs +++ b/bundler/src/bundler/chunk/export.rs @@ -194,9 +194,10 @@ where } }; - dep = self - .merge_imports(plan, &module_plan, dep, &info, merged, false) - .context("failed to merge imports")?; + // dep = self + // .merge_imports(plan, &module_plan, dep, &info, merged, + // false) .context("failed to merge + // imports")?; } else { dep = self.remark_exports(dep, src.ctxt, None, false); } From c966164af9588164525ebb09b1077ee8e05198d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 16:08:04 +0900 Subject: [PATCH 11/18] Revert "circular: Swap entry and dep" This reverts commit 1c155580d80873dd664f07fd9f4107b3ea71599f. --- bundler/src/bundler/chunk/circular.rs | 3 ++- .../circular/complex-class-function/output/entry.js | 10 +++++----- spack/tests/pass/circular/mixed/output/entry.js | 2 +- .../pass/circular/top-level-idents/output/entry.js | 4 ++-- .../pass/transitive/import/simple-2/output/entry.js | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bundler/src/bundler/chunk/circular.rs b/bundler/src/bundler/chunk/circular.rs index 5cacaee2be1c..280b8d349009 100644 --- a/bundler/src/bundler/chunk/circular.rs +++ b/bundler/src/bundler/chunk/circular.rs @@ -114,7 +114,8 @@ where } } -fn merge_respecting_order(mut entry: Vec, mut dep: Vec) -> Vec { +/// Originally, this method should create a dependency graph, but +fn merge_respecting_order(mut dep: Vec, mut entry: Vec) -> Vec { let mut new = Vec::with_capacity(dep.len() + entry.len()); // While looping over items from entry, we check for dependency. diff --git a/spack/tests/pass/circular/complex-class-function/output/entry.js b/spack/tests/pass/circular/complex-class-function/output/entry.js index 3e20247ffb1b..5a673b060295 100644 --- a/spack/tests/pass/circular/complex-class-function/output/entry.js +++ b/spack/tests/pass/circular/complex-class-function/output/entry.js @@ -1,11 +1,11 @@ -function a() { - return new A(); -} function getC() { return C; } -class A extends getC() { -} class C { } +function a() { + return new A(); +} +class A extends getC() { +} console.log(a, a()); diff --git a/spack/tests/pass/circular/mixed/output/entry.js b/spack/tests/pass/circular/mixed/output/entry.js index 974142d7b43f..33705c0885a2 100644 --- a/spack/tests/pass/circular/mixed/output/entry.js +++ b/spack/tests/pass/circular/mixed/output/entry.js @@ -1,9 +1,9 @@ +console.log('c'); class A { method() { return new B(); } } -console.log('c'); class B extends A { } console.log(A, B); diff --git a/spack/tests/pass/circular/top-level-idents/output/entry.js b/spack/tests/pass/circular/top-level-idents/output/entry.js index 3330e73d33de..291bdc4563aa 100644 --- a/spack/tests/pass/circular/top-level-idents/output/entry.js +++ b/spack/tests/pass/circular/top-level-idents/output/entry.js @@ -1,4 +1,4 @@ -console.log('a'); -console.log('b'); console.log('c'); +console.log('b'); +console.log('a'); console.log('entry'); diff --git a/spack/tests/pass/transitive/import/simple-2/output/entry.js b/spack/tests/pass/transitive/import/simple-2/output/entry.js index f64baa89887d..7acd39239096 100644 --- a/spack/tests/pass/transitive/import/simple-2/output/entry.js +++ b/spack/tests/pass/transitive/import/simple-2/output/entry.js @@ -1,9 +1,9 @@ +const common1 = 1; const common = 2; const common2 = common; -const common1 = 1; +console.log('a', common1, common2); const common3 = 3; const common31 = common3; -console.log('a', common1, common2); console.log('b', common31, common1); var common4; try { From 436d25840fb260b7e08d80eafb5f35faebf44676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 16:19:25 +0900 Subject: [PATCH 12/18] Don't treat referencing as a callee as an usage of identifier. --- bundler/src/bundler/chunk/circular.rs | 67 ++++++++++++++++++- .../pass/issue-1139/example-1/output/entry.js | 2 +- .../pass/issue-1139/example-2/output/entry.js | 2 +- .../import/simple-2/output/entry.js | 4 +- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/bundler/src/bundler/chunk/circular.rs b/bundler/src/bundler/chunk/circular.rs index 280b8d349009..94622d03c0f6 100644 --- a/bundler/src/bundler/chunk/circular.rs +++ b/bundler/src/bundler/chunk/circular.rs @@ -7,7 +7,6 @@ use anyhow::{Context, Error}; use std::borrow::Borrow; use swc_common::DUMMY_SP; use swc_ecma_ast::*; -use swc_ecma_utils::UsageFinder; use swc_ecma_visit::{noop_visit_type, FoldWith, Node, Visit, VisitMutWith, VisitWith}; #[cfg(test)] @@ -231,7 +230,7 @@ where } dep => { - if UsageFinder::find(i, dep) { + if DepUsageFinder::find(i, dep) { self.last_usage_idx = Some(idx); } } @@ -263,3 +262,67 @@ where #[inline] fn visit_block_stmt(&mut self, _: &BlockStmt, _: &dyn Node) {} } + +/// Finds usage of `ident` +struct DepUsageFinder<'a> { + ident: &'a Ident, + found: bool, +} + +impl<'a> Visit for DepUsageFinder<'a> { + noop_visit_type!(); + + fn visit_call_expr(&mut self, e: &CallExpr, _: &dyn Node) { + if self.found { + return; + } + + match &e.callee { + ExprOrSuper::Super(_) => {} + ExprOrSuper::Expr(callee) => match &**callee { + Expr::Ident(..) => {} + _ => { + callee.visit_with(e, self); + } + }, + } + + e.args.visit_with(e, self); + } + + fn visit_ident(&mut self, i: &Ident, _: &dyn Node) { + if self.found { + return; + } + + if i.span.ctxt() == self.ident.span.ctxt() && i.sym == self.ident.sym { + self.found = true; + } + } + + fn visit_member_expr(&mut self, e: &MemberExpr, _: &dyn Node) { + if self.found { + return; + } + + e.obj.visit_with(e as _, self); + + if e.computed { + e.prop.visit_with(e as _, self); + } + } +} + +impl<'a> DepUsageFinder<'a> { + pub fn find(ident: &'a Ident, node: &N) -> bool + where + N: VisitWith, + { + let mut v = DepUsageFinder { + ident, + found: false, + }; + node.visit_with(&Invalid { span: DUMMY_SP } as _, &mut v); + v.found + } +} diff --git a/spack/tests/pass/issue-1139/example-1/output/entry.js b/spack/tests/pass/issue-1139/example-1/output/entry.js index 5a208d10e45d..2347973046ba 100644 --- a/spack/tests/pass/issue-1139/example-1/output/entry.js +++ b/spack/tests/pass/issue-1139/example-1/output/entry.js @@ -1,8 +1,8 @@ function f2() { console.log("f2"); } -f1(); export function f1() { console.log("f1"); } +f1(); f2(); diff --git a/spack/tests/pass/issue-1139/example-2/output/entry.js b/spack/tests/pass/issue-1139/example-2/output/entry.js index db97c0606f9d..b8cb7d07cb37 100644 --- a/spack/tests/pass/issue-1139/example-2/output/entry.js +++ b/spack/tests/pass/issue-1139/example-2/output/entry.js @@ -1,8 +1,8 @@ function f2() { console.log("f2"); } -f1(); function f1() { console.log("f1"); } +f1(); f2(); diff --git a/spack/tests/pass/transitive/import/simple-2/output/entry.js b/spack/tests/pass/transitive/import/simple-2/output/entry.js index 7acd39239096..f64baa89887d 100644 --- a/spack/tests/pass/transitive/import/simple-2/output/entry.js +++ b/spack/tests/pass/transitive/import/simple-2/output/entry.js @@ -1,9 +1,9 @@ -const common1 = 1; const common = 2; const common2 = common; -console.log('a', common1, common2); +const common1 = 1; const common3 = 3; const common31 = common3; +console.log('a', common1, common2); console.log('b', common31, common1); var common4; try { From 06fb1119cc36ad4e236d92f86877ff460a376ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 16:19:57 +0900 Subject: [PATCH 13/18] Remove print_hygiene --- bundler/src/bundler/chunk/merge.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bundler/src/bundler/chunk/merge.rs b/bundler/src/bundler/chunk/merge.rs index 8696936ee706..3f108f9e2ea1 100644 --- a/bundler/src/bundler/chunk/merge.rs +++ b/bundler/src/bundler/chunk/merge.rs @@ -1,7 +1,6 @@ use super::plan::{NormalPlan, Plan}; use crate::{ bundler::load::{Imports, Specifier, TransformedModule}, - debug::print_hygiene, id::ModuleId, load::Load, resolve::Resolve, @@ -385,7 +384,7 @@ where } fn finalize_merging_of_entry(&self, plan: &Plan, entry: &mut Module) { - print_hygiene("done", &self.cm, &entry); + // print_hygiene("done", &self.cm, &entry); entry.body.retain_mut(|item| { match item { From 570cf3fd7a11b0d9bf295f837a19e3556b948843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 16:20:15 +0900 Subject: [PATCH 14/18] Remove dbg! --- bundler/src/bundler/chunk/plan/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/bundler/src/bundler/chunk/plan/mod.rs b/bundler/src/bundler/chunk/plan/mod.rs index ac90bba6cedc..423af99747b9 100644 --- a/bundler/src/bundler/chunk/plan/mod.rs +++ b/bundler/src/bundler/chunk/plan/mod.rs @@ -566,7 +566,6 @@ fn toposort(b: &PlanBuilder, module_ids: &mut Vec) { continue; } let res = topo_compare(b, mi, mj); - dbg!(mi, mj, res); match res { Ordering::Less => {} Ordering::Equal => {} From 9efd9418117afca6d6893cf5782121e7678166fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 16:20:41 +0900 Subject: [PATCH 15/18] Remove dead code --- bundler/src/bundler/chunk/export.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bundler/src/bundler/chunk/export.rs b/bundler/src/bundler/chunk/export.rs index 4d180518ce82..901b71827395 100644 --- a/bundler/src/bundler/chunk/export.rs +++ b/bundler/src/bundler/chunk/export.rs @@ -184,20 +184,6 @@ where if let Some(id) = id_of_export_namespace_from { dep = self.wrap_esm_as_a_var(plan, dep, &imported, merged, id)?; - - let module_plan; - let module_plan = match plan.normal.get(&info.id) { - Some(v) => v, - None => { - module_plan = Default::default(); - &module_plan - } - }; - - // dep = self - // .merge_imports(plan, &module_plan, dep, &info, merged, - // false) .context("failed to merge - // imports")?; } else { dep = self.remark_exports(dep, src.ctxt, None, false); } From 7eecf365dc10b8c29563268eeb98d35daf43b5d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 17:00:48 +0900 Subject: [PATCH 16/18] Optimize --- bundler/src/bundler/chunk/plan/mod.rs | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/bundler/src/bundler/chunk/plan/mod.rs b/bundler/src/bundler/chunk/plan/mod.rs index 423af99747b9..3cab3cd379a8 100644 --- a/bundler/src/bundler/chunk/plan/mod.rs +++ b/bundler/src/bundler/chunk/plan/mod.rs @@ -11,7 +11,6 @@ use petgraph::{ EdgeDirection::{Incoming, Outgoing}, }; use std::{ - cmp::Ordering, collections::{hash_map::Entry, HashMap, HashSet}, ops::{Deref, DerefMut}, }; @@ -565,28 +564,10 @@ fn toposort(b: &PlanBuilder, module_ids: &mut Vec) { if mi == mj { continue; } - let res = topo_compare(b, mi, mj); - match res { - Ordering::Less => {} - Ordering::Equal => {} - Ordering::Greater => { - module_ids.swap(i, j); - } + + if b.direct_deps.contains_edge(mi, mj) { + module_ids.swap(i, j); } } } } - -/// Compare topology of `i` and `k`. -fn topo_compare(b: &PlanBuilder, i: ModuleId, j: ModuleId) -> Ordering { - // - let higher = least_common_ancestor(b, &[i, j]); - - if higher == i { - Ordering::Greater - } else if higher == j { - Ordering::Less - } else { - Ordering::Equal - } -} From 7f9eb5310291937586040e32726c279db01e31cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 17:02:41 +0900 Subject: [PATCH 17/18] Fix --- bundler/src/bundler/chunk/plan/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/src/bundler/chunk/plan/mod.rs b/bundler/src/bundler/chunk/plan/mod.rs index 3cab3cd379a8..10dc50b939dc 100644 --- a/bundler/src/bundler/chunk/plan/mod.rs +++ b/bundler/src/bundler/chunk/plan/mod.rs @@ -565,7 +565,7 @@ fn toposort(b: &PlanBuilder, module_ids: &mut Vec) { continue; } - if b.direct_deps.contains_edge(mi, mj) { + if b.direct_deps.contains_edge(mj, mi) { module_ids.swap(i, j); } } From c655a5e11d73895c0ea2950e6f734b5cce121600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 6 Nov 2020 17:19:14 +0900 Subject: [PATCH 18/18] Bump version --- bundler/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundler/Cargo.toml b/bundler/Cargo.toml index 56452acbd701..e68109b49079 100644 --- a/bundler/Cargo.toml +++ b/bundler/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_bundler" repository = "https://github.com/swc-project/swc.git" -version = "0.16.0" +version = "0.16.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features]