From a325d0afd3851e2ef635868f6e14b45b8c9726e1 Mon Sep 17 00:00:00 2001 From: Artem Zverev Date: Wed, 1 May 2024 01:27:55 +0200 Subject: [PATCH] feat(loadable-components)!: lazy and configuring --- .vscode/settings.json | 4 +- Cargo.lock | 9 +- packages/loadable-components/Cargo.toml | 1 + packages/loadable-components/src/lib.rs | 107 ++++++++++++++++-- packages/loadable-components/tests/fixture.rs | 9 +- .../should work with destructuration/input.js | 1 + .../output.js | 1 + .../should keep it/input.js | 1 + .../should keep it/output.js | 1 + .../should replace it/input.js | 1 + .../should replace it/output.js | 1 + .../should support complex request/input.js | 1 + .../should support complex request/output.js | 1 + .../should support destructuring/input.js | 1 + .../should support destructuring/output.js | 1 + .../should support simple request/input.js | 1 + .../should support simple request/output.js | 1 + .../lazy/should be transpiled too/input.js | 3 + .../lazy/should be transpiled too/output.js | 40 +++++++ .../should not work without imported/input.js | 3 + .../output.js | 3 + .../input.js | 3 + .../output.js | 40 +++++++ .../should be transpiled too/input.js | 1 + .../should be transpiled too/output.js | 1 + .../in a complex promise/should work/input.js | 1 + .../should work/output.js | 1 + .../input.js | 1 + .../output.js | 1 + .../should work with mul in name/input.js | 1 + .../should work with mul in name/output.js | 1 + .../input.js | 1 + .../output.js | 1 + .../input.js | 1 + .../output.js | 1 + .../should add it/input.js | 1 + .../should add it/output.js | 1 + .../input.js | 1 + .../output.js | 1 + .../should use it/input.js | 1 + .../should use it/output.js | 1 + 41 files changed, 235 insertions(+), 17 deletions(-) create mode 100644 packages/loadable-components/tests/fixture/lazy/should be transpiled too/input.js create mode 100644 packages/loadable-components/tests/fixture/lazy/should be transpiled too/output.js create mode 100644 packages/loadable-components/tests/fixture/lazy/should not work without imported/input.js create mode 100644 packages/loadable-components/tests/fixture/lazy/should not work without imported/output.js create mode 100644 packages/loadable-components/tests/fixture/lazy/should work with renamed specifier/input.js create mode 100644 packages/loadable-components/tests/fixture/lazy/should work with renamed specifier/output.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 3518db63d..81d26f761 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ { - "editor.formatOnSave": true, + "editor.formatOnSave": false, "rust-analyzer.check.command": "clippy" -} +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 2d62b38f0..f0a2628c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2034,18 +2034,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.199" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc" dependencies = [ "proc-macro2", "quote", @@ -3072,6 +3072,7 @@ version = "0.18.4" dependencies = [ "once_cell", "regex", + "serde", "serde_json", "swc_common", "swc_core", diff --git a/packages/loadable-components/Cargo.toml b/packages/loadable-components/Cargo.toml index 6df9fa2e6..9e0fce29b 100644 --- a/packages/loadable-components/Cargo.toml +++ b/packages/loadable-components/Cargo.toml @@ -18,6 +18,7 @@ crate-type = ["cdylib", "rlib"] [dependencies] once_cell = "1.13.1" regex = "1.6.0" +serde = { version = "1.0.199", features = ["derive"] } serde_json = "1.0.79" swc_common = { version = "0.33.25", features = ["concurrent"] } swc_core = { version = "0.91.0", features = [ diff --git a/packages/loadable-components/src/lib.rs b/packages/loadable-components/src/lib.rs index a9d6c1ccf..5f69df797 100644 --- a/packages/loadable-components/src/lib.rs +++ b/packages/loadable-components/src/lib.rs @@ -1,7 +1,10 @@ #![allow(clippy::boxed_local)] #![allow(clippy::not_unsafe_ptr_arg_deref)] +use std::collections::HashSet; + use once_cell::sync::Lazy; +use serde::Deserialize; use swc_common::{ comments::{Comment, CommentKind, Comments}, util::take::Take, @@ -34,18 +37,34 @@ static MATCH_LEFT_HYPHENS_REPLACE_REGEX: Lazy = #[plugin_transform] fn loadable_components_plugin( mut program: Program, - _data: TransformPluginProgramMetadata, + data: TransformPluginProgramMetadata, ) -> Program { - program.visit_mut_with(&mut loadable_transform(PluginCommentsProxy)); + let config = serde_json::from_str::( + &data + .get_transform_plugin_config() + .expect("failed to get plugin config for swc-loadable-components"), + ) + .expect("invalid config for swc-loadable-components"); + + let signatures = config.signatures; + + program.visit_mut_with(&mut loadable_transform( + PluginCommentsProxy, + signatures.unwrap_or(vec![Signature::default(), Signature::default_lazy()]), + )); program } -pub fn loadable_transform(comments: C) -> impl VisitMut +pub fn loadable_transform(comments: C, signatures: Vec) -> impl VisitMut where C: Comments, { - Loadable { comments } + Loadable { + comments, + signatures, + specifiers: HashSet::new(), + } } struct Loadable @@ -53,21 +72,24 @@ where C: Comments, { comments: C, + signatures: Vec, + specifiers: HashSet, } impl Loadable where C: Comments, { - fn is_valid_identifier(e: &Expr) -> bool { + fn is_valid_identifier(&self, e: &Expr) -> bool { + dbg!(&self.specifiers); match e { - Expr::Ident(i) => &*i.sym == "loadable", + Expr::Ident(i) => self.specifiers.contains(&*i.sym), Expr::Member(MemberExpr { obj, prop: MemberProp::Ident(prop), .. }) => match &**obj { - Expr::Ident(i) => &*i.sym == "loadable" && &*prop.sym == "lib", + Expr::Ident(i) => self.specifiers.contains(&*i.sym) && &*prop.sym == "lib", _ => false, }, _ => false, @@ -616,11 +638,45 @@ impl VisitMut for Loadable where C: Comments, { + fn visit_mut_import_decl(&mut self, import_decl: &mut ImportDecl) { + for signature in self.signatures.iter() { + dbg!(&signature); + dbg!(&import_decl.src.value); + dbg!(&signature.from); + if dbg!(signature.from == *import_decl.src.value) { + for specifier in import_decl.specifiers.iter() { + match specifier { + ImportSpecifier::Default(default_spec) => { + if signature.is_default_specifier() { + self.specifiers.insert(default_spec.local.sym.to_string()); + } + } + ImportSpecifier::Named(named_specifier) => { + dbg!(&named_specifier.local.sym); + if let Some(ModuleExportName::Ident(imported)) = + &named_specifier.imported + { + if imported.sym == signature.name { + self.specifiers + .insert(named_specifier.local.sym.to_string()); + return; + } + } + if named_specifier.local.sym == signature.name { + self.specifiers.insert(signature.name.clone()); + } + } + _ => (), + } + } + } + } + } + fn visit_mut_call_expr(&mut self, call: &mut CallExpr) { call.visit_mut_children_with(self); - match &call.callee { - Callee::Expr(callee) if Self::is_valid_identifier(callee) => {} + Callee::Expr(callee) if self.is_valid_identifier(callee) => {} _ => return, } @@ -725,3 +781,36 @@ fn clone_params(e: &Expr) -> Vec { _ => Default::default(), } } + +#[derive(Debug, Clone, Deserialize)] +pub struct Signature { + name: String, + from: String, +} + +impl Default for Signature { + fn default() -> Self { + Signature { + name: "default".into(), + from: "@loadable/component".into(), + } + } +} + +impl Signature { + fn is_default_specifier(&self) -> bool { + self.name == "default".to_string() + } + + pub fn default_lazy() -> Self { + Signature { + name: "lazy".into(), + from: "@loadable/component".into(), + } + } +} + +#[derive(Default, Debug, Clone, Deserialize)] +struct PluginConfig { + signatures: Option>, +} diff --git a/packages/loadable-components/tests/fixture.rs b/packages/loadable-components/tests/fixture.rs index c2268e84c..9992d3984 100644 --- a/packages/loadable-components/tests/fixture.rs +++ b/packages/loadable-components/tests/fixture.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use swc_core::ecma::{transforms::testing::test_fixture, visit::as_folder}; -use swc_plugin_loadable_components::loadable_transform; +use swc_plugin_loadable_components::{loadable_transform, Signature}; #[testing::fixture("tests/fixture/**/input.js")] fn fixture(input: PathBuf) { @@ -9,7 +9,12 @@ fn fixture(input: PathBuf) { test_fixture( Default::default(), - &|t| as_folder(loadable_transform(t.comments.clone())), + &|t| { + as_folder(loadable_transform( + t.comments.clone(), + vec![Signature::default(), Signature::default_lazy()], + )) + }, &input, &output, Default::default(), diff --git a/packages/loadable-components/tests/fixture/aggressive import/should work with destructuration/input.js b/packages/loadable-components/tests/fixture/aggressive import/should work with destructuration/input.js index 89f5d98b4..2f55eee8f 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/should work with destructuration/input.js +++ b/packages/loadable-components/tests/fixture/aggressive import/should work with destructuration/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(({ foo }) => import(/* webpackChunkName: "Pages" */ `./${foo}`)); diff --git a/packages/loadable-components/tests/fixture/aggressive import/should work with destructuration/output.js b/packages/loadable-components/tests/fixture/aggressive import/should work with destructuration/output.js index ccc18964a..cf4babafa 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/should work with destructuration/output.js +++ b/packages/loadable-components/tests/fixture/aggressive import/should work with destructuration/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName ({ foo }) { diff --git a/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should keep it/input.js b/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should keep it/input.js index 489b775b4..9b4a83b78 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should keep it/input.js +++ b/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should keep it/input.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable( (props) => import(/* webpackChunkName: "pages/[request]" */ `./pages/${props.path}`), diff --git a/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should keep it/output.js b/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should keep it/output.js index 88c405e44..b34923b6f 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should keep it/output.js +++ b/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should keep it/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName (props) { diff --git a/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should replace it/input.js b/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should replace it/input.js index ba905cc0e..06559306f 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should replace it/input.js +++ b/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should replace it/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable((props) => import(/* webpackChunkName: "Pages" */ `./${props.foo}`)); diff --git a/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should replace it/output.js b/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should replace it/output.js index 8c8713376..bb30aa878 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should replace it/output.js +++ b/packages/loadable-components/tests/fixture/aggressive import/with webpackChunkName/should replace it/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName (props) { diff --git a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support complex request/input.js b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support complex request/input.js index 49a3e5925..28883e3ce 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support complex request/input.js +++ b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support complex request/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable((props) => import(`./dir/${props.foo}/test`)); diff --git a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support complex request/output.js b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support complex request/output.js index bbc95bbe1..9161ca450 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support complex request/output.js +++ b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support complex request/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName (props) { diff --git a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support destructuring/input.js b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support destructuring/input.js index 621836e39..fc1cc8cb6 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support destructuring/input.js +++ b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support destructuring/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(({ foo }) => import(`./dir/${foo}/test`)); diff --git a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support destructuring/output.js b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support destructuring/output.js index eba8f031e..ca204541b 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support destructuring/output.js +++ b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support destructuring/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName ({ foo }) { diff --git a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support simple request/input.js b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support simple request/input.js index 2c1af89bc..3a4bf1582 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support simple request/input.js +++ b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support simple request/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable((props) => import(`./${props.foo}`)); diff --git a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support simple request/output.js b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support simple request/output.js index 8c8713376..bb30aa878 100644 --- a/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support simple request/output.js +++ b/packages/loadable-components/tests/fixture/aggressive import/without webpackChunkName/should support simple request/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName (props) { diff --git a/packages/loadable-components/tests/fixture/lazy/should be transpiled too/input.js b/packages/loadable-components/tests/fixture/lazy/should be transpiled too/input.js new file mode 100644 index 000000000..3ec157e26 --- /dev/null +++ b/packages/loadable-components/tests/fixture/lazy/should be transpiled too/input.js @@ -0,0 +1,3 @@ +import { lazy } from "@loadable/component"; + +lazy(() => import("./ModA")); diff --git a/packages/loadable-components/tests/fixture/lazy/should be transpiled too/output.js b/packages/loadable-components/tests/fixture/lazy/should be transpiled too/output.js new file mode 100644 index 000000000..15b0352b4 --- /dev/null +++ b/packages/loadable-components/tests/fixture/lazy/should be transpiled too/output.js @@ -0,0 +1,40 @@ +import { lazy } from "@loadable/component"; + +lazy({ + resolved: {}, + chunkName () { + return "ModA"; + }, + isReady (props) { + const key = this.resolve(props); + if (this.resolved[key] !== true) { + return false; + } + if (typeof __webpack_modules__ !== 'undefined') { + return !!__webpack_modules__[key]; + } + return false; + }, + importAsync: ()=>import(/*webpackChunkName: "ModA"*/ "./ModA"), + requireAsync (props) { + const key = this.resolve(props); + this.resolved[key] = false; + return this.importAsync(props).then((resolved)=>{ + this.resolved[key] = true; + return resolved; + }); + }, + requireSync (props) { + const id = this.resolve(props); + if (typeof __webpack_require__ !== 'undefined') { + return __webpack_require__(id); + } + return eval('module.require')(id); + }, + resolve () { + if (require.resolveWeak) { + return require.resolveWeak("./ModA"); + } + return eval('require.resolve')("./ModA"); + } +}); diff --git a/packages/loadable-components/tests/fixture/lazy/should not work without imported/input.js b/packages/loadable-components/tests/fixture/lazy/should not work without imported/input.js new file mode 100644 index 000000000..d9f0fc696 --- /dev/null +++ b/packages/loadable-components/tests/fixture/lazy/should not work without imported/input.js @@ -0,0 +1,3 @@ +import { lazy } from "react"; + +lazy(() => import("./ModA")); diff --git a/packages/loadable-components/tests/fixture/lazy/should not work without imported/output.js b/packages/loadable-components/tests/fixture/lazy/should not work without imported/output.js new file mode 100644 index 000000000..d9f0fc696 --- /dev/null +++ b/packages/loadable-components/tests/fixture/lazy/should not work without imported/output.js @@ -0,0 +1,3 @@ +import { lazy } from "react"; + +lazy(() => import("./ModA")); diff --git a/packages/loadable-components/tests/fixture/lazy/should work with renamed specifier/input.js b/packages/loadable-components/tests/fixture/lazy/should work with renamed specifier/input.js new file mode 100644 index 000000000..1c396edb4 --- /dev/null +++ b/packages/loadable-components/tests/fixture/lazy/should work with renamed specifier/input.js @@ -0,0 +1,3 @@ +import { lazy as renamedLazy } from "@loadable/component"; + +renamedLazy(() => import("./ModA")); diff --git a/packages/loadable-components/tests/fixture/lazy/should work with renamed specifier/output.js b/packages/loadable-components/tests/fixture/lazy/should work with renamed specifier/output.js new file mode 100644 index 000000000..6653e6172 --- /dev/null +++ b/packages/loadable-components/tests/fixture/lazy/should work with renamed specifier/output.js @@ -0,0 +1,40 @@ +import { lazy as renamedLazy } from "@loadable/component"; + +renamedLazy({ + resolved: {}, + chunkName () { + return "ModA"; + }, + isReady (props) { + const key = this.resolve(props); + if (this.resolved[key] !== true) { + return false; + } + if (typeof __webpack_modules__ !== 'undefined') { + return !!__webpack_modules__[key]; + } + return false; + }, + importAsync: ()=>import(/*webpackChunkName: "ModA"*/ "./ModA"), + requireAsync (props) { + const key = this.resolve(props); + this.resolved[key] = false; + return this.importAsync(props).then((resolved)=>{ + this.resolved[key] = true; + return resolved; + }); + }, + requireSync (props) { + const id = this.resolve(props); + if (typeof __webpack_require__ !== 'undefined') { + return __webpack_require__(id); + } + return eval('module.require')(id); + }, + resolve () { + if (require.resolveWeak) { + return require.resolveWeak("./ModA"); + } + return eval('require.resolve')("./ModA"); + } +}); diff --git a/packages/loadable-components/tests/fixture/loadable.lib/should be transpiled too/input.js b/packages/loadable-components/tests/fixture/loadable.lib/should be transpiled too/input.js index 3201bf91e..69a577eab 100644 --- a/packages/loadable-components/tests/fixture/loadable.lib/should be transpiled too/input.js +++ b/packages/loadable-components/tests/fixture/loadable.lib/should be transpiled too/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable.lib(() => import("moment")); diff --git a/packages/loadable-components/tests/fixture/loadable.lib/should be transpiled too/output.js b/packages/loadable-components/tests/fixture/loadable.lib/should be transpiled too/output.js index 0cdcccf92..31cb9946c 100644 --- a/packages/loadable-components/tests/fixture/loadable.lib/should be transpiled too/output.js +++ b/packages/loadable-components/tests/fixture/loadable.lib/should be transpiled too/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable.lib({ resolved: {}, chunkName () { diff --git a/packages/loadable-components/tests/fixture/simple import/in a complex promise/should work/input.js b/packages/loadable-components/tests/fixture/simple import/in a complex promise/should work/input.js index 7c31ab108..ad029cf67 100644 --- a/packages/loadable-components/tests/fixture/simple import/in a complex promise/should work/input.js +++ b/packages/loadable-components/tests/fixture/simple import/in a complex promise/should work/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(() => timeout(import("./ModA"), 2000)); diff --git a/packages/loadable-components/tests/fixture/simple import/in a complex promise/should work/output.js b/packages/loadable-components/tests/fixture/simple import/in a complex promise/should work/output.js index 666758378..6868d5a25 100644 --- a/packages/loadable-components/tests/fixture/simple import/in a complex promise/should work/output.js +++ b/packages/loadable-components/tests/fixture/simple import/in a complex promise/should work/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName () { diff --git a/packages/loadable-components/tests/fixture/simple import/should transform path into chunk-friendly name/input.js b/packages/loadable-components/tests/fixture/simple import/should transform path into chunk-friendly name/input.js index a41af4148..e723f0f4c 100644 --- a/packages/loadable-components/tests/fixture/simple import/should transform path into chunk-friendly name/input.js +++ b/packages/loadable-components/tests/fixture/simple import/should transform path into chunk-friendly name/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(() => import("../foo/bar")); diff --git a/packages/loadable-components/tests/fixture/simple import/should transform path into chunk-friendly name/output.js b/packages/loadable-components/tests/fixture/simple import/should transform path into chunk-friendly name/output.js index 2b997ed10..c249e05c9 100644 --- a/packages/loadable-components/tests/fixture/simple import/should transform path into chunk-friendly name/output.js +++ b/packages/loadable-components/tests/fixture/simple import/should transform path into chunk-friendly name/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName () { diff --git a/packages/loadable-components/tests/fixture/simple import/should work with mul in name/input.js b/packages/loadable-components/tests/fixture/simple import/should work with mul in name/input.js index e7762091b..a738c5748 100644 --- a/packages/loadable-components/tests/fixture/simple import/should work with mul in name/input.js +++ b/packages/loadable-components/tests/fixture/simple import/should work with mul in name/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(() => import(`./foo*`)); diff --git a/packages/loadable-components/tests/fixture/simple import/should work with mul in name/output.js b/packages/loadable-components/tests/fixture/simple import/should work with mul in name/output.js index a046e67e4..f2a3333f7 100644 --- a/packages/loadable-components/tests/fixture/simple import/should work with mul in name/output.js +++ b/packages/loadable-components/tests/fixture/simple import/should work with mul in name/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName () { diff --git a/packages/loadable-components/tests/fixture/simple import/should work with plus concatenation/input.js b/packages/loadable-components/tests/fixture/simple import/should work with plus concatenation/input.js index 85c4ebbcb..f5fcb073c 100644 --- a/packages/loadable-components/tests/fixture/simple import/should work with plus concatenation/input.js +++ b/packages/loadable-components/tests/fixture/simple import/should work with plus concatenation/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(() => import("./Mod" + "A")); diff --git a/packages/loadable-components/tests/fixture/simple import/should work with plus concatenation/output.js b/packages/loadable-components/tests/fixture/simple import/should work with plus concatenation/output.js index 5c3294ceb..8e792833d 100644 --- a/packages/loadable-components/tests/fixture/simple import/should work with plus concatenation/output.js +++ b/packages/loadable-components/tests/fixture/simple import/should work with plus concatenation/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName () { diff --git a/packages/loadable-components/tests/fixture/simple import/should work with template literal/input.js b/packages/loadable-components/tests/fixture/simple import/should work with template literal/input.js index 91a998a0f..c00666ffb 100644 --- a/packages/loadable-components/tests/fixture/simple import/should work with template literal/input.js +++ b/packages/loadable-components/tests/fixture/simple import/should work with template literal/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(() => import(`./ModA`)); diff --git a/packages/loadable-components/tests/fixture/simple import/should work with template literal/output.js b/packages/loadable-components/tests/fixture/simple import/should work with template literal/output.js index bca81ae28..053d472f3 100644 --- a/packages/loadable-components/tests/fixture/simple import/should work with template literal/output.js +++ b/packages/loadable-components/tests/fixture/simple import/should work with template literal/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName () { diff --git a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should add it/input.js b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should add it/input.js index fac31dc83..53a7828e3 100644 --- a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should add it/input.js +++ b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should add it/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(() => import("./ModA")); diff --git a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should add it/output.js b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should add it/output.js index 3bef76dc2..ab513a047 100644 --- a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should add it/output.js +++ b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should add it/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName () { diff --git a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it even if comment is separated by ,/input.js b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it even if comment is separated by ,/input.js index fc9825893..48fe8a968 100644 --- a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it even if comment is separated by ,/input.js +++ b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it even if comment is separated by ,/input.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable( () => import(/* webpackPrefetch: true, webpackChunkName: "ChunkA" */ "./ModA"), diff --git a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it even if comment is separated by ,/output.js b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it even if comment is separated by ,/output.js index ad56fe324..566efa187 100644 --- a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it even if comment is separated by ,/output.js +++ b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it even if comment is separated by ,/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName () { diff --git a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it/input.js b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it/input.js index a380878d9..78cc361c7 100644 --- a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it/input.js +++ b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it/input.js @@ -1 +1,2 @@ +import loadable from "@loadable/component"; loadable(() => import(/* webpackChunkName: "ChunkA" */ "./ModA")); diff --git a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it/output.js b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it/output.js index 7115be351..43f8b7062 100644 --- a/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it/output.js +++ b/packages/loadable-components/tests/fixture/simple import/with webpackChunkName comment/should use it/output.js @@ -1,3 +1,4 @@ +import loadable from "@loadable/component"; loadable({ resolved: {}, chunkName () {