From 69728bdef4ae1e07d35f0ffa77e2e583688b0533 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Fri, 24 Nov 2023 17:07:00 +0800 Subject: [PATCH] fix: flag side effects plugin update dep (#4747) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 🤖 ck point * chore: 🤖 update * chore: 🤖 update * chore: 🤖 update snapshot * chore: 🤖 update * chore: 🤖 update snap * chore: 🤖 update snapshot * chore: 🤖 update check.js * chore: 🤖 update snapshot * chore: 🤖 resolve conflict * chore: 🤖 lint * chore: 🤖 update dep * chore: 🤖 impl hash by hand * chore: 🤖 recover * chore: 🤖 clean up * chore: 🤖 update snap * chore: 🤖 fmt * chore: 🤖 clean * chore: 🤖 recover --- crates/rspack/tests/check.js | 58 ++++- crates/rspack/tests/fixtures.rs | 10 +- .../snapshot/new_treeshaking.snap | 2 +- .../array-side-effects/snapshot/output.snap | 2 +- .../rspack/tests/tree-shaking/basic/index.js | 4 +- crates/rspack/tests/tree-shaking/basic/lib.js | 5 +- .../basic/snapshot/new_treeshaking.snap | 32 +-- .../tree-shaking/basic/snapshot/output.snap | 25 +- .../tree-shaking/basic/snapshot/snap.diff | 29 ++- .../bb/snapshot/new_treeshaking.snap | 23 +- .../tests/tree-shaking/bb/snapshot/snap.diff | 39 +++ .../snapshot/new_treeshaking.snap | 13 +- .../snapshot/output.snap | 4 +- .../cjs-tree-shaking-basic/snapshot/snap.diff | 23 ++ .../snapshot/new_treeshaking.snap | 14 +- .../snapshot/snap.diff | 31 +++ .../snapshot/new_treeshaking.snap | 22 +- .../snapshot/snap.diff | 35 +++ .../snapshot/new_treeshaking.snap | 35 +-- .../export-star-chain/snapshot/snap.diff | 63 +++++ .../snapshot/new_treeshaking.snap | 12 +- .../snapshot/snap.diff | 26 ++ .../snapshot/new_treeshaking.snap | 14 +- .../snapshot/snap.diff | 27 +++ .../snapshot/new_treeshaking.snap | 15 +- .../snapshot/output.snap | 4 +- .../snapshot/snap.diff | 28 +++ .../snapshot/new_treeshaking.snap | 2 +- .../snapshot/output.snap | 2 +- .../snapshot/new_treeshaking.snap | 6 +- .../snapshot/snap.diff | 18 ++ .../snapshot/new_treeshaking.snap | 34 +-- .../snapshot/snap.diff | 53 ++++- .../snapshot/new_treeshaking.snap | 4 +- .../named_export_alias/snapshot/output.snap | 4 +- .../snapshot/new_treeshaking.snap | 24 +- .../snapshot/snap.diff | 47 ++++ .../snapshot/new_treeshaking.snap | 16 +- .../nested-import-3/snapshot/snap.diff | 30 +++ .../snapshot/new_treeshaking.snap | 14 +- .../nested-import-4/snapshot/snap.diff | 24 ++ .../snapshot/new_treeshaking.snap | 14 +- .../prune-bailout-module/snapshot/snap.diff | 24 ++ .../snapshot/new_treeshaking.snap | 29 +-- .../react-redux-like/snapshot/snap.diff | 42 ++++ .../snapshot/new_treeshaking.snap | 24 +- .../snapshot/snap.diff | 37 +++ .../snapshot/new_treeshaking.snap | 22 +- .../reexport-all-as/snapshot/snap.diff | 35 +++ .../snapshot/new_treeshaking.snap | 14 +- .../snapshot/snap.diff | 31 +++ .../snapshot/new_treeshaking.snap | 14 +- .../side-effects-analyzed/snapshot/snap.diff | 27 +++ .../snapshot/new_treeshaking.snap | 12 +- .../side-effects-prune/snapshot/snap.diff | 24 ++ .../snapshot/new_treeshaking.snap | 16 +- .../side-effects-two/snapshot/snap.diff | 29 +++ .../snapshot/new_treeshaking.snap | 4 +- .../snapshot/output.snap | 4 +- .../snapshot/new_treeshaking.snap | 13 +- .../ts-target-es5/snapshot/snap.diff | 32 ++- .../snapshot/new_treeshaking.snap | 12 +- .../snapshot/output.snap | 12 +- .../snapshot/new_treeshaking.snap | 22 +- .../snapshot/snap.diff | 53 +++++ .../snapshot/new_treeshaking.snap | 17 +- .../snapshot/snap.diff | 48 ++++ .../rspack_core/src/compiler/compilation.rs | 9 +- crates/rspack_core/src/dependency/mod.rs | 32 +-- .../src/dependency/runtime_template.rs | 10 +- crates/rspack_core/src/exports_info.rs | 225 ++++++++---------- .../src/module_graph/connection.rs | 13 +- crates/rspack_core/src/module_graph/mod.rs | 115 ++++----- crates/rspack_core/src/utils/import_var.rs | 30 +++ crates/rspack_core/src/utils/mod.rs | 3 + ...ny_export_imported_specifier_dependency.rs | 18 +- .../esm/harmony_import_dependency.rs | 23 +- .../harmony_import_specifier_dependency.rs | 21 +- .../plugin/flag_dependency_usage_plugin.rs | 4 + .../src/plugin/side_effects_flag_plugin.rs | 33 ++- .../__snapshots__/StatsTestCases.test.ts.snap | 8 +- 81 files changed, 1246 insertions(+), 782 deletions(-) create mode 100644 crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/export-imported-import-all-as/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/export-star-chain/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/namespace-access-var-decl-rhs/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/nested-import-3/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/nested-import-4/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/react-redux-like/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/reexport-all-as-multi-level-nested/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/side-effects-two/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/snap.diff create mode 100644 crates/rspack_core/src/utils/import_var.rs diff --git a/crates/rspack/tests/check.js b/crates/rspack/tests/check.js index 73bfb53648e..3b78f808665 100644 --- a/crates/rspack/tests/check.js +++ b/crates/rspack/tests/check.js @@ -27,17 +27,48 @@ const falsePositiveMap = { "var-function-expr": "align webpack unused binding behavior", "webpack-innergraph-no-side-effects": "align webpack unused binding behavior", "side-effects-export-default-expr": "align webpack unused binding behavior", - "webpack-innergraph-circular": "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files", - "static-class": "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files", - "webpack-inner-graph-export-default-named": "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files", - "class-extend": "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4481/files", - "export_star": "same as webpack https://gist.github.com/IWANABETHATGUY/1ee8aa4c2889a9246d19d7be0ac75bb7", - "issue-4637": "align webpack https://github.com/web-infra-dev/rspack/pull/4637/files#diff-d434486532fb1507da93a26ce108dca465337b6af0ee86b4ab94fd788810d288", - "named-export-decl-with-src-eval": "align to webpack: https://github.com/web-infra-dev/rspack/pull/4629/files#r1393574682", - "rollup-unused-var": "align to webpack, https://github.com/web-infra-dev/rspack/pull/4629/files#r1393575194", - "ts-target-es5": "align to webpack, https://github.com/web-infra-dev/rspack/pull/4629/files#r1392268704", - "webpack-reexport-namespace-and-default": "align to webapck, https://github.com/web-infra-dev/rspack/pull/4629/files#r1393576913" - + "webpack-innergraph-circular": + "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files", + "static-class": + "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files", + "webpack-inner-graph-export-default-named": + "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4463/files", + "class-extend": + "align webpack unused binding behavior https://github.com/web-infra-dev/rspack/pull/4481/files", + export_star: + "same as webpack https://gist.github.com/IWANABETHATGUY/1ee8aa4c2889a9246d19d7be0ac75bb7", + "issue-4637": + "align webpack https://github.com/web-infra-dev/rspack/pull/4637/files#diff-d434486532fb1507da93a26ce108dca465337b6af0ee86b4ab94fd788810d288", + "named-export-decl-with-src-eval": + "align to webpack: https://github.com/web-infra-dev/rspack/pull/4629/files#r1393574682", + "rollup-unused-var": + "align to webpack, https://github.com/web-infra-dev/rspack/pull/4629/files#r1393575194", + "ts-target-es5": + "align to webpack, https://github.com/web-infra-dev/rspack/pull/4629/files#r1392268704", + "webpack-reexport-namespace-and-default": + "align to webapck, https://github.com/web-infra-dev/rspack/pull/4629/files#r1393576913", + bb: "update dep", + "cjs-tree-shaking-basic": "update dep", + "cyclic-reference-export-all": + "redundant `usePlatform: function() { return usePlatform;`", + "export-imported-import-all-as": "update dep", + "import-var-assign-side-effects": "update dep", + "nested-import-3": "update dep", + "nested-import-4": "update dep", + "prune-bailout-module": "update dep", + pure_comments_magic_comments: "update dep", + "reexport-all-as": "update dep", + reexport_entry_elimination: "update dep", + "side-effects-analyzed": "update dep", + "side-effects-prune": "update dep", + "side-effects-two": "update dep", + "export-star-chain": "update dep", + "import-export-all-as-a-empty-module": "update dep", + "import-star-as-and-export": "update dep", + "module-rule-side-effects2": "align with webpack", + "react-redux-like": "update dep", + "webpack-side-effects-all-used": "update dep", + "webpack-side-effects-simple-unused": "update dep", }; const normalizedList = filteredList.map((item) => { @@ -69,5 +100,8 @@ let failedCases = normalizedList console.log(`failed: ${filteredList.length - successedCount}`); console.log(`passed: ${successedCount}`); -console.log(`fasePositiveCases: ${fasePositiveCases.length}\n`, fasePositiveCases); +console.log( + `fasePositiveCases: ${fasePositiveCases.length}\n`, + fasePositiveCases, +); console.log(`failedCases: ${failedCases.length}\n`, failedCases); diff --git a/crates/rspack/tests/fixtures.rs b/crates/rspack/tests/fixtures.rs index 8fab32cde09..8e1ff69f91a 100644 --- a/crates/rspack/tests/fixtures.rs +++ b/crates/rspack/tests/fixtures.rs @@ -3,7 +3,9 @@ use std::sync::atomic::Ordering; use cargo_rst::git_diff; use rspack_core::{BoxPlugin, CompilerOptions, TreeShaking, UsedExportsOption, IS_NEW_TREESHAKING}; -use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsagePlugin}; +use rspack_plugin_javascript::{ + FlagDependencyExportsPlugin, FlagDependencyUsagePlugin, SideEffectsFlagPlugin, +}; use rspack_testing::test_fixture; use testing_macros::fixture; @@ -38,9 +40,9 @@ fn tree_shaking(fixture_path: PathBuf) { options.optimization.used_exports = UsedExportsOption::True; options.builtins.tree_shaking = TreeShaking::False; - // if options.optimization.side_effects.is_enable() { - // plugins.push(Box::::default()); - // } + if options.optimization.side_effects.is_enable() { + plugins.push(Box::::default()); + } plugins.push(Box::::default()); plugins.push(Box::::default()); }, diff --git a/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/new_treeshaking.snap index a0540c9d9ab..c6480eb00ad 100644 --- a/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/new_treeshaking.snap @@ -17,7 +17,7 @@ app.prototype.result = _lib__WEBPACK_IMPORTED_MODULE_0__.result; "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./src/a */"./src/a.js"); +/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./src/a */"./src/a.js"); }), diff --git a/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/output.snap b/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/output.snap index a0540c9d9ab..c6480eb00ad 100644 --- a/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/output.snap @@ -17,7 +17,7 @@ app.prototype.result = _lib__WEBPACK_IMPORTED_MODULE_0__.result; "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./src/a */"./src/a.js"); +/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./src/a */"./src/a.js"); }), diff --git a/crates/rspack/tests/tree-shaking/basic/index.js b/crates/rspack/tests/tree-shaking/basic/index.js index cf9432001e6..8c062158924 100644 --- a/crates/rspack/tests/tree-shaking/basic/index.js +++ b/crates/rspack/tests/tree-shaking/basic/index.js @@ -1 +1,3 @@ -import * as test from "./app"; +import { answer } from "./lib"; +answer + diff --git a/crates/rspack/tests/tree-shaking/basic/lib.js b/crates/rspack/tests/tree-shaking/basic/lib.js index e38fe0783e0..f0e60e6085a 100644 --- a/crates/rspack/tests/tree-shaking/basic/lib.js +++ b/crates/rspack/tests/tree-shaking/basic/lib.js @@ -1,4 +1 @@ -import { answer } from "./answer"; -export const secret = "888"; -export const myanswer = answer, - result = 20000; +export {answer} from './answer' diff --git a/crates/rspack/tests/tree-shaking/basic/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/basic/snapshot/new_treeshaking.snap index 630685c4fe7..06581f2e08e 100644 --- a/crates/rspack/tests/tree-shaking/basic/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/basic/snapshot/new_treeshaking.snap @@ -11,40 +11,12 @@ __webpack_require__.d(__webpack_exports__, { }); const answer = 103330; }), -"./app.js": (function (module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); - -setTimeout(()=>{ - console.log(_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer); -}, 1000); - function render() { - function test() { - const container = document.getElementById("root"); - container.innerHTML = `adddd333:${secret}:${myanswer}`; - } -} -if (module.hot?.accept) module.hot.accept((module1)=>{ - console.log("xxx:", module1); -}); -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); - -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - myanswer: function() { return myanswer; } -}); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./answer.js"); - const secret = "888"; - const myanswer = _answer__WEBPACK_IMPORTED_MODULE_0__.answer, result = 20000; +_lib__WEBPACK_IMPORTED_MODULE_0__.answer; }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/basic/snapshot/output.snap b/crates/rspack/tests/tree-shaking/basic/snapshot/output.snap index 3d0028d4048..c2b672d0c5b 100644 --- a/crates/rspack/tests/tree-shaking/basic/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/basic/snapshot/output.snap @@ -11,40 +11,21 @@ __webpack_require__.d(__webpack_exports__, { }); const answer = 103330; }), -"./app.js": (function (module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); - -setTimeout(()=>{ - console.log(_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer); -}, 1000); - function render() { - function test() { - const container = document.getElementById("root"); - container.innerHTML = `adddd333:${/* "./lib" unused */null}:${_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer}`; - } -} -if (module.hot?.accept) module.hot.accept((module1)=>{ - console.log("xxx:", module1); -}); -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +_lib__WEBPACK_IMPORTED_MODULE_0__.answer; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - myanswer: function() { return myanswer; } + answer: function() { return _answer__WEBPACK_IMPORTED_MODULE_0__.answer; } }); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); - const secret = "888"; - const myanswer = _answer__WEBPACK_IMPORTED_MODULE_0__.answer, result = 20000; }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff index 6038165cb99..e9aa74c7167 100644 --- a/crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff @@ -1,11 +1,22 @@ --- expected +++ actual -@@ -22,7 +22,7 @@ - function render() { - function test() { - const container = document.getElementById("root"); -- container.innerHTML = `adddd333:${/* "./lib" unused */null}:${_lib__WEBPACK_IMPORTED_MODULE_0__.myanswer}`; -+ container.innerHTML = `adddd333:${secret}:${myanswer}`; - } - } - if (module.hot?.accept) module.hot.accept((module1)=>{ +@@ -14,18 +14,9 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); ++/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./answer.js"); + + _lib__WEBPACK_IMPORTED_MODULE_0__.answer; +-}), +-"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- answer: function() { return _answer__WEBPACK_IMPORTED_MODULE_0__.answer; } +-}); +-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); +- + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap index b23742753b9..c3156d404c4 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -3,27 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./b.js */"./b.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./c.js */"./c.js"); -__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); - - - const a = 3; -_b_js__WEBPACK_IMPORTED_MODULE_0__.d; - -}), -"./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - d: function() { return d; } -}); - const d = 3; - const c = 100; -}), "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); @@ -35,7 +14,7 @@ __webpack_require__.d(__webpack_exports__, { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); +/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./c.js"); _a_js__WEBPACK_IMPORTED_MODULE_0__.ccc; }), diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff new file mode 100644 index 00000000000..1f56357f555 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -0,0 +1,39 @@ +--- expected ++++ actual +@@ -3,27 +3,6 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./b.js */"./b.js"); +-/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./c.js */"./c.js"); +-__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); +- +- +- const a = 3; +-_b_js__WEBPACK_IMPORTED_MODULE_0__.d; +- +-}), +-"./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- d: function() { return d; } +-}); +- const d = 3; +- const c = 100; +-}), + "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +@@ -35,7 +14,7 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); ++/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./c.js"); + + _a_js__WEBPACK_IMPORTED_MODULE_0__.ccc; + }), diff --git a/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/new_treeshaking.snap index becfafa2f97..43ecbfbf1f7 100644 --- a/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/new_treeshaking.snap @@ -11,23 +11,14 @@ __webpack_require__.d(__webpack_exports__, { }); const answer = 42; -}), -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - myanswer: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__.myanswer; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); - }), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); __webpack_require__(/* ./answer */"./answer.js"); -(0, _app__WEBPACK_IMPORTED_MODULE_1__.myanswer)(); +(0, _app__WEBPACK_IMPORTED_MODULE_0__.myanswer)(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; diff --git a/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/output.snap b/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/output.snap index becfafa2f97..43fbd2b6ddd 100644 --- a/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/output.snap @@ -24,10 +24,10 @@ __webpack_require__.d(__webpack_exports__, { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); __webpack_require__(/* ./answer */"./answer.js"); -(0, _app__WEBPACK_IMPORTED_MODULE_1__.myanswer)(); +(0, _app__WEBPACK_IMPORTED_MODULE_0__.myanswer)(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; diff --git a/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/snap.diff new file mode 100644 index 00000000000..246f325364a --- /dev/null +++ b/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/snap.diff @@ -0,0 +1,23 @@ +--- expected ++++ actual +@@ -12,19 +12,10 @@ + + const answer = 42; + }), +-"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- myanswer: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__.myanswer; } +-}); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +- +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); + + __webpack_require__(/* ./answer */"./answer.js"); + (0, _app__WEBPACK_IMPORTED_MODULE_0__.myanswer)(); diff --git a/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/new_treeshaking.snap index b11b989675d..5dd5e732ed8 100644 --- a/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/new_treeshaking.snap @@ -9,9 +9,9 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": function() { return __WEBPACK_DEFAULT_EXPORT__; } }); -/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./containers */"./src/containers/index.js"); +/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); -const { PlatformProvider } = _containers__WEBPACK_IMPORTED_MODULE_0__.containers; +const { PlatformProvider } = _containers__WEBPACK_IMPORTED_MODULE_0__; const Index = ()=>{ console.log("PlatformProvider", PlatformProvider); return 'something'; @@ -25,16 +25,6 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -}), -"./src/containers/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - containers: function() { return _containers__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); - - }), "./src/containers/platform-container/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; diff --git a/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/snap.diff new file mode 100644 index 00000000000..260ca5fbc2e --- /dev/null +++ b/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/snap.diff @@ -0,0 +1,31 @@ +--- expected ++++ actual +@@ -9,9 +9,9 @@ + __webpack_require__.d(__webpack_exports__, { + "default": function() { return __WEBPACK_DEFAULT_EXPORT__; } + }); +-/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./containers */"./src/containers/index.js"); ++/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); + +-const { PlatformProvider } = _containers__WEBPACK_IMPORTED_MODULE_0__.containers; ++const { PlatformProvider } = _containers__WEBPACK_IMPORTED_MODULE_0__; + const Index = ()=>{ + console.log("PlatformProvider", PlatformProvider); + return 'something'; +@@ -23,16 +23,6 @@ + __webpack_require__.r(__webpack_exports__); + /* harmony import */var _platform_container__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./platform-container */"./src/containers/platform-container/index.js"); + __webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +- +-}), +-"./src/containers/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- containers: function() { return _containers__WEBPACK_IMPORTED_MODULE_0__; } +-}); +-/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); + + + }), diff --git a/crates/rspack/tests/tree-shaking/export-imported-import-all-as/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/export-imported-import-all-as/snapshot/new_treeshaking.snap index 017d686c7af..c945014d522 100644 --- a/crates/rspack/tests/tree-shaking/export-imported-import-all-as/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/export-imported-import-all-as/snapshot/new_treeshaking.snap @@ -3,30 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); -__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); - -_answer__WEBPACK_IMPORTED_MODULE_0__.filter; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - filter: function() { return _test_js__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./test.js */"./test.js"); - const a = 3; - +/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./test.js"); +_answer__WEBPACK_IMPORTED_MODULE_0__; }), "./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; diff --git a/crates/rspack/tests/tree-shaking/export-imported-import-all-as/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export-imported-import-all-as/snapshot/snap.diff new file mode 100644 index 00000000000..a072561e96e --- /dev/null +++ b/crates/rspack/tests/tree-shaking/export-imported-import-all-as/snapshot/snap.diff @@ -0,0 +1,35 @@ +--- expected ++++ actual +@@ -3,30 +3,12 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./answer.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +-__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); ++/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./test.js"); + +-_answer__WEBPACK_IMPORTED_MODULE_0__.filter; +-}), +-"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- filter: function() { return _test_js__WEBPACK_IMPORTED_MODULE_0__; } +-}); +-/* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./test.js */"./test.js"); +- const a = 3; +- +- ++_answer__WEBPACK_IMPORTED_MODULE_0__; + }), + "./test.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; diff --git a/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/new_treeshaking.snap index 47e3df2e3a1..65f62f212fa 100644 --- a/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/new_treeshaking.snap @@ -3,14 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./something */"./something/index.js"); -__webpack_require__.es(_something__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - - -}), "./colors/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); @@ -54,21 +46,15 @@ __webpack_require__.d(__webpack_exports__, { result: function() { return result; } }); const result = 'ssss'; -}), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./Layout */"./Layout.js"); -__webpack_require__.es(_Layout__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - }), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./export.js"); +/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./colors/index.js"); +/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./export */"./something/Something.js"); -_export__WEBPACK_IMPORTED_MODULE_0__.Colors; -_export__WEBPACK_IMPORTED_MODULE_0__.Something; +_export__WEBPACK_IMPORTED_MODULE_0__; +_export__WEBPACK_IMPORTED_MODULE_1__.Something; }), "./something/Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -78,19 +64,6 @@ __webpack_require__.d(__webpack_exports__, { }); class Something { } -}), -"./something/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Colors: function() { return _colors_index__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _colors_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../colors/index */"./colors/index.js"); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./Something */"./something/Something.js"); -__webpack_require__.es(_Something__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); - - - }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/snap.diff new file mode 100644 index 00000000000..23adc21cc97 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/snap.diff @@ -0,0 +1,63 @@ +--- expected ++++ actual +@@ -3,14 +3,6 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./something */"./something/index.js"); +-__webpack_require__.es(_something__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +- +-}), + "./colors/a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +@@ -54,21 +46,15 @@ + result: function() { return result; } + }); + const result = 'ssss'; +-}), +-"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./Layout */"./Layout.js"); +-__webpack_require__.es(_Layout__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- + }), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./export.js"); ++/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./colors/index.js"); ++/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./export */"./something/Something.js"); + +-_export__WEBPACK_IMPORTED_MODULE_0__.Colors; +-_export__WEBPACK_IMPORTED_MODULE_0__.Something; ++_export__WEBPACK_IMPORTED_MODULE_0__; ++_export__WEBPACK_IMPORTED_MODULE_1__.Something; + }), + "./something/Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; +@@ -78,19 +64,6 @@ + }); + class Something { + } +-}), +-"./something/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- Colors: function() { return _colors_index__WEBPACK_IMPORTED_MODULE_0__; } +-}); +-/* harmony import */var _colors_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../colors/index */"./colors/index.js"); +-/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./Something */"./something/Something.js"); +-__webpack_require__.es(_Something__WEBPACK_IMPORTED_MODULE_1__, __webpack_exports__); +- +- +- + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap index 3f35c2b32f1..b1d66c8da7d 100644 --- a/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap @@ -7,17 +7,17 @@ source: crates/rspack_testing/src/run_fixture.rs "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - aaa: function() { return _app__WEBPACK_IMPORTED_MODULE_1__; }, + aaa: function() { return _app__WEBPACK_IMPORTED_MODULE_0__; }, routes: function() { return routes; } }); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./app */"./app.js"); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./answer */"./answer.js"); +/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_0__); const routes = { - answer: _answer__WEBPACK_IMPORTED_MODULE_0__.something + answer: _answer__WEBPACK_IMPORTED_MODULE_1__.something }; }), "./answer.js": (function (__unused_webpack_module, exports, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/snap.diff new file mode 100644 index 00000000000..14b24db8101 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/snap.diff @@ -0,0 +1,26 @@ +--- expected ++++ actual +@@ -7,17 +7,17 @@ + "use strict"; + __webpack_require__.r(__webpack_exports__); + __webpack_require__.d(__webpack_exports__, { +- aaa: function() { return _app__WEBPACK_IMPORTED_MODULE_1__; }, ++ aaa: function() { return _app__WEBPACK_IMPORTED_MODULE_0__; }, + routes: function() { return routes; } + }); +-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); +-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_0__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./app */"./app.js"); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_1__); ++/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./answer */"./answer.js"); ++/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_1__); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_0__); + + + const routes = { +- answer: _answer__WEBPACK_IMPORTED_MODULE_0__.something ++ answer: _answer__WEBPACK_IMPORTED_MODULE_1__.something + }; + }), + "./answer.js": (function (__unused_webpack_module, exports, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/new_treeshaking.snap index 4323edf26e9..eb971e3f58e 100644 --- a/crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/new_treeshaking.snap @@ -3,22 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - app: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); - - -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); -_app__WEBPACK_IMPORTED_MODULE_0__.app; +_app__WEBPACK_IMPORTED_MODULE_0__; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; diff --git a/crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/snap.diff new file mode 100644 index 00000000000..c3a55f1a01c --- /dev/null +++ b/crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/snap.diff @@ -0,0 +1,27 @@ +--- expected ++++ actual +@@ -3,22 +3,12 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- app: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__; } +-}); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +- +- +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); + +-_app__WEBPACK_IMPORTED_MODULE_0__.app; ++_app__WEBPACK_IMPORTED_MODULE_0__; + }), + "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; diff --git a/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/new_treeshaking.snap index 5d34affaef2..bb1a0729796 100644 --- a/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/new_treeshaking.snap @@ -11,24 +11,13 @@ __webpack_require__.d(__webpack_exports__, { }); class Something { } -}), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Sider: function() { return _Something__WEBPACK_IMPORTED_MODULE_1__["default"]; } -}); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./Something */"./Something.js"); - - - }), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./export.js"); +/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./Something.js"); -(0, _export__WEBPACK_IMPORTED_MODULE_0__.Sider)(); +(0, _export__WEBPACK_IMPORTED_MODULE_0__["default"])(); }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/output.snap b/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/output.snap index 5d34affaef2..e0502b69356 100644 --- a/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/output.snap @@ -16,9 +16,9 @@ class Something { "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - Sider: function() { return _Something__WEBPACK_IMPORTED_MODULE_1__["default"]; } + Sider: function() { return _Something__WEBPACK_IMPORTED_MODULE_0__["default"]; } }); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./Something */"./Something.js"); +/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./Something */"./Something.js"); diff --git a/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/snap.diff new file mode 100644 index 00000000000..7d7aa585297 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/snap.diff @@ -0,0 +1,28 @@ +--- expected ++++ actual +@@ -12,23 +12,12 @@ + class Something { + } + }), +-"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- Sider: function() { return _Something__WEBPACK_IMPORTED_MODULE_0__["default"]; } +-}); +-/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./Something */"./Something.js"); +- +- +- +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./export.js"); ++/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./Something.js"); + +-(0, _export__WEBPACK_IMPORTED_MODULE_0__.Sider)(); ++(0, _export__WEBPACK_IMPORTED_MODULE_0__["default"])(); + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/new_treeshaking.snap index 5ce597bbcbb..c398a7eb74f 100644 --- a/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/new_treeshaking.snap @@ -20,7 +20,7 @@ __webpack_require__.r(__webpack_exports__); "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./c.js */"./c.js"); +/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./c.js */"./c.js"); diff --git a/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/output.snap b/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/output.snap index 5ce597bbcbb..c398a7eb74f 100644 --- a/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/output.snap @@ -20,7 +20,7 @@ __webpack_require__.r(__webpack_exports__); "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./c.js */"./c.js"); +/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./c.js */"./c.js"); diff --git a/crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/new_treeshaking.snap index 51c51483df1..038ba8775ff 100644 --- a/crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/new_treeshaking.snap @@ -19,12 +19,12 @@ __webpack_require__.r(__webpack_exports__); "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./b.js */"./b.js"); +/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./a.js */"./a.js"); +/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./b.js */"./b.js"); -_a_js__WEBPACK_IMPORTED_MODULE_0__.a; +_a_js__WEBPACK_IMPORTED_MODULE_1__.a; }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/snap.diff new file mode 100644 index 00000000000..e9203fd5bce --- /dev/null +++ b/crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/snap.diff @@ -0,0 +1,18 @@ +--- expected ++++ actual +@@ -19,12 +19,12 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); +-/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./b.js */"./b.js"); ++/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./a.js */"./a.js"); ++/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./b.js */"./b.js"); + + + +-_a_js__WEBPACK_IMPORTED_MODULE_0__.a; ++_a_js__WEBPACK_IMPORTED_MODULE_1__.a; + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/new_treeshaking.snap index d6eff2d7698..ee937e71fd5 100644 --- a/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/new_treeshaking.snap @@ -3,22 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - "default": function() { return Layout; } -}); -function Layout() {} -}), -"./Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return something; } -}); - function something() {} -}), "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); @@ -27,26 +11,10 @@ __webpack_require__.d(__webpack_exports__, { }); function cccc() {} }), -"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - cccc: function() { return _c__WEBPACK_IMPORTED_MODULE_2__.cccc; } -}); -/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./Layout */"./Layout.js"); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./Something */"./Something.js"); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./c */"./c.js"); - - -var L = _Layout__WEBPACK_IMPORTED_MODULE_0__["default"]; -L.something = _Something__WEBPACK_IMPORTED_MODULE_1__.something; - - var LL = (/* unused pure expression or super */ null && (L)); -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./export.js"); +/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./c.js"); (0, _export__WEBPACK_IMPORTED_MODULE_0__.cccc)(); }), diff --git a/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/snap.diff index e3bd1da87a0..feebb434100 100644 --- a/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/snap.diff @@ -1,11 +1,54 @@ --- expected +++ actual -@@ -41,7 +41,7 @@ - var L = _Layout__WEBPACK_IMPORTED_MODULE_0__["default"]; - L.something = _Something__WEBPACK_IMPORTED_MODULE_1__.something; - +@@ -3,22 +3,6 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./Layout.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- "default": function() { return Layout; } +-}); +-function Layout() {} +-}), +-"./Something.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- something: function() { return something; } +-}); +- function something() {} +-}), + "./c.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +@@ -26,27 +10,11 @@ + cccc: function() { return cccc; } + }); + function cccc() {} +-}), +-"./export.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- cccc: function() { return _c__WEBPACK_IMPORTED_MODULE_2__.cccc; } +-}); +-/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./Layout */"./Layout.js"); +-/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./Something */"./Something.js"); +-/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./c */"./c.js"); +- +- +-var L = _Layout__WEBPACK_IMPORTED_MODULE_0__["default"]; +-L.something = _Something__WEBPACK_IMPORTED_MODULE_1__.something; +- - var LL = L; -+ var LL = (/* unused pure expression or super */ null && (L)); }), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./export.js"); ++/* harmony import */var _export__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./export */"./c.js"); + + (0, _export__WEBPACK_IMPORTED_MODULE_0__.cccc)(); + }), diff --git a/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/new_treeshaking.snap index 858a956988a..f8595caf65a 100644 --- a/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/new_treeshaking.snap @@ -17,11 +17,11 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": function() { return a; } }); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./Something */"./Something.js"); +/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./Something */"./Something.js"); var a = function test() { - _Something__WEBPACK_IMPORTED_MODULE_1__.something; + _Something__WEBPACK_IMPORTED_MODULE_0__.something; }; }), diff --git a/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/output.snap b/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/output.snap index 858a956988a..f8595caf65a 100644 --- a/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/output.snap @@ -17,11 +17,11 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { "default": function() { return a; } }); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./Something */"./Something.js"); +/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./Something */"./Something.js"); var a = function test() { - _Something__WEBPACK_IMPORTED_MODULE_1__.something; + _Something__WEBPACK_IMPORTED_MODULE_0__.something; }; }), diff --git a/crates/rspack/tests/tree-shaking/namespace-access-var-decl-rhs/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/namespace-access-var-decl-rhs/snapshot/new_treeshaking.snap index c34db7b787a..2a01d5de3d9 100644 --- a/crates/rspack/tests/tree-shaking/namespace-access-var-decl-rhs/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/namespace-access-var-decl-rhs/snapshot/new_treeshaking.snap @@ -22,25 +22,6 @@ __webpack_require__.d(__webpack_exports__, { const b = { b: "" }; -}), -"./enum-old.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__.a; }, - b: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.b; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a */"./a.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./b */"./b.js"); - - -}), -"./enum.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _enum_old__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./enum-old */"./enum-old.js"); -__webpack_require__.es(_enum_old__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - }), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -55,7 +36,8 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { getDocPermissionTextSendMe: function() { return getDocPermissionTextSendMe; } }); -/* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./enum.js */"./enum.js"); +/* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./enum.js */"./a.js"); +/* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./enum.js */"./b.js"); function Record() {} const code2CreateChatDocPermission = { @@ -64,7 +46,7 @@ function Record() {} function getDocPermissionTextSendMe() {} class Doc extends Record({}) { isSheet() { - return this.type === _enum_js__WEBPACK_IMPORTED_MODULE_0__.b.b; + return this.type === _enum_js__WEBPACK_IMPORTED_MODULE_1__.b.b; } } Doc.fromJS = (data)=>new Doc(data); diff --git a/crates/rspack/tests/tree-shaking/namespace-access-var-decl-rhs/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/namespace-access-var-decl-rhs/snapshot/snap.diff new file mode 100644 index 00000000000..619359a8188 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/namespace-access-var-decl-rhs/snapshot/snap.diff @@ -0,0 +1,47 @@ +--- expected ++++ actual +@@ -23,25 +23,6 @@ + b: "" + }; + }), +-"./enum-old.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__.a; }, +- b: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.b; } +-}); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a */"./a.js"); +-/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./b */"./b.js"); +- +- +-}), +-"./enum.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _enum_old__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./enum-old */"./enum-old.js"); +-__webpack_require__.es(_enum_old__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +@@ -55,7 +36,8 @@ + __webpack_require__.d(__webpack_exports__, { + getDocPermissionTextSendMe: function() { return getDocPermissionTextSendMe; } + }); +-/* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./enum.js */"./enum.js"); ++/* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./enum.js */"./a.js"); ++/* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./enum.js */"./b.js"); + + function Record() {} + const code2CreateChatDocPermission = { +@@ -64,7 +46,7 @@ + function getDocPermissionTextSendMe() {} + class Doc extends Record({}) { + isSheet() { +- return this.type === _enum_js__WEBPACK_IMPORTED_MODULE_0__.b.b; ++ return this.type === _enum_js__WEBPACK_IMPORTED_MODULE_1__.b.b; + } + } + Doc.fromJS = (data)=>new Doc(data); diff --git a/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/new_treeshaking.snap index b0d0471c383..1332ab2db24 100644 --- a/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/new_treeshaking.snap @@ -11,27 +11,13 @@ __webpack_require__.d(__webpack_exports__, { }); const a = 103330; const b = 103330; -}), -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); -__webpack_require__.es(_answer__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - }), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./answer.js"); _lib__WEBPACK_IMPORTED_MODULE_0__.a; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); -__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/snap.diff new file mode 100644 index 00000000000..a81ccbd1e42 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/snap.diff @@ -0,0 +1,30 @@ +--- expected ++++ actual +@@ -12,26 +12,12 @@ + const a = 103330; + const b = 103330; + }), +-"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); +-__webpack_require__.es(_answer__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); ++/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./answer.js"); + + _lib__WEBPACK_IMPORTED_MODULE_0__.a; +-}), +-"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); +-__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/new_treeshaking.snap index cc8dc5d6919..1332ab2db24 100644 --- a/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/new_treeshaking.snap @@ -15,19 +15,9 @@ __webpack_require__.d(__webpack_exports__, { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); - -_lib__WEBPACK_IMPORTED_MODULE_0__.Lib.a; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Lib: function() { return _answer__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); - +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./answer.js"); +_lib__WEBPACK_IMPORTED_MODULE_0__.a; }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/snap.diff new file mode 100644 index 00000000000..1c94e76ee5f --- /dev/null +++ b/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/snap.diff @@ -0,0 +1,24 @@ +--- expected ++++ actual +@@ -15,19 +15,9 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); ++/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./answer.js"); + +-_lib__WEBPACK_IMPORTED_MODULE_0__.Lib.a; +-}), +-"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- Lib: function() { return _answer__WEBPACK_IMPORTED_MODULE_0__; } +-}); +-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./answer */"./answer.js"); +- +- ++_lib__WEBPACK_IMPORTED_MODULE_0__.a; + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/new_treeshaking.snap index 5d08d165bd3..b4f9adce29d 100644 --- a/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/new_treeshaking.snap @@ -14,19 +14,9 @@ var __WEBPACK_DEFAULT_EXPORT__ = 300; "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); - -_lib__WEBPACK_IMPORTED_MODULE_0__.a; -}), -"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _a_js__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); - +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./a.js"); +_lib__WEBPACK_IMPORTED_MODULE_0__["default"]; }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/snap.diff new file mode 100644 index 00000000000..f5489463b59 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/snap.diff @@ -0,0 +1,24 @@ +--- expected ++++ actual +@@ -14,19 +14,9 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); ++/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./a.js"); + +-_lib__WEBPACK_IMPORTED_MODULE_0__.a; +-}), +-"./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- a: function() { return _a_js__WEBPACK_IMPORTED_MODULE_0__["default"]; } +-}); +-/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); +- +- ++_lib__WEBPACK_IMPORTED_MODULE_0__["default"]; + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/new_treeshaking.snap index 62cc2a18f48..8b361f3e630 100644 --- a/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/new_treeshaking.snap @@ -3,35 +3,14 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - Provider: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; }, - useSelector: function() { return _selector_js__WEBPACK_IMPORTED_MODULE_1__["default"]; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); -/* harmony import */var _selector_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./selector.js */"./selector.js"); - - - -}), -"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); -__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - -function batch() {} - -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./foo */"./foo.js"); +/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./foo */"./lib.js"); +/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./foo */"./selector.js"); -_foo__WEBPACK_IMPORTED_MODULE_0__.Provider; -_foo__WEBPACK_IMPORTED_MODULE_0__.useSelector; +_foo__WEBPACK_IMPORTED_MODULE_0__["default"]; +_foo__WEBPACK_IMPORTED_MODULE_1__["default"]; }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; diff --git a/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/snap.diff new file mode 100644 index 00000000000..1326320c0de --- /dev/null +++ b/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/snap.diff @@ -0,0 +1,42 @@ +--- expected ++++ actual +@@ -3,35 +3,14 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- Provider: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; }, +- useSelector: function() { return _selector_js__WEBPACK_IMPORTED_MODULE_1__["default"]; } +-}); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +-/* harmony import */var _selector_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./selector.js */"./selector.js"); +- +- +- +-}), +-"./foo.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); +-__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +-function batch() {} +- +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./foo */"./foo.js"); ++/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./foo */"./lib.js"); ++/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./foo */"./selector.js"); + +-_foo__WEBPACK_IMPORTED_MODULE_0__.Provider; +-_foo__WEBPACK_IMPORTED_MODULE_0__.useSelector; ++_foo__WEBPACK_IMPORTED_MODULE_0__["default"]; ++_foo__WEBPACK_IMPORTED_MODULE_1__["default"]; + }), + "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; diff --git a/crates/rspack/tests/tree-shaking/reexport-all-as-multi-level-nested/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/reexport-all-as-multi-level-nested/snapshot/new_treeshaking.snap index b3fea228e3f..c1c1b503d43 100644 --- a/crates/rspack/tests/tree-shaking/reexport-all-as-multi-level-nested/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/reexport-all-as-multi-level-nested/snapshot/new_treeshaking.snap @@ -24,32 +24,14 @@ __webpack_require__.d(__webpack_exports__, { }); const aa = 3; const cc = 3; -}), -"./package/autogen/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a */"./package/autogen/a.js"); - - - -}), -"./package/src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../autogen/index */"./package/autogen/index.js"); -__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - }), "./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../package/src/index.js */"./package/src/index.js"); +/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../package/src/index.js */"./package/autogen/a.js"); -_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.a; -_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.aa.aa; +_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a; +_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.aa.aa; }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/reexport-all-as-multi-level-nested/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/reexport-all-as-multi-level-nested/snapshot/snap.diff new file mode 100644 index 00000000000..73dd3b4af21 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/reexport-all-as-multi-level-nested/snapshot/snap.diff @@ -0,0 +1,37 @@ +--- expected ++++ actual +@@ -25,31 +25,13 @@ + const aa = 3; + const cc = 3; + }), +-"./package/autogen/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__; } +-}); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a */"./package/autogen/a.js"); +- +- +- +-}), +-"./package/src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../autogen/index */"./package/autogen/index.js"); +-__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +-}), + "./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../package/src/index.js */"./package/src/index.js"); ++/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../package/src/index.js */"./package/autogen/a.js"); + +-_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.a; +-_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.aa.aa; ++_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a; ++_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.aa.aa; + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/new_treeshaking.snap index 34fb7e0ee21..f69e982d18c 100644 --- a/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/new_treeshaking.snap @@ -11,31 +11,13 @@ __webpack_require__.d(__webpack_exports__, { }); function a() {} function dddd() {} -}), -"./package/autogen/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a */"./package/autogen/a.js"); - - - -}), -"./package/src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../autogen/index */"./package/autogen/index.js"); -__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - }), "./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../package/src/index.js */"./package/src/index.js"); +/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../package/src/index.js */"./package/autogen/a.js"); -_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.a; +_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a; }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/snap.diff new file mode 100644 index 00000000000..6ce6589311e --- /dev/null +++ b/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/snap.diff @@ -0,0 +1,35 @@ +--- expected ++++ actual +@@ -12,30 +12,12 @@ + function a() {} + function dddd() {} + }), +-"./package/autogen/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- a: function() { return _a__WEBPACK_IMPORTED_MODULE_0__; } +-}); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a */"./package/autogen/a.js"); +- +- +- +-}), +-"./package/src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../autogen/index */"./package/autogen/index.js"); +-__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +-}), + "./src/index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../package/src/index.js */"./package/src/index.js"); ++/* harmony import */var _package_src_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ../package/src/index.js */"./package/autogen/a.js"); + +-_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a.a; ++_package_src_index_js__WEBPACK_IMPORTED_MODULE_0__.a; + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/new_treeshaking.snap index ee5db544fe9..16fbb849e6e 100644 --- a/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/new_treeshaking.snap @@ -3,16 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - b: function() { return _b_js__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./b.js */"./b.js"); - - -}), "./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); @@ -34,9 +24,9 @@ var __WEBPACK_DEFAULT_EXPORT__ = 10; "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); +/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./b.js"); -_a_js__WEBPACK_IMPORTED_MODULE_0__.b; +_a_js__WEBPACK_IMPORTED_MODULE_0__["default"]; }), },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/snap.diff new file mode 100644 index 00000000000..dd6a70cbf21 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/snap.diff @@ -0,0 +1,31 @@ +--- expected ++++ actual +@@ -3,16 +3,6 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./a.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- b: function() { return _b_js__WEBPACK_IMPORTED_MODULE_0__["default"]; } +-}); +-/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./b.js */"./b.js"); +- +- +-}), + "./b.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +@@ -34,9 +24,9 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./a.js"); ++/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a.js */"./b.js"); + +-_a_js__WEBPACK_IMPORTED_MODULE_0__.b; ++_a_js__WEBPACK_IMPORTED_MODULE_0__["default"]; + }), + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/new_treeshaking.snap index 80e7353cf4e..afc73a29e27 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/new_treeshaking.snap @@ -3,22 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); - - -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); -(0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); +(0, _app__WEBPACK_IMPORTED_MODULE_0__["default"])(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; diff --git a/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/snap.diff new file mode 100644 index 00000000000..7ef23ddee58 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/snap.diff @@ -0,0 +1,27 @@ +--- expected ++++ actual +@@ -3,22 +3,12 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- something: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; } +-}); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +- +- +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); + +-(0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); ++(0, _app__WEBPACK_IMPORTED_MODULE_0__["default"])(); + }), + "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; diff --git a/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/new_treeshaking.snap index 0287645b14d..6f33f564255 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/new_treeshaking.snap @@ -3,20 +3,10 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); -__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); - - // export { - // result as test - // } -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); (0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); // a; }), diff --git a/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/snap.diff new file mode 100644 index 00000000000..f8f4bf2f310 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/snap.diff @@ -0,0 +1,24 @@ +--- expected ++++ actual +@@ -3,20 +3,10 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +-__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +- +- // export { +- // result as test +- // } +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); + + (0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); // a; + }), diff --git a/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/new_treeshaking.snap index aed7b34179c..afc73a29e27 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/new_treeshaking.snap @@ -3,24 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - something: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); - - // export { - // result as test - // } -}), "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); -(0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); +(0, _app__WEBPACK_IMPORTED_MODULE_0__["default"])(); }), "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; diff --git a/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/snap.diff new file mode 100644 index 00000000000..76586acb45f --- /dev/null +++ b/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/snap.diff @@ -0,0 +1,29 @@ +--- expected ++++ actual +@@ -3,24 +3,12 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./app.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- something: function() { return _lib__WEBPACK_IMPORTED_MODULE_0__["default"]; } +-}); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./lib */"./lib.js"); +- +- // export { +- // result as test +- // } +-}), + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./app.js"); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./app */"./lib.js"); + +-(0, _app__WEBPACK_IMPORTED_MODULE_0__.something)(); ++(0, _app__WEBPACK_IMPORTED_MODULE_0__["default"])(); + }), + "./lib.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; diff --git a/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/new_treeshaking.snap index 7c389185aa4..ad05d24523f 100644 --- a/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/new_treeshaking.snap @@ -9,8 +9,8 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); -/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./side-effects.js */"./side-effects.js"); -/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_side_effects_js__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./side-effects.js */"./side-effects.js"); +/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_side_effects_js__WEBPACK_IMPORTED_MODULE_0__); const a = 3; diff --git a/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/output.snap b/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/output.snap index 7c389185aa4..ad05d24523f 100644 --- a/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/output.snap @@ -9,8 +9,8 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { a: function() { return a; } }); -/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./side-effects.js */"./side-effects.js"); -/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_side_effects_js__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./side-effects.js */"./side-effects.js"); +/* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_side_effects_js__WEBPACK_IMPORTED_MODULE_0__); const a = 3; diff --git a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/new_treeshaking.snap index 29326beb406..a6ba86578f5 100644 --- a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/new_treeshaking.snap @@ -36,15 +36,6 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { }; } -}), -"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -"use strict"; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - _: function() { return tslib__WEBPACK_IMPORTED_MODULE_0__.__generator; } -}); -/* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); - }), "../../../../../node_modules/tslib/tslib.es6.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -483,7 +474,7 @@ var __setModuleDefault = Object.create ? function(o, v) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony import */var _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* @swc/helpers/_/_async_to_generator */"../../../../../node_modules/@swc/helpers/esm/_async_to_generator.js"); -/* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* @swc/helpers/_/_ts_generator */"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js"); +/* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* @swc/helpers/_/_ts_generator */"../../../../../node_modules/tslib/tslib.es6.js"); function test() { @@ -491,7 +482,7 @@ __webpack_require__.r(__webpack_exports__); } function _test() { _test = (0, _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__._)(function() { - return (0, _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__._)(this, function(_state) { + return (0, _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__.__generator)(this, function(_state) { return [ 2 ]; diff --git a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff index 517ec438e8d..021173220ac 100644 --- a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff @@ -1,6 +1,22 @@ --- expected +++ actual -@@ -482,9 +482,6 @@ +@@ -37,15 +37,6 @@ + } + + }), +-"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-"use strict"; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- _: function() { return tslib__WEBPACK_IMPORTED_MODULE_0__.__generator; } +-}); +-/* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); +- +-}), + "../../../../../node_modules/tslib/tslib.es6.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +@@ -482,11 +473,8 @@ "./index.ts": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); @@ -8,5 +24,17 @@ - test: function() { return test; } -}); /* harmony import */var _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* @swc/helpers/_/_async_to_generator */"../../../../../node_modules/@swc/helpers/esm/_async_to_generator.js"); - /* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* @swc/helpers/_/_ts_generator */"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js"); +-/* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* @swc/helpers/_/_ts_generator */"../../../../../node_modules/@swc/helpers/esm/_ts_generator.js"); ++/* harmony import */var _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* @swc/helpers/_/_ts_generator */"../../../../../node_modules/tslib/tslib.es6.js"); + + function test() { +@@ -494,7 +482,7 @@ + } + function _test() { + _test = (0, _swc_helpers_async_to_generator__WEBPACK_IMPORTED_MODULE_0__._)(function() { +- return (0, _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__._)(this, function(_state) { ++ return (0, _swc_helpers_ts_generator__WEBPACK_IMPORTED_MODULE_1__.__generator)(this, function(_state) { + return [ + 2 + ]; diff --git a/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/new_treeshaking.snap index b0ef4c09796..e8083820794 100644 --- a/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/new_treeshaking.snap @@ -6,9 +6,9 @@ source: crates/rspack_testing/src/run_fixture.rs "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./package1/script */"./package1/script.js"); -/* harmony import */var _package1_script2__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./package1/script2 */"./package1/script2.js"); -/* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/* ./package2/script */"./package2/script.js"); +/* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./package1/script */"./package1/script.js"); +/* harmony import */var _package1_script2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./package1/script2 */"./package1/script2.js"); +/* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./package2/script */"./package2/script.js"); @@ -17,12 +17,12 @@ it("should load module correctly", ()=>{ }); // if (process.env.NODE_ENV === "production") { it("default export should be unused", ()=>{ - expect(_package1_script__WEBPACK_IMPORTED_MODULE_1__.exportDefaultUsed).toBe(false); - expect(_package1_script2__WEBPACK_IMPORTED_MODULE_2__.exportDefaultUsed).toBe(false); + expect(_package1_script__WEBPACK_IMPORTED_MODULE_0__.exportDefaultUsed).toBe(false); + expect(_package1_script2__WEBPACK_IMPORTED_MODULE_1__.exportDefaultUsed).toBe(false); }); // } it("default export should be used", ()=>{ - expect(_package2_script__WEBPACK_IMPORTED_MODULE_3__.exportDefaultUsed).toBe(true); + expect(_package2_script__WEBPACK_IMPORTED_MODULE_2__.exportDefaultUsed).toBe(true); }); }), "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/output.snap b/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/output.snap index a3a7f520ba8..248ab0f65c4 100644 --- a/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/output.snap +++ b/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/output.snap @@ -6,9 +6,9 @@ source: crates/rspack_testing/src/run_fixture.rs "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./package1/script */"./package1/script.js"); -/* harmony import */var _package1_script2__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./package1/script2 */"./package1/script2.js"); -/* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/* ./package2/script */"./package2/script.js"); +/* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./package1/script */"./package1/script.js"); +/* harmony import */var _package1_script2__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./package1/script2 */"./package1/script2.js"); +/* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./package2/script */"./package2/script.js"); @@ -17,12 +17,12 @@ it("should load module correctly", ()=>{ }); // if (process.env.NODE_ENV === "production") { it("default export should be unused", ()=>{ - expect(_package1_script__WEBPACK_IMPORTED_MODULE_1__.exportDefaultUsed).toBe(false); - expect(_package1_script2__WEBPACK_IMPORTED_MODULE_2__.exportDefaultUsed).toBe(false); + expect(_package1_script__WEBPACK_IMPORTED_MODULE_0__.exportDefaultUsed).toBe(false); + expect(_package1_script2__WEBPACK_IMPORTED_MODULE_1__.exportDefaultUsed).toBe(false); }); // } it("default export should be used", ()=>{ - expect(_package2_script__WEBPACK_IMPORTED_MODULE_3__.exportDefaultUsed).toBe(true); + expect(_package2_script__WEBPACK_IMPORTED_MODULE_2__.exportDefaultUsed).toBe(true); }); }), "./module.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/new_treeshaking.snap index aeebc950b15..3f8bf396dbd 100644 --- a/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/new_treeshaking.snap @@ -21,10 +21,8 @@ var c = "c"; "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - z: function() { return _c__WEBPACK_IMPORTED_MODULE_0__.z; }, x: function() { return x; } }); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var x = "x"; var y = "y"; @@ -49,13 +47,8 @@ var z = "z"; "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - x: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.x; }, - z: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.z; }, "default": function() { return __WEBPACK_DEFAULT_EXPORT__; } }); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a */"../node_modules/pmodule/a.js"); -__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); @@ -82,16 +75,19 @@ __webpack_require__.d(__webpack_exports__, { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); -/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); +/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); +/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/a.js"); +/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/b.js"); +/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/c.js"); +/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); -pmodule__WEBPACK_IMPORTED_MODULE_1__["default"].should.be.eql("def"); +pmodule__WEBPACK_IMPORTED_MODULE_0__["default"].should.be.eql("def"); pmodule__WEBPACK_IMPORTED_MODULE_1__.a.should.be.eql("a"); -pmodule__WEBPACK_IMPORTED_MODULE_1__.x.should.be.eql("x"); -pmodule__WEBPACK_IMPORTED_MODULE_1__.z.should.be.eql("z"); -pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__.log.should.be.eql([ +pmodule__WEBPACK_IMPORTED_MODULE_2__.x.should.be.eql("x"); +pmodule__WEBPACK_IMPORTED_MODULE_3__.z.should.be.eql("z"); +pmodule_tracker__WEBPACK_IMPORTED_MODULE_4__.log.should.be.eql([ "a.js", "b.js", "c.js", diff --git a/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/snap.diff new file mode 100644 index 00000000000..be36ab885bb --- /dev/null +++ b/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/snap.diff @@ -0,0 +1,53 @@ +--- expected ++++ actual +@@ -21,10 +21,8 @@ + "use strict"; + __webpack_require__.r(__webpack_exports__); + __webpack_require__.d(__webpack_exports__, { +- z: function() { return _c__WEBPACK_IMPORTED_MODULE_0__.z; }, + x: function() { return x; } + }); +-/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + var x = "x"; + var y = "y"; +@@ -49,13 +47,8 @@ + "use strict"; + __webpack_require__.r(__webpack_exports__); + __webpack_require__.d(__webpack_exports__, { +- x: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.x; }, +- z: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.z; }, + "default": function() { return __WEBPACK_DEFAULT_EXPORT__; } + }); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./a */"../node_modules/pmodule/a.js"); +-__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0__, __webpack_exports__); +-/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + + +@@ -82,16 +75,19 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); +-/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); ++/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); ++/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/a.js"); ++/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/b.js"); ++/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/c.js"); ++/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); + + + +-pmodule__WEBPACK_IMPORTED_MODULE_1__["default"].should.be.eql("def"); ++pmodule__WEBPACK_IMPORTED_MODULE_0__["default"].should.be.eql("def"); + pmodule__WEBPACK_IMPORTED_MODULE_1__.a.should.be.eql("a"); +-pmodule__WEBPACK_IMPORTED_MODULE_1__.x.should.be.eql("x"); +-pmodule__WEBPACK_IMPORTED_MODULE_1__.z.should.be.eql("z"); +-pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__.log.should.be.eql([ ++pmodule__WEBPACK_IMPORTED_MODULE_2__.x.should.be.eql("x"); ++pmodule__WEBPACK_IMPORTED_MODULE_3__.z.should.be.eql("z"); ++pmodule_tracker__WEBPACK_IMPORTED_MODULE_4__.log.should.be.eql([ + "a.js", + "b.js", + "c.js", diff --git a/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/new_treeshaking.snap index 07a59e796e6..6802fe9269c 100644 --- a/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/new_treeshaking.snap @@ -7,10 +7,8 @@ source: crates/rspack_testing/src/run_fixture.rs "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - z: function() { return _c__WEBPACK_IMPORTED_MODULE_0__.z; }, x: function() { return x; } }); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var x = "x"; var y = "y"; @@ -35,11 +33,8 @@ var z = "z"; "use strict"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - x: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.x; }, - z: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.z; }, "default": function() { return __WEBPACK_DEFAULT_EXPORT__; } }); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); @@ -66,15 +61,17 @@ __webpack_require__.d(__webpack_exports__, { "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); -/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); -/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); +/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); +/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/b.js"); +/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/c.js"); +/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); -pmodule__WEBPACK_IMPORTED_MODULE_1__["default"].should.be.eql("def"); +pmodule__WEBPACK_IMPORTED_MODULE_0__["default"].should.be.eql("def"); pmodule__WEBPACK_IMPORTED_MODULE_1__.x.should.be.eql("x"); -pmodule__WEBPACK_IMPORTED_MODULE_1__.z.should.be.eql("z"); -pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__.log.should.be.eql([ +pmodule__WEBPACK_IMPORTED_MODULE_2__.z.should.be.eql("z"); +pmodule_tracker__WEBPACK_IMPORTED_MODULE_3__.log.should.be.eql([ "b.js", "c.js", "index.js" diff --git a/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/snap.diff new file mode 100644 index 00000000000..2c0eced625c --- /dev/null +++ b/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/snap.diff @@ -0,0 +1,48 @@ +--- expected ++++ actual +@@ -7,10 +7,8 @@ + "use strict"; + __webpack_require__.r(__webpack_exports__); + __webpack_require__.d(__webpack_exports__, { +- z: function() { return _c__WEBPACK_IMPORTED_MODULE_0__.z; }, + x: function() { return x; } + }); +-/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + var x = "x"; + var y = "y"; +@@ -35,11 +33,8 @@ + "use strict"; + __webpack_require__.r(__webpack_exports__); + __webpack_require__.d(__webpack_exports__, { +- x: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.x; }, +- z: function() { return _b__WEBPACK_IMPORTED_MODULE_1__.z; }, + "default": function() { return __WEBPACK_DEFAULT_EXPORT__; } + }); +-/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + + +@@ -66,15 +61,17 @@ + "./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "use strict"; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); +-/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); ++/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); ++/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/b.js"); ++/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/c.js"); ++/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); + + + +-pmodule__WEBPACK_IMPORTED_MODULE_1__["default"].should.be.eql("def"); ++pmodule__WEBPACK_IMPORTED_MODULE_0__["default"].should.be.eql("def"); + pmodule__WEBPACK_IMPORTED_MODULE_1__.x.should.be.eql("x"); +-pmodule__WEBPACK_IMPORTED_MODULE_1__.z.should.be.eql("z"); +-pmodule_tracker__WEBPACK_IMPORTED_MODULE_0__.log.should.be.eql([ ++pmodule__WEBPACK_IMPORTED_MODULE_2__.z.should.be.eql("z"); ++pmodule_tracker__WEBPACK_IMPORTED_MODULE_3__.log.should.be.eql([ + "b.js", + "c.js", + "index.js" diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 6a3793e4c8c..d8aef2adee4 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -767,13 +767,6 @@ impl Compilation { module_graph: &mut ModuleGraph, current_block: Option| { for dependency in dependencies { - if let Some(dependency) = dependency.as_module_dependency() { - module_graph - .set_dependency_import_var(module.identifier(), dependency.request()); - } else if let Some(dependency) = dependency.as_context_dependency() { - module_graph - .set_dependency_import_var(module.identifier(), dependency.request()); - } let dependency_id = *dependency.id(); if current_block.is_none() { module.add_dependency_id(dependency_id); @@ -1263,7 +1256,7 @@ impl Compilation { while plugin_driver.optimize_dependencies(self).await?.is_some() {} logger.time_end(start); // if self.options.is_new_tree_shaking() { - // debug_exports_info!(&self.module_graph); + // // debug_all_exports_info!(&self.module_graph); // } let start = logger.time("create chunks"); diff --git a/crates/rspack_core/src/dependency/mod.rs b/crates/rspack_core/src/dependency/mod.rs index 0107dcbe9c2..ba7479f04e6 100644 --- a/crates/rspack_core/src/dependency/mod.rs +++ b/crates/rspack_core/src/dependency/mod.rs @@ -14,6 +14,8 @@ mod runtime_requirements_dependency; mod runtime_template; mod span; +use std::sync::Arc; + pub use const_dependency::ConstDependency; pub use context_dependency::{AsContextDependency, ContextDependency}; pub use context_element_dependency::ContextElementDependency; @@ -127,33 +129,11 @@ impl From> for ExportsReferencedType { } } -pub type DependencyConditionFn = Box; - -pub trait Function: - Fn(&ModuleGraphConnection, Option<&RuntimeSpec>, &ModuleGraph) -> ConnectionState + Send + Sync -{ - fn clone_boxed(&self) -> Box; -} - -/// Copy from https://github.com/rust-lang/rust/issues/24000#issuecomment-479425396 -impl Function for T -where - T: 'static - + Fn(&ModuleGraphConnection, Option<&RuntimeSpec>, &ModuleGraph) -> ConnectionState +pub type DependencyConditionFn = Arc< + dyn Fn(&ModuleGraphConnection, Option<&RuntimeSpec>, &ModuleGraph) -> ConnectionState + Send - + Sync - + Clone, -{ - fn clone_boxed(&self) -> Box { - Box::new(self.clone()) - } -} - -impl Clone for Box { - fn clone(&self) -> Self { - self.clone_boxed() - } -} + + Sync, +>; #[derive(Clone)] pub enum DependencyCondition { diff --git a/crates/rspack_core/src/dependency/runtime_template.rs b/crates/rspack_core/src/dependency/runtime_template.rs index 6a9aa06d67d..0d98f1add74 100644 --- a/crates/rspack_core/src/dependency/runtime_template.rs +++ b/crates/rspack_core/src/dependency/runtime_template.rs @@ -1,9 +1,9 @@ use swc_core::ecma::atoms::JsWord; use crate::{ - property_access, AsyncDependenciesBlockIdentifier, Compilation, DependencyId, ExportsType, - FakeNamespaceObjectMode, InitFragmentExt, InitFragmentKey, InitFragmentStage, ModuleGraph, - ModuleIdentifier, NormalInitFragment, RuntimeGlobals, TemplateContext, + get_import_var, property_access, AsyncDependenciesBlockIdentifier, Compilation, DependencyId, + ExportsType, FakeNamespaceObjectMode, InitFragmentExt, InitFragmentKey, InitFragmentStage, + ModuleGraph, ModuleIdentifier, NormalInitFragment, RuntimeGlobals, TemplateContext, }; pub fn export_from_import( @@ -166,9 +166,7 @@ pub fn import_statement( runtime_requirements.insert(RuntimeGlobals::REQUIRE); - let import_var = compilation - .module_graph - .get_import_var(&module.identifier(), request); + let import_var = get_import_var(&compilation.module_graph, *id); let opt_declaration = if update { "" } else { "var " }; diff --git a/crates/rspack_core/src/exports_info.rs b/crates/rspack_core/src/exports_info.rs index fcd9360df58..9c6e8ae260a 100644 --- a/crates/rspack_core/src/exports_info.rs +++ b/crates/rspack_core/src/exports_info.rs @@ -682,7 +682,7 @@ impl ExportInfoId { pub fn set_used_conditionally( &self, mg: &mut ModuleGraph, - condition: UsageFilterFnTy, + condition: UsageFilterFnTy, new_value: UsageState, runtime: Option<&RuntimeSpec>, ) -> bool { @@ -821,54 +821,18 @@ struct UnResolvedExportInfoTarget { export: Option>, } +#[derive(Debug)] pub enum ResolvedExportInfoTargetWithCircular { Target(ResolvedExportInfoTarget), Circular, } -pub type UpdateOriginalFunctionTy = Box; - -pub trait UpdateOriginalFunction: - Fn(&ResolvedExportInfoTarget, &mut ModuleGraph) -> Option -{ - fn clone_boxed(&self) -> Box; -} - -impl UpdateOriginalFunction for T -where - T: 'static - + Fn(&ResolvedExportInfoTarget, &mut ModuleGraph) -> Option - + Clone, -{ - fn clone_boxed(&self) -> Box { - Box::new(self.clone()) - } -} +pub type UpdateOriginalFunctionTy = + Arc Option>; pub type ResolveFilterFnTy = Arc bool>; -pub type UsageFilterFnTy = Box>; - -pub trait FilterFn: Fn(&T) -> bool + Send + Sync { - fn clone_boxed(&self) -> Box>; -} - -/// Copy from https://github.com/rust-lang/rust/issues/24000#issuecomment-479425396 -impl FilterFn for T -where - T: 'static + Fn(&F) -> bool + Send + Sync + Clone, - F: 'static, -{ - fn clone_boxed(&self) -> Box> { - Box::new(self.clone()) - } -} - -impl Clone for Box> { - fn clone(&self) -> Self { - self.clone_boxed() - } -} +pub type UsageFilterFnTy = Box bool>; impl ExportInfo { // TODO: remove usage_state after new tree shaking is landing @@ -1046,93 +1010,95 @@ impl ExportInfo { } } - pub fn _get_target( - &mut self, - mg: &mut ModuleGraph, - resolve_filter: ResolveFilterFnTy, + #[allow(clippy::unwrap_in_result)] + fn resolve_target( + input_target: Option, already_visited: &mut HashSet, + resolve_filter: ResolveFilterFnTy, + mg: &mut ModuleGraph, ) -> Option { - fn resolve_target( - input_target: Option, - already_visited: &mut HashSet, - resolve_filter: ResolveFilterFnTy, - mg: &mut ModuleGraph, - ) -> Option { - if let Some(input_target) = input_target { - let mut target = ResolvedExportInfoTarget { - module: input_target - .connection - .as_ref() - .expect("should have connection") - .module_identifier, - export: input_target.export, - connection: input_target.connection.expect("should have connection"), - }; - if target.export.is_none() { - return Some(ResolvedExportInfoTargetWithCircular::Target(target)); - } - if !resolve_filter(&target, mg) { + if let Some(input_target) = input_target { + let mut target = ResolvedExportInfoTarget { + module: input_target + .connection + .as_ref() + .expect("should have connection") + .module_identifier, + export: input_target.export, + connection: input_target.connection.expect("should have connection"), + }; + if target.export.is_none() { + return Some(ResolvedExportInfoTargetWithCircular::Target(target)); + } + if !resolve_filter(&target, mg) { + return Some(ResolvedExportInfoTargetWithCircular::Target(target)); + } + loop { + let name = if let Some(export) = target.export.as_ref().and_then(|exports| exports.first()) + { + export + } else { return Some(ResolvedExportInfoTargetWithCircular::Target(target)); + }; + + let export_info_id = { + let id = mg + .module_graph_module_by_identifier(&target.module) + .expect("should have mgm") + .exports; + id.get_export_info(name, mg) + }; + if already_visited.contains(&export_info_id) { + return Some(ResolvedExportInfoTargetWithCircular::Circular); } - loop { - let name = - if let Some(export) = target.export.as_ref().and_then(|exports| exports.first()) { - export - } else { - return Some(ResolvedExportInfoTargetWithCircular::Target(target)); - }; - - let export_info_id = { - let id = mg - .module_graph_module_by_identifier(&target.module) - .expect("should have mgm") - .exports; - id.get_export_info(name, mg) - }; - if already_visited.contains(&export_info_id) { - return Some(ResolvedExportInfoTargetWithCircular::Circular); - } - let mut export_info = mg.get_export_info_by_id(&export_info_id).clone(); + let mut export_info = mg.get_export_info_by_id(&export_info_id).clone(); + // dbg!(&export_info); - let export_info_id = export_info.id; - let new_target = export_info._get_target(mg, resolve_filter.clone(), already_visited); - _ = std::mem::replace(mg.get_export_info_mut_by_id(&export_info_id), export_info); + let export_info_id = export_info.id; + let new_target = export_info._get_target(mg, resolve_filter.clone(), already_visited); + _ = std::mem::replace(mg.get_export_info_mut_by_id(&export_info_id), export_info); - match new_target { - Some(ResolvedExportInfoTargetWithCircular::Circular) => { - return Some(ResolvedExportInfoTargetWithCircular::Circular); - } - None => return None, - Some(ResolvedExportInfoTargetWithCircular::Target(t)) => { - // SAFETY: if the target.exports is None, program will not reach here - let target_exports = target.export.as_ref().expect("should have exports"); - if target_exports.len() == 1 { - target = t; - if target.export.is_none() { - return Some(ResolvedExportInfoTargetWithCircular::Target(target)); - } + match new_target { + Some(ResolvedExportInfoTargetWithCircular::Circular) => { + return Some(ResolvedExportInfoTargetWithCircular::Circular); + } + None => return Some(ResolvedExportInfoTargetWithCircular::Target(target)), + Some(ResolvedExportInfoTargetWithCircular::Target(t)) => { + // SAFETY: if the target.exports is None, program will not reach here + let target_exports = target.export.as_ref().expect("should have exports"); + if target_exports.len() == 1 { + target = t; + if target.export.is_none() { + return Some(ResolvedExportInfoTargetWithCircular::Target(target)); + } + } else { + target.module = t.module; + target.connection = t.connection; + target.export = if let Some(mut exports) = t.export { + exports.extend_from_slice(&target_exports[1..]); + Some(exports) } else { - target.module = t.module; - target.connection = t.connection; - target.export = if let Some(mut exports) = t.export { - exports.extend_from_slice(&target_exports[1..]); - Some(exports) - } else { - Some(target_exports[1..].to_vec()) - } + Some(target_exports[1..].to_vec()) } } } - if !resolve_filter(&target, mg) { - return Some(ResolvedExportInfoTargetWithCircular::Target(target)); - } - already_visited.insert(export_info_id); } - } else { - None + if !resolve_filter(&target, mg) { + return Some(ResolvedExportInfoTargetWithCircular::Target(target)); + } + already_visited.insert(export_info_id); } + } else { + None } + } + pub fn _get_target( + &mut self, + mg: &mut ModuleGraph, + resolve_filter: ResolveFilterFnTy, + already_visited: &mut HashSet, + ) -> Option { if self.target.is_empty() { return None; } @@ -1149,7 +1115,7 @@ impl ExportInfo { export: item.exports.clone(), }) .collect::>(); - let target = resolve_target( + let target = Self::resolve_target( values.first().cloned(), already_visited, resolve_filter.clone(), @@ -1164,7 +1130,7 @@ impl ExportInfo { Some(ResolvedExportInfoTargetWithCircular::Target(target)) => { for val in values.into_iter().skip(1) { let resolved_target = - resolve_target(Some(val), already_visited, resolve_filter.clone(), mg); + Self::resolve_target(Some(val), already_visited, resolve_filter.clone(), mg); match resolved_target { Some(ResolvedExportInfoTargetWithCircular::Circular) => { return Some(ResolvedExportInfoTargetWithCircular::Circular); @@ -1306,7 +1272,7 @@ pub fn get_dependency_used_by_exports_condition( match used_by_exports { Some(UsedByExports::Set(used_by_exports)) => { let used_by_exports = Arc::new(used_by_exports.clone()); - Some(DependencyCondition::Fn(Box::new( + Some(DependencyCondition::Fn(Arc::new( move |_, runtime, module_graph: &ModuleGraph| { let module_identifier = module_graph .parent_module_by_dependency_id(&dependency_id) @@ -1462,17 +1428,24 @@ pub fn process_export_info( } #[macro_export] -macro_rules! debug_exports_info { +macro_rules! debug_all_exports_info { ($mg:expr) => { for mgm in $mg.module_graph_modules().values() { - dbg!(&mgm.module_identifier); - let exports_info_id = mgm.exports; - let exports_info = $mg.get_exports_info_by_id(&exports_info_id); - dbg!(&exports_info); - for id in exports_info.exports.values() { - let export_info = $mg.get_export_info_by_id(id); - dbg!(&export_info); - } + $crate::debug_exports_info!(mgm, $mg); + } + }; +} + +#[macro_export] +macro_rules! debug_exports_info { + ($mgm:expr, $mg:expr) => { + dbg!(&$mgm.module_identifier); + let exports_info_id = $mgm.exports; + let exports_info = $mg.get_exports_info_by_id(&exports_info_id); + dbg!(&exports_info); + for id in exports_info.exports.values() { + let export_info = $mg.get_export_info_by_id(id); + dbg!(&export_info); } }; } diff --git a/crates/rspack_core/src/module_graph/connection.rs b/crates/rspack_core/src/module_graph/connection.rs index d7637b0fdc1..85f04746c5a 100644 --- a/crates/rspack_core/src/module_graph/connection.rs +++ b/crates/rspack_core/src/module_graph/connection.rs @@ -19,7 +19,7 @@ impl From for ConnectionId { } } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Eq)] pub struct ModuleGraphConnection { /// The referencing module identifier pub original_module_identifier: Option, @@ -33,32 +33,23 @@ pub struct ModuleGraphConnection { conditional: bool, } -/// implementing hash by hand because condition maybe a function, which can't be hash impl Hash for ModuleGraphConnection { fn hash(&self, state: &mut H) { self.original_module_identifier.hash(state); self.module_identifier.hash(state); self.dependency_id.hash(state); - self.active.hash(state); self.conditional.hash(state); } } -/// implementing hash by hand because condition maybe a function, which can't be hash impl PartialEq for ModuleGraphConnection { fn eq(&self, other: &Self) -> bool { self.original_module_identifier == other.original_module_identifier && self.module_identifier == other.module_identifier && self.dependency_id == other.dependency_id - && self.active == other.active && self.conditional == other.conditional } } -/// implementing eq -impl Eq for ModuleGraphConnection { - fn assert_receiver_is_total_eq(&self) {} -} - impl ModuleGraphConnection { pub fn new( original_module_identifier: Option, @@ -124,7 +115,7 @@ impl ModuleGraphConnection { match module_graph .connection_to_condition .get(self) - .expect("should have condition") + .unwrap_or_else(|| panic!("{:#?}", self)) { DependencyCondition::False => ConnectionState::Bool(false), DependencyCondition::Fn(f) => f(self, runtime, module_graph), diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index d6c4c251955..2e1c4c0d82c 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -2,6 +2,7 @@ use std::borrow::Cow; use std::collections::hash_map::Entry; use std::path::PathBuf; +use dashmap::DashMap; use rspack_error::{internal_error, Result}; use rspack_hash::RspackHashDigest; use rspack_identifier::{Identifiable, IdentifierMap}; @@ -13,9 +14,9 @@ mod connection; pub use connection::*; use crate::{ - to_identifier, BoxDependency, BoxModule, BuildDependency, BuildInfo, BuildMeta, - DependencyCondition, DependencyId, ExportInfo, ExportInfoId, ExportsInfo, ExportsInfoId, - ModuleGraphModule, ModuleIdentifier, ModuleProfile, + BoxDependency, BoxModule, BuildDependency, BuildInfo, BuildMeta, DependencyCondition, + DependencyId, ExportInfo, ExportInfoId, ExportsInfo, ExportsInfoId, ModuleGraphModule, + ModuleIdentifier, ModuleProfile, }; // TODO Here request can be used JsWord @@ -29,7 +30,7 @@ pub struct DependencyParents { #[derive(Debug, Default)] pub struct ModuleGraph { - dependency_id_to_module_identifier: HashMap, + pub dependency_id_to_module_identifier: HashMap, /// Module identifier to its module pub module_identifier_to_module: IdentifierMap, @@ -55,7 +56,7 @@ pub struct ModuleGraph { /// Module graph connections table index for `ConnectionId` connections_map: HashMap, - import_var_map: IdentifierMap, + pub import_var_map: DashMap, pub exports_info_map: HashMap, pub export_info_map: HashMap, connection_to_condition: HashMap, @@ -630,6 +631,43 @@ impl ModuleGraph { self.dep_meta_map.get(&id) } + pub fn normalize_new_connection( + mg: &mut ModuleGraph, + mut connection: ModuleGraphConnection, + module_identifier: ModuleIdentifier, + ) -> ModuleGraphConnection { + let old_connection_module_id = connection.module_identifier; + let old_connection_original_module_id = connection.original_module_identifier; + let old_connection_dependency_id = connection.dependency_id; + let new_connection_id = ConnectionId::from(mg.connections.len()); + connection.set_active(true); + connection.module_identifier = module_identifier; + mg.connections.push(Some(connection)); + mg.connections_map.insert(connection, new_connection_id); + + mg.dependency_id_to_module_identifier + .insert(old_connection_dependency_id, module_identifier); + + mg.dependency_id_to_connection_id + .insert(old_connection_dependency_id, new_connection_id); + + mg.connection_id_to_dependency_id + .insert(new_connection_id, old_connection_dependency_id); + + let mgm = mg + .module_graph_module_by_identifier_mut(&old_connection_module_id) + .expect("should have mgm"); + + mgm.add_incoming_connection(new_connection_id); + + if let Some(identifier) = old_connection_original_module_id + && let Some(original_mgm) = mg.module_graph_module_by_identifier_mut(&identifier) + { + original_mgm.add_outgoing_connection(new_connection_id); + }; + connection + } + pub fn update_module(&mut self, dep_id: &DependencyId, module_id: &ModuleIdentifier) { let connection = self .connection_by_dependency_mut(dep_id) @@ -637,76 +675,17 @@ impl ModuleGraph { if &connection.module_identifier == module_id { return; } + let connection_copy = *connection; connection.set_active(false); - let mut new_connection = *connection; - let condition = self.connection_to_condition.get(&new_connection).cloned(); - new_connection.module_identifier = *module_id; - let new_connection = normalize_new_connection(self, new_connection); + let condition = { self.connection_to_condition.get(&connection_copy).cloned() }; + let new_connection = Self::normalize_new_connection(self, connection_copy, *module_id); + // copy condition if let Some(condition) = condition { self .connection_to_condition .insert(new_connection, condition); } - - pub fn normalize_new_connection( - mg: &mut ModuleGraph, - new_connection: ModuleGraphConnection, - ) -> ModuleGraphConnection { - let dependency_id = new_connection.dependency_id; - let connection_id = if let Some(connection_id) = mg.connections_map.get(&new_connection) { - *connection_id - } else { - let new_connection_id = ConnectionId::from(mg.connections.len()); - mg.connections.push(Some(new_connection)); - mg.connections_map.insert(new_connection, new_connection_id); - new_connection_id - }; - - mg.dependency_id_to_connection_id - .insert(dependency_id, connection_id); - - mg.connection_id_to_dependency_id - .insert(connection_id, dependency_id); - - let mgm = mg - .module_graph_module_by_identifier_mut(&new_connection.module_identifier) - .expect("should have mgm"); - - mgm.add_incoming_connection(connection_id); - - if let Some(identifier) = new_connection.original_module_identifier - && let Some(original_mgm) = mg.module_graph_module_by_identifier_mut(&identifier) - { - original_mgm.add_outgoing_connection(connection_id); - }; - new_connection - } - } - - pub fn set_dependency_import_var(&mut self, module_identifier: ModuleIdentifier, request: &str) { - self.import_var_map.entry(module_identifier).or_default(); - if let Some(module_var_map) = self.import_var_map.get_mut(&module_identifier) { - if !module_var_map.contains_key(request) { - module_var_map.insert( - request.to_string(), - format!( - "{}__WEBPACK_IMPORTED_MODULE_{}__", - to_identifier(request), - module_var_map.len() - ), - ); - } - } - } - - pub fn get_import_var(&self, module_identifier: &ModuleIdentifier, request: &str) -> &str { - self - .import_var_map - .get(module_identifier) - .expect("should have module import var") - .get(request) - .unwrap_or_else(|| panic!("should have import var for {module_identifier} {request}")) } pub fn get_exports_info(&self, module_identifier: &ModuleIdentifier) -> &ExportsInfo { diff --git a/crates/rspack_core/src/utils/import_var.rs b/crates/rspack_core/src/utils/import_var.rs new file mode 100644 index 00000000000..062353a2eaa --- /dev/null +++ b/crates/rspack_core/src/utils/import_var.rs @@ -0,0 +1,30 @@ +use std::collections::hash_map::Entry; + +use crate::{to_identifier, DependencyId, ModuleGraph}; + +/// refer to https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/dependencies/HarmonyImportDependency.js#L85-L97 +pub fn get_import_var(mg: &ModuleGraph, dep_id: DependencyId) -> String { + let parent_module_id = mg + .get_parent_module(&dep_id) + .expect("should have parent module"); + let module_id = *mg + .module_identifier_by_dependency_id(&dep_id) + .expect("should have module id"); + let module_dep = mg + .dependency_by_id(&dep_id) + .and_then(|dep| dep.as_module_dependency()) + .expect("should be module dependency"); + let user_request = to_identifier(module_dep.user_request()); + let mut import_var_map_of_module = mg.import_var_map.entry(*parent_module_id).or_default(); + let len = import_var_map_of_module.len(); + + let import_var = match import_var_map_of_module.entry(module_id.to_string()) { + Entry::Occupied(occ) => occ.get().clone(), + Entry::Vacant(vac) => { + let import_var = format!("{}__WEBPACK_IMPORTED_MODULE_{}__", user_request, len); + vac.insert(import_var.clone()); + import_var + } + }; + import_var +} diff --git a/crates/rspack_core/src/utils/mod.rs b/crates/rspack_core/src/utils/mod.rs index 660e6c6c8b7..6a63b933a1e 100644 --- a/crates/rspack_core/src/utils/mod.rs +++ b/crates/rspack_core/src/utils/mod.rs @@ -24,6 +24,9 @@ pub use source::*; mod hash; pub use hash::*; +mod import_var; +pub use import_var::*; + mod module_rules; pub use module_rules::*; diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs index 637f1af29e3..5dc04309359 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_imported_specifier_dependency.rs @@ -1,9 +1,11 @@ +use std::sync::Arc; + use linked_hash_set::LinkedHashSet; use rspack_core::{ create_exports_object_referenced, create_no_exports_referenced, export_from_import, - get_exports_type, process_export_info, AsContextDependency, ConnectionState, Dependency, - DependencyCategory, DependencyCondition, DependencyId, DependencyTemplate, DependencyType, - ExportInfoId, ExportInfoProvided, ExportNameOrSpec, ExportSpec, ExportsInfoId, + get_exports_type, get_import_var, process_export_info, AsContextDependency, ConnectionState, + Dependency, DependencyCategory, DependencyCondition, DependencyId, DependencyTemplate, + DependencyType, ExportInfoId, ExportInfoProvided, ExportNameOrSpec, ExportSpec, ExportsInfoId, ExportsOfExportsSpec, ExportsSpec, ExportsType, ExtendedReferencedExport, HarmonyExportInitFragment, ModuleDependency, ModuleGraph, ModuleIdentifier, RuntimeSpec, TemplateContext, TemplateReplaceSource, UsageState, UsedName, @@ -30,7 +32,7 @@ pub struct HarmonyExportImportedSpecifierDependency { // Because it is shared by multiply HarmonyExportImportedSpecifierDependency, so put it to `BuildInfo` // pub active_exports: HashSet, // pub all_star_exports: Option>, - pub other_star_exports: Option>, // look like it is unused + pub other_star_exports: Option>, pub export_all: bool, } @@ -472,9 +474,7 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { .module_graph_module_by_identifier(&module.identifier()) .expect("should have module graph module"); - let import_var = compilation - .module_graph - .get_import_var(&module.identifier(), &self.request); + let import_var = get_import_var(&compilation.module_graph, self.id); let is_new_tree_shaking = compilation.options.is_new_tree_shaking(); let used_exports = if is_new_tree_shaking { @@ -528,7 +528,7 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { JsWord::from(export_from_import( code_generatable_context, true, - import_var, + &import_var, id.1.clone().map(|i| vec![i]).unwrap_or_default(), &self.id, false, @@ -765,7 +765,7 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { fn get_condition(&self) -> Option { let id = self.id; - Some(DependencyCondition::Fn(Box::new( + Some(DependencyCondition::Fn(Arc::new( move |_mc, runtime, module_graph: &ModuleGraph| { let dep = module_graph .dependency_by_id(&id) diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs index 821fa3550a6..7b408d8db8b 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs @@ -1,11 +1,13 @@ +use std::sync::Arc; + use rspack_core::tree_shaking::symbol::{self, IndirectTopLevelSymbol}; use rspack_core::tree_shaking::visitor::SymbolRef; use rspack_core::{ - import_statement, AsContextDependency, AwaitDependenciesInitFragment, ConnectionState, - Dependency, DependencyCategory, DependencyCondition, DependencyId, DependencyTemplate, - DependencyType, ErrorSpan, ExtendedReferencedExport, InitFragmentExt, InitFragmentKey, - InitFragmentStage, ModuleDependency, ModuleIdentifier, NormalInitFragment, RuntimeGlobals, - TemplateContext, TemplateReplaceSource, + get_import_var, import_statement, AsContextDependency, AwaitDependenciesInitFragment, + ConnectionState, Dependency, DependencyCategory, DependencyCondition, DependencyId, + DependencyTemplate, DependencyType, ErrorSpan, ExtendedReferencedExport, InitFragmentExt, + InitFragmentKey, InitFragmentStage, ModuleDependency, ModuleIdentifier, NormalInitFragment, + RuntimeGlobals, TemplateContext, TemplateReplaceSource, }; use rspack_core::{ModuleGraph, RuntimeSpec}; use rustc_hash::FxHashSet as HashSet; @@ -174,10 +176,11 @@ pub fn harmony_import_dependency_apply( .module_graph .module_identifier_by_dependency_id(module_dependency.id()) .expect("should have dependency referenced module"); - let import_var = compilation - .module_graph - .get_import_var(&module.identifier(), module_dependency.request()); - let key = module_dependency.request(); + let import_var = get_import_var(&compilation.module_graph, *module_dependency.id()); + // + // https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/dependencies/HarmonyImportDependency.js#L282-L285 + let module_key = ref_module; + let key = format!("harmony import {}", module_key); let is_async_module = matches!(compilation.module_graph.is_async(ref_module), Some(true)); if is_async_module { init_fragments.push(Box::new(NormalInitFragment::new( @@ -298,7 +301,7 @@ impl ModuleDependency for HarmonyImportSideEffectDependency { // TODO: It's from HarmonyImportSideEffectDependency. fn get_condition(&self) -> Option { - Some(DependencyCondition::Fn(Box::new( + Some(DependencyCondition::Fn(Arc::new( move |con, _, module_graph: &ModuleGraph| { let id = con.module_identifier; if let Some(module) = module_graph.module_by_identifier(&id) { diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs index 7622513d221..8ba21937a39 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_specifier_dependency.rs @@ -1,3 +1,4 @@ +use rspack_core::get_import_var; use rspack_core::{ create_exports_object_referenced, create_no_exports_referenced, export_from_import, get_dependency_used_by_exports_condition, get_exports_type, @@ -138,8 +139,8 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { .module_graph_module_by_dependency_id(&self.id) .expect("should have ref module"); - let compilation = &code_generatable_context.compilation; - if compilation.options.is_new_tree_shaking() { + let is_new_tree_shaking = compilation.options.is_new_tree_shaking(); + if is_new_tree_shaking { let connection = compilation.module_graph.connection_by_dependency(&self.id); let is_target_active = if let Some(con) = connection { // TODO: runtime opt @@ -165,13 +166,14 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { return; } - let import_var = code_generatable_context - .compilation + let ids = self.get_ids(&compilation.module_graph); + compilation .module_graph - .get_import_var(&code_generatable_context.module.identifier(), &self.request); + .module_identifier_by_dependency_id(&self.id); + let import_var = get_import_var(&compilation.module_graph, self.id); // TODO: scope hoist - if compilation.options.is_new_tree_shaking() { + if is_new_tree_shaking { harmony_import_dependency_apply( self, self.source_order, @@ -182,12 +184,13 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { let export_expr = export_from_import( code_generatable_context, true, - import_var, - self.ids.clone(), + &import_var, + ids, &self.id, self.call, !self.direct_import, ); + // dbg!(&export_expr); if self.shorthand { source.insert(self.end, format!(": {export_expr}").as_str(), None); } else { @@ -206,6 +209,7 @@ impl Dependency for HarmonyImportSpecifierDependency { end: self.end, }) } + fn span_for_on_usage_search(&self) -> Option { Some(self.span_for_on_usage_search.into()) } @@ -264,6 +268,7 @@ impl ModuleDependency for HarmonyImportSpecifierDependency { // self.used_by_exports.as_ref() // ); let ret = get_dependency_used_by_exports_condition(self.id, self.used_by_exports.as_ref()); + // dbg!(&ret); ret } diff --git a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs index 157d84a83cc..97efa659088 100644 --- a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs @@ -387,6 +387,10 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { UsageState::Used, runtime.as_ref(), ); + // dbg!( + // &export_info_id.get_export_info(&self.compilation.module_graph), + // changed_flag + // ); if changed_flag { let current_module = if current_exports_info_id == mgm_exports_info_id { Some(module_id) diff --git a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs index 7b9f0ef0124..30068080e8e 100644 --- a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs @@ -423,9 +423,8 @@ impl Plugin for SideEffectsFlagPlugin { .collect::>(); for module_identifier in module_id_list { let mut module_chain = HashSet::default(); - let module = match mg.module_by_identifier(&module_identifier) { - Some(module) => module, - None => continue, + let Some(module) = mg.module_by_identifier(&module_identifier) else { + continue; }; let side_effects_state = module.get_side_effects_connection_state(mg, &mut module_chain); if side_effects_state != rspack_core::ConnectionState::Bool(false) { @@ -435,21 +434,17 @@ impl Plugin for SideEffectsFlagPlugin { let incoming_connections = mg.get_incoming_connections_cloned(module); for con in incoming_connections { - let dep = match mg.dependency_by_id(&con.dependency_id) { - Some(dep) => dep, - None => continue, + let Some(dep) = mg.dependency_by_id(&con.dependency_id) else { + continue; }; let dep_id = *dep.id(); let is_reexport = dep .downcast_ref::() .is_some(); - let is_valid_import_specifier_dep = if let Some(import_specifier_dep) = - dep.downcast_ref::() - { - !import_specifier_dep.namespace_object_as_context - } else { - false - }; + let is_valid_import_specifier_dep = dep + .downcast_ref::() + .map(|import_specifier_dep| !import_specifier_dep.namespace_object_as_context) + .unwrap_or_default(); if !is_reexport && !is_valid_import_specifier_dep { continue; } @@ -471,7 +466,7 @@ impl Plugin for SideEffectsFlagPlugin { .get_side_effects_connection_state(mg, &mut HashSet::default()) == ConnectionState::Bool(false) }), - Box::new( + Arc::new( move |target: &ResolvedExportInfoTarget, mg: &mut ModuleGraph| { mg.update_module(&dep_id, &target.module); // TODO: Explain https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/optimize/SideEffectsFlagPlugin.js#L303-L306 @@ -494,6 +489,7 @@ impl Plugin for SideEffectsFlagPlugin { } let ids = dep_id.get_ids(mg); + if !ids.is_empty() { let export_info_id = cur_exports_info_id.get_export_info(&ids[0], mg); @@ -508,10 +504,11 @@ impl Plugin for SideEffectsFlagPlugin { }, )), ); - let target = match target { - Some(target) => target, - None => continue, + let Some(target) = target else { + continue; }; + + // dbg!(&mg.connection_by_dependency(&dep_id)); mg.update_module(&dep_id, &target.module); // TODO: Explain https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/optimize/SideEffectsFlagPlugin.js#L303-L306 let processed_ids = target @@ -521,6 +518,8 @@ impl Plugin for SideEffectsFlagPlugin { item }) .unwrap_or_else(|| ids[1..].to_vec()); + + // dbg!(&mg.connection_by_dependency(&dep_id)); dep_id.set_ids(processed_ids, mg); } } diff --git a/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap b/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap index c3dc5407b17..25e39155e66 100644 --- a/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap +++ b/packages/rspack/tests/__snapshots__/StatsTestCases.test.ts.snap @@ -190,7 +190,7 @@ import rawModule from './raw.png'; "errors": [], "errorsCount": 0, "filteredModules": undefined, - "hash": "fbfdd615b948d480bcd1", + "hash": "e39918359c4433621683", "logging": {}, "modules": [ { @@ -380,7 +380,7 @@ chunk {main} bundle.js (main) [entry] esm import ./stringModule [10] webpack/runtime/public_path {main} webpack/runtime/make_namespace_object {main} -Rspack compiled successfully (fbfdd615b948d480bcd1)" +Rspack compiled successfully (e39918359c4433621683)" `; exports[`StatsTestCases should print correct stats for filename 1`] = ` @@ -6119,7 +6119,7 @@ import rawModule from './raw.png'; "errors": [], "errorsCount": 0, "filteredModules": undefined, - "hash": "272d9a92b8ecd819a332", + "hash": "22f9734c6c6aa6e0afd5", "logging": {}, "modules": [ { @@ -6325,7 +6325,7 @@ runtime modules 4 modules ./raw.png ./index.js ./stringModule.js -Rspack compiled successfully (272d9a92b8ecd819a332)" +Rspack compiled successfully (22f9734c6c6aa6e0afd5)" `; exports[`StatsTestCases should print correct stats for stats-hooks 1`] = `