From bc7ac45d8701a0783250ec720a9ae9dd10fb95b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Tue, 29 Dec 2020 00:09:46 +0900 Subject: [PATCH] fix(bundler): Don't load dynamic imports (#1297) swc_bundler: - Do not load dynamically imported files. --- bundler/Cargo.toml | 2 +- bundler/src/bundler/import/mod.rs | 23 +++++++++++-------- bundler/tests/common/mod.rs | 1 + bundler/tests/fixture/dynamic/input/dep.ts | 3 +++ bundler/tests/fixture/dynamic/input/entry.ts | 3 +++ bundler/tests/fixture/dynamic/output/entry.ts | 2 ++ 6 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 bundler/tests/fixture/dynamic/input/dep.ts create mode 100644 bundler/tests/fixture/dynamic/input/entry.ts create mode 100644 bundler/tests/fixture/dynamic/output/entry.ts diff --git a/bundler/Cargo.toml b/bundler/Cargo.toml index 53e56d1f0f66..85a8a7a4e53d 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.18.1" +version = "0.18.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] diff --git a/bundler/src/bundler/import/mod.rs b/bundler/src/bundler/import/mod.rs index f7c04723e15a..740f1eb6518a 100644 --- a/bundler/src/bundler/import/mod.rs +++ b/bundler/src/bundler/import/mod.rs @@ -516,16 +516,19 @@ where return Expr::Call(e); } - ExprOrSuper::Expr(ref e) => match &**e { - Expr::Ident(Ident { - sym: js_word!("import"), - .. - }) => { - self.info.dynamic_imports.push(src.clone()); - } - _ => {} - }, - + // TODO: Uncomment this after implementing an option to make swc_bundler + // includes dynamic imports + // + // + // ExprOrSuper::Expr(ref e) => match &**e { + // Expr::Ident(Ident { + // sym: js_word!("import"), + // .. + // }) => { + // self.info.dynamic_imports.push(src.clone()); + // } + // _ => {} + // }, _ => {} } diff --git a/bundler/tests/common/mod.rs b/bundler/tests/common/mod.rs index 80c8ab68bc4f..590bf298f0b9 100644 --- a/bundler/tests/common/mod.rs +++ b/bundler/tests/common/mod.rs @@ -76,6 +76,7 @@ impl Load for Loader { Syntax::Typescript(TsConfig { decorators: true, tsx, + dynamic_import: true, ..Default::default() }), JscTarget::Es2020, diff --git a/bundler/tests/fixture/dynamic/input/dep.ts b/bundler/tests/fixture/dynamic/input/dep.ts new file mode 100644 index 000000000000..6b74fc6bf20c --- /dev/null +++ b/bundler/tests/fixture/dynamic/input/dep.ts @@ -0,0 +1,3 @@ +console.log('Foo') + +export const a = 5; \ No newline at end of file diff --git a/bundler/tests/fixture/dynamic/input/entry.ts b/bundler/tests/fixture/dynamic/input/entry.ts new file mode 100644 index 000000000000..2d3dfc46c09e --- /dev/null +++ b/bundler/tests/fixture/dynamic/input/entry.ts @@ -0,0 +1,3 @@ +const a = import('./dep') + +console.log(a) \ No newline at end of file diff --git a/bundler/tests/fixture/dynamic/output/entry.ts b/bundler/tests/fixture/dynamic/output/entry.ts new file mode 100644 index 000000000000..f5c46e8d62df --- /dev/null +++ b/bundler/tests/fixture/dynamic/output/entry.ts @@ -0,0 +1,2 @@ +const a = import('./dep'); +console.log(a);