diff --git a/crates/mako/src/plugins/farm_tree_shake/shake/skip_module.rs b/crates/mako/src/plugins/farm_tree_shake/shake/skip_module.rs index 8719e93e4..60c2aaaa9 100644 --- a/crates/mako/src/plugins/farm_tree_shake/shake/skip_module.rs +++ b/crates/mako/src/plugins/farm_tree_shake/shake/skip_module.rs @@ -204,6 +204,7 @@ pub(super) fn skip_module_optimize( if match_ident == replace.re_export_ident { matched_ident = Some(named.local.take()); matched_index = Some(index); + break; } } ImportSpecifier::Default(_default_specifier) => {} diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/expect.js b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/expect.js new file mode 100644 index 000000000..27e2ee3fc --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/expect.js @@ -0,0 +1,9 @@ +const assert = require('assert'); +const { parseBuildResult } = require('../../../scripts/test-utils'); +const { files } = parseBuildResult(__dirname); + +const content = files['index.js']; + +assert(!content.includes('src/dep/index.js'), `should skip middle files`); + +assert(content.includes('console.log(_dep.default, _dep.default)'), `should change field name`); diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/mako.config.json b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/mako.config.json new file mode 100644 index 000000000..1b25a8c21 --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/mako.config.json @@ -0,0 +1,3 @@ +{ + "optimizePackageImports": false +} diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/dep/dep.js b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/dep/dep.js new file mode 100644 index 000000000..aef22247d --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/dep/dep.js @@ -0,0 +1 @@ +export default 1; diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/dep/index.js b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/dep/index.js new file mode 100644 index 000000000..a0721f721 --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/dep/index.js @@ -0,0 +1 @@ +export { default } from './dep.js'; diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/index.ts b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/index.ts new file mode 100644 index 000000000..219b33ee6 --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_default_as/src/index.ts @@ -0,0 +1,3 @@ +import { default as d1, default as d2 } from './dep/index.js'; + +console.log(d1,d2); diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/expect.js b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/expect.js new file mode 100644 index 000000000..27e2ee3fc --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/expect.js @@ -0,0 +1,9 @@ +const assert = require('assert'); +const { parseBuildResult } = require('../../../scripts/test-utils'); +const { files } = parseBuildResult(__dirname); + +const content = files['index.js']; + +assert(!content.includes('src/dep/index.js'), `should skip middle files`); + +assert(content.includes('console.log(_dep.default, _dep.default)'), `should change field name`); diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/mako.config.json b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/mako.config.json new file mode 100644 index 000000000..1b25a8c21 --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/mako.config.json @@ -0,0 +1,3 @@ +{ + "optimizePackageImports": false +} diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/dep/dep.js b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/dep/dep.js new file mode 100644 index 000000000..aef22247d --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/dep/dep.js @@ -0,0 +1 @@ +export default 1; diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/dep/index.js b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/dep/index.js new file mode 100644 index 000000000..7ef795b25 --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/dep/index.js @@ -0,0 +1 @@ +export { default as n } from './dep.js'; diff --git a/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/index.ts b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/index.ts new file mode 100644 index 000000000..9aaa2784a --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.import_double_named_as/src/index.ts @@ -0,0 +1,3 @@ +import { n as d1, n as d2 } from './dep/index.js'; + +console.log(d1,d2); diff --git a/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/expect.js b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/expect.js new file mode 100644 index 000000000..b8369cfdc --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/expect.js @@ -0,0 +1,10 @@ +const assert = require('assert'); +const { parseBuildResult } = require('../../../scripts/test-utils'); +const { files } = parseBuildResult(__dirname); + +const content = files['index.js']; + +assert(!content.includes('src/dep/proxy.js'), `should skip middle files`); + +assert(content.match(/v1:\s+function\(\) {\s+return _dep\.default;\s+}/), `should export v1 ref to _dep.default`) +assert(content.match(/v2:\s+function\(\) {\s+return _dep\.default;\s+}/), `should export v2 ref to _dep.default`) diff --git a/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/mako.config.json b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/mako.config.json new file mode 100644 index 000000000..1b25a8c21 --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/mako.config.json @@ -0,0 +1,3 @@ +{ + "optimizePackageImports": false +} diff --git a/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/dep.js b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/dep.js new file mode 100644 index 000000000..aef22247d --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/dep.js @@ -0,0 +1 @@ +export default 1; diff --git a/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/index.js b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/index.js new file mode 100644 index 000000000..11c93571a --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/index.js @@ -0,0 +1,3 @@ +export { default as v1, default as v2 } from './proxy.js'; + +console.log('sideEffects') diff --git a/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/proxy.js b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/proxy.js new file mode 100644 index 000000000..fead7cde4 --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/dep/proxy.js @@ -0,0 +1 @@ +export { default } from './dep.js' diff --git a/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/index.ts b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/index.ts new file mode 100644 index 000000000..47ce804de --- /dev/null +++ b/e2e/fixtures/tree-shaking.skip_module.reexport_same_name_twice/src/index.ts @@ -0,0 +1,3 @@ +import { v1, v2 } from './dep/index.js'; + +console.log(v1,v2);