Skip to content

Commit

Permalink
fix(bundler): Don't load dynamic imports (#1297)
Browse files Browse the repository at this point in the history
swc_bundler:
 - Do not load dynamically imported files.
  • Loading branch information
kdy1 authored Dec 28, 2020
1 parent ba13db5 commit bc7ac45
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
23 changes: 13 additions & 10 deletions bundler/src/bundler/import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
// }
// _ => {}
// },
_ => {}
}

Expand Down
1 change: 1 addition & 0 deletions bundler/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl Load for Loader {
Syntax::Typescript(TsConfig {
decorators: true,
tsx,
dynamic_import: true,
..Default::default()
}),
JscTarget::Es2020,
Expand Down
3 changes: 3 additions & 0 deletions bundler/tests/fixture/dynamic/input/dep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log('Foo')

export const a = 5;
3 changes: 3 additions & 0 deletions bundler/tests/fixture/dynamic/input/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const a = import('./dep')

console.log(a)
2 changes: 2 additions & 0 deletions bundler/tests/fixture/dynamic/output/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const a = import('./dep');
console.log(a);

0 comments on commit bc7ac45

Please sign in to comment.