diff --git a/Cargo.lock b/Cargo.lock index ee8131aaa6a..6fc138d6df0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2330,6 +2330,7 @@ dependencies = [ "rspack_binding_options", "rspack_core", "rspack_fs", + "rspack_plugin_javascript", "rspack_testing", "rspack_tracing", "serde", diff --git a/crates/rspack/Cargo.toml b/crates/rspack/Cargo.toml index 2e4790b2980..b3ee6d46af7 100644 --- a/crates/rspack/Cargo.toml +++ b/crates/rspack/Cargo.toml @@ -15,9 +15,10 @@ rspack_fs = { path = "../rspack_fs", features = ["async", "rspack-error"] } tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros"] } [dev-dependencies] -rspack_binding_options = { path = "../rspack_binding_options" } -rspack_testing = { path = "../rspack_testing" } -rspack_tracing = { path = "../rspack_tracing" } +rspack_binding_options = { path = "../rspack_binding_options" } +rspack_plugin_javascript = { path = "../rspack_plugin_javascript" } +rspack_testing = { path = "../rspack_testing" } +rspack_tracing = { path = "../rspack_tracing" } cargo-rst = { path = "../cargo-rst" } diff --git a/crates/rspack/tests/fixtures.rs b/crates/rspack/tests/fixtures.rs index 2fd1b57fecd..17fe026b90f 100644 --- a/crates/rspack/tests/fixtures.rs +++ b/crates/rspack/tests/fixtures.rs @@ -1,8 +1,8 @@ use std::path::PathBuf; use cargo_rst::git_diff; -use insta::Settings; -use rspack_core::{CompilerOptions, TreeShaking, UsedExportsOption}; +use rspack_core::{BoxPlugin, CompilerOptions, TreeShaking, UsedExportsOption}; +use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsagePlugin}; use rspack_testing::test_fixture; use testing_macros::fixture; @@ -28,12 +28,17 @@ fn tree_shaking(fixture_path: PathBuf) { // second test is webpack based tree shaking test_fixture( &fixture_path, - Box::new(|_: &mut Settings, options: &mut CompilerOptions| { - options.experiments.rspack_future.new_treeshaking = true; - options.optimization.provided_exports = true; - options.optimization.used_exports = UsedExportsOption::True; - options.builtins.tree_shaking = TreeShaking::False; - }), + Box::new( + |plugins: &mut Vec, options: &mut CompilerOptions| { + options.experiments.rspack_future.new_treeshaking = true; + options.optimization.provided_exports = true; + options.optimization.used_exports = UsedExportsOption::True; + options.builtins.tree_shaking = TreeShaking::False; + + plugins.push(Box::::default()); + plugins.push(Box::::default()); + }, + ), Some("new_treeshaking".to_string()), ); @@ -45,5 +50,11 @@ fn tree_shaking(fixture_path: PathBuf) { let new_treeshaking_snapshot = std::fs::read_to_string(new_treeshaking_snapshot_path).expect("should have snapshot"); let diff = git_diff(&old_snapshot, &new_treeshaking_snapshot); - std::fs::write(fixture_path.join("snapshot/snap.diff"), diff).expect("should write successfully"); + let diff_path = fixture_path.join("snapshot/snap.diff"); + if diff_path.exists() { + std::fs::remove_file(diff_path.clone()).expect("remove file failed"); + } + if !diff.is_empty() { + std::fs::write(diff_path, diff).expect("should write successfully"); + } } 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 4960045bc01..8fda05d7224 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 @@ -26,9 +26,7 @@ __webpack_require__.r(__webpack_exports__); 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'secret': function() { return secret; }, - 'result': function() { return result; }, - 'something': function() { return something; } + 'result': function() { return result; } }); const secret = "888"; const result = 20000; diff --git a/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/snap.diff index f7e607a59fa..918d130d977 100644 --- a/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/snap.diff @@ -8,14 +8,3 @@ /* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./src/a */"./src/a.js"); -@@ -25,7 +26,9 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'result': function() { return result; } -+ 'secret': function() { return secret; }, -+ 'result': function() { return result; }, -+ 'something': function() { return something; } - }); - const secret = "888"; - const result = 20000; diff --git a/crates/rspack/tests/tree-shaking/assign-with-side-effects/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/assign-with-side-effects/snapshot/new_treeshaking.snap index 42b56d14f25..407bc677e6e 100644 --- a/crates/rspack/tests/tree-shaking/assign-with-side-effects/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/assign-with-side-effects/snapshot/new_treeshaking.snap @@ -25,9 +25,7 @@ __webpack_require__.r(__webpack_exports__); 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'secret': function() { return secret; }, - 'result': function() { return result; }, - 'something': function() { return something; } + 'result': function() { return result; } }); const secret = "888"; const result = 20000; diff --git a/crates/rspack/tests/tree-shaking/assign-with-side-effects/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/assign-with-side-effects/snapshot/snap.diff deleted file mode 100644 index 8a46f5915e3..00000000000 --- a/crates/rspack/tests/tree-shaking/assign-with-side-effects/snapshot/snap.diff +++ /dev/null @@ -1,13 +0,0 @@ ---- expected -+++ actual -@@ -25,7 +25,9 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'result': function() { return result; } -+ 'secret': function() { return secret; }, -+ 'result': function() { return result; }, -+ 'something': function() { return something; } - }); - const secret = "888"; - const result = 20000; 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 d6a481436ee..5525f1dd5d2 100644 --- a/crates/rspack/tests/tree-shaking/basic/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/basic/snapshot/new_treeshaking.snap @@ -14,9 +14,6 @@ __webpack_require__.d(__webpack_exports__, { "./app.js": function (module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'render': function() { return render; } -}); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); setTimeout(()=>{ @@ -43,8 +40,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'secret': function() { return secret; }, - 'myanswer': function() { return myanswer; }, - 'result': function() { return result; } + 'myanswer': function() { return myanswer; } }); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); diff --git a/crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff index 3fc854ea8b6..88332af7f14 100644 --- a/crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff @@ -1,16 +1,6 @@ --- expected +++ actual -@@ -14,6 +14,9 @@ - "./app.js": function (module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'render': function() { return render; } -+}); - /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); - - setTimeout(()=>{ -@@ -22,7 +25,7 @@ +@@ -22,7 +22,7 @@ function render() { function test() { const container = document.getElementById("root"); @@ -19,14 +9,11 @@ } } if (module.hot?.accept) module.hot.accept((module1)=>{ -@@ -39,7 +42,9 @@ +@@ -39,6 +39,7 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { -- 'myanswer': function() { return myanswer; } + 'secret': function() { return secret; }, -+ 'myanswer': function() { return myanswer; }, -+ 'result': function() { return result; } + 'myanswer': function() { return myanswer; } }); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); - 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 5b6ef1c022f..ecb69e8169c 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -7,7 +7,6 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; }, 'c': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.c; } }); /* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); @@ -23,8 +22,7 @@ _b_js__WEBPACK_IMPORTED_MODULE_0_.d; 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'd': function() { return d; }, - 'c': function() { return c; } + 'd': function() { return d; } }); const d = 3; const c = 100; @@ -32,9 +30,6 @@ __webpack_require__.d(__webpack_exports__, { "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'ccc': function() { return ccc; } -}); const ccc = 30; }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index 3313e54f6ba..59fa831735a 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -1,23 +1,22 @@ --- expected +++ actual -@@ -6,6 +6,10 @@ +@@ -6,6 +6,9 @@ "./a.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; }, + 'c': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.c; } +}); /* 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__); -@@ -19,7 +23,8 @@ +@@ -27,9 +30,6 @@ + "./c.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; } -+ 'd': function() { return d; }, -+ 'c': function() { return c; } - }); - const d = 3; - const c = 100; +-__webpack_require__.d(__webpack_exports__, { +- 'ccc': function() { return ccc; } +-}); + const ccc = 30; + }, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/new_treeshaking.snap index 8e9d6100605..d5ebf30e9ee 100644 --- a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/new_treeshaking.snap @@ -28,9 +28,6 @@ const locales = { "./index.ts": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'test': function() { return test; } -}); /* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./antd/index */"./antd/index.ts"); _antd_index__WEBPACK_IMPORTED_MODULE_0_.locales.zh_CN; diff --git a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/snap.diff index e69de29bb2d..184e438e452 100644 --- a/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/cjs-export-computed-property/snapshot/snap.diff @@ -0,0 +1,12 @@ +--- expected ++++ actual +@@ -28,9 +28,6 @@ + "./index.ts": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'test': function() { return test; } +-}); + /* harmony import */var _antd_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./antd/index */"./antd/index.ts"); + + _antd_index__WEBPACK_IMPORTED_MODULE_0_.locales.zh_CN; 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 278cdf83ba1..640365ce899 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 @@ -6,17 +6,11 @@ source: crates/rspack_testing/src/run_fixture.rs "./a/aaa.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'aaa': function() { return aaa; } -}); function aaa() {} }, "./a/bbb.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'bbb': function() { return bbb; } -}); function bbb() {} }, "./a/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { @@ -59,9 +53,6 @@ __webpack_require__(/* ./answer */"./answer.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; } -}); const myanswer = 'anyser'; }, 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 index 751f6626574..8037312974b 100644 --- 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 @@ -1,23 +1,17 @@ --- expected +++ actual -@@ -3,12 +3,39 @@ +@@ -3,12 +3,33 @@ --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"./a/aaa.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'aaa': function() { return aaa; } -+}); + function aaa() {} +}, +"./a/bbb.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'bbb': function() { return bbb; } -+}); + function bbb() {} +}, +"./a/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { @@ -40,3 +34,13 @@ const answer = 42; }, +@@ -32,9 +53,6 @@ + "./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; } +-}); + const myanswer = 'anyser'; + }, + diff --git a/crates/rspack/tests/tree-shaking/class-extend/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/class-extend/snapshot/new_treeshaking.snap index e786cd5e20f..af784057aa7 100644 --- a/crates/rspack/tests/tree-shaking/class-extend/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/class-extend/snapshot/new_treeshaking.snap @@ -7,7 +7,6 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'Lib': function() { return Lib; }, 'v': function() { return v; } }); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); diff --git a/crates/rspack/tests/tree-shaking/class-extend/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/class-extend/snapshot/snap.diff index 9ca6a7d6c1e..1665d4d4074 100644 --- a/crates/rspack/tests/tree-shaking/class-extend/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/class-extend/snapshot/snap.diff @@ -1,11 +1,6 @@ --- expected +++ actual -@@ -7,15 +7,16 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'Lib': function() { return Lib; }, - 'v': function() { return v; } +@@ -11,11 +11,11 @@ }); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); @@ -19,7 +14,7 @@ }; } const v = _lib__WEBPACK_IMPORTED_MODULE_0_.value; -@@ -31,6 +32,7 @@ +@@ -31,6 +31,7 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { diff --git a/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/new_treeshaking.snap index 7b4ab051768..46f2a271fc8 100644 --- a/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/new_treeshaking.snap @@ -6,18 +6,11 @@ source: crates/rspack_testing/src/run_fixture.rs "./bar.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; } -}); const a = 'bar'; }, "./foo.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; }, - 'b': function() { return b; } -}); const a = 'foo'; const b = 'foo'; }, diff --git a/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/snap.diff deleted file mode 100644 index 3db9d29dcc5..00000000000 --- a/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/snap.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- expected -+++ actual -@@ -6,11 +6,18 @@ - "./bar.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; } -+}); - const a = 'bar'; - }, - "./foo.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; }, -+ 'b': function() { return b; } -+}); - const a = 'foo'; - const b = 'foo'; - }, diff --git a/crates/rspack/tests/tree-shaking/context-module/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/context-module/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 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 ac1ed03cd8c..8de2c371ee3 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 @@ -48,10 +48,6 @@ _containers__WEBPACK_IMPORTED_MODULE_0_.usePlatform; "./src/containers/platform-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'usePlatform': function() { return usePlatform; }, - 'PlatformProvider': function() { return PlatformProvider; } -}); const usePlatform = 3; const PlatformProvider = 1000; }, 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 index 569e8aef214..f861150f333 100644 --- 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 @@ -9,7 +9,7 @@ }, -@@ -36,6 +38,13 @@ +@@ -36,13 +38,16 @@ }, @@ -23,3 +23,10 @@ "./src/containers/platform-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'usePlatform': function() { return usePlatform; }, +- 'PlatformProvider': function() { return PlatformProvider; } +-}); + const usePlatform = 3; + const PlatformProvider = 1000; + }, diff --git a/crates/rspack/tests/tree-shaking/default_export/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/default_export/snapshot/new_treeshaking.snap index 3f176a5aa51..cd892fcd8fb 100644 --- a/crates/rspack/tests/tree-shaking/default_export/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/default_export/snapshot/new_treeshaking.snap @@ -40,8 +40,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'secret': function() { return secret; }, - 'myanswer': function() { return myanswer; }, - 'result': function() { return result; } + 'myanswer': function() { return myanswer; } }); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); diff --git a/crates/rspack/tests/tree-shaking/default_export/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/default_export/snapshot/snap.diff deleted file mode 100644 index b0889e8e100..00000000000 --- a/crates/rspack/tests/tree-shaking/default_export/snapshot/snap.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- expected -+++ actual -@@ -40,7 +40,8 @@ - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { - 'secret': function() { return secret; }, -- 'myanswer': function() { return myanswer; } -+ 'myanswer': function() { return myanswer; }, -+ 'result': function() { return result; } - }); - /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); - diff --git a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/new_treeshaking.snap index 43be2494847..51599a002db 100644 --- a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/new_treeshaking.snap @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./bar.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; } -}); const a = 'bar'; }, "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/snap.diff deleted file mode 100644 index 53d58d7cb6d..00000000000 --- a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/snap.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- expected -+++ actual -@@ -6,6 +6,9 @@ - "./bar.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; } -+}); - const a = 'bar'; - }, - "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/new_treeshaking.snap index 151f15ff237..64528fd1cec 100644 --- a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/new_treeshaking.snap @@ -6,17 +6,11 @@ source: crates/rspack_testing/src/run_fixture.rs "./bar.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; } -}); const a = 'bar'; }, "./baz.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; } -}); const a = 'baz'; }, "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/snap.diff index b6a30f1ffa9..074fc1f59ba 100644 --- a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/snap.diff @@ -1,12 +1,12 @@ --- expected +++ actual -@@ -6,6 +6,9 @@ - "./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -11,9 +11,6 @@ + "./baz.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; } -+}); - const a = 'bar'; +-__webpack_require__.d(__webpack_exports__, { +- 'a': function() { return a; } +-}); + const a = 'baz'; }, - "./baz.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/export-all-from-side-effects-free-commonjs/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export-all-from-side-effects-free-commonjs/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 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 ca39bfc0ae4..1c21692936c 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 @@ -21,7 +21,6 @@ _answer__WEBPACK_IMPORTED_MODULE_0_.filter; 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; }, 'filter': function() { return _test_js__WEBPACK_IMPORTED_MODULE_0_; } }); /* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./test.js */"./test.js"); @@ -32,9 +31,6 @@ __webpack_require__.d(__webpack_exports__, { "./test.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'result': function() { return result; } -}); const result = ""; }, 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 index 52be774a067..2fcb66d19f9 100644 --- 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 @@ -1,10 +1,12 @@ --- expected +++ actual -@@ -21,6 +21,7 @@ +@@ -31,9 +31,6 @@ + "./test.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; }, - 'filter': function() { return _test_js__WEBPACK_IMPORTED_MODULE_0_; } - }); - /* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./test.js */"./test.js"); +-__webpack_require__.d(__webpack_exports__, { +- 'result': function() { return result; } +-}); + const result = ""; + }, + diff --git a/crates/rspack/tests/tree-shaking/export-named-decl-as/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/export-named-decl-as/snapshot/new_treeshaking.snap index cd333f42285..0810f183395 100644 --- a/crates/rspack/tests/tree-shaking/export-named-decl-as/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/export-named-decl-as/snapshot/new_treeshaking.snap @@ -23,9 +23,6 @@ console.log(_answer__WEBPACK_IMPORTED_MODULE_0_); "./src/plugin/formatNumber.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return formatNumber_default; } -}); function formatNumber(config) {} const plugin = (cls)=>{ cls.prototype.formatNumber = formatNumber; diff --git a/crates/rspack/tests/tree-shaking/export-named-decl-as/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export-named-decl-as/snapshot/snap.diff index e69de29bb2d..932aea79560 100644 --- a/crates/rspack/tests/tree-shaking/export-named-decl-as/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/export-named-decl-as/snapshot/snap.diff @@ -0,0 +1,12 @@ +--- expected ++++ actual +@@ -23,9 +23,6 @@ + "./src/plugin/formatNumber.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return formatNumber_default; } +-}); + function formatNumber(config) {} + const plugin = (cls)=>{ + cls.prototype.formatNumber = formatNumber; 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 67d5cb05623..482cef67e5e 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 @@ -16,25 +16,16 @@ __webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'cccc': function() { return cccc; } -}); function cccc() {} }, "./colors/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'red': function() { return red; } -}); const red = 'red'; }, "./colors/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'blue': function() { return blue; } -}); const blue = 'blue'; }, "./colors/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { @@ -60,9 +51,6 @@ __webpack_require__.es(_c__WEBPACK_IMPORTED_MODULE_2_, __webpack_exports__); "./colors/result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'result': function() { return result; } -}); const result = 'ssss'; }, "./export.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { @@ -83,9 +71,6 @@ _export__WEBPACK_IMPORTED_MODULE_0_.Something; "./something/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; } -}); class Something { } }, 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 index ba1a64aa177..d1c07230056 100644 --- a/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/snap.diff @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -8,9 +8,19 @@ +@@ -8,23 +8,24 @@ __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__); @@ -12,11 +12,42 @@ +"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'cccc': function() { return cccc; } -+}); + function cccc() {} +}, "./colors/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'red': function() { return red; } +-}); + const red = 'red'; + }, + "./colors/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'blue': function() { return blue; } +-}); + const blue = 'blue'; + }, + "./colors/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -50,9 +51,6 @@ + "./colors/result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'result': function() { return result; } +-}); + const result = 'ssss'; + }, + "./export.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -73,9 +71,6 @@ + "./something/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; } +-}); + class Something { + } + }, diff --git a/crates/rspack/tests/tree-shaking/export_star/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/export_star/snapshot/new_treeshaking.snap index 5fd3110e09a..99613de3738 100644 --- a/crates/rspack/tests/tree-shaking/export_star/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/export_star/snapshot/new_treeshaking.snap @@ -7,8 +7,7 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'bar': function() { return _foo__WEBPACK_IMPORTED_MODULE_0_; }, - 'b': function() { return b; } + 'bar': function() { return _foo__WEBPACK_IMPORTED_MODULE_0_; } }); /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); @@ -20,10 +19,6 @@ __webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__) "./foo.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; }, - 'foo': function() { return foo; } -}); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); @@ -44,9 +39,6 @@ _foo__WEBPACK_IMPORTED_MODULE_0_.bar.a; "./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'c': function() { return c; } -}); /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); diff --git a/crates/rspack/tests/tree-shaking/export_star/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export_star/snapshot/snap.diff index c6fbbbb0892..45d4a1ce593 100644 --- a/crates/rspack/tests/tree-shaking/export_star/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/export_star/snapshot/snap.diff @@ -1,22 +1,22 @@ --- expected +++ actual -@@ -7,7 +7,8 @@ +@@ -19,9 +19,6 @@ + "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'bar': function() { return _foo__WEBPACK_IMPORTED_MODULE_0_; } -+ 'bar': function() { return _foo__WEBPACK_IMPORTED_MODULE_0_; }, -+ 'b': function() { return b; } - }); - /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); - /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); -@@ -20,7 +21,8 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +-__webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; } -+ 'a': function() { return a; }, -+ 'foo': function() { return foo; } - }); +-}); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); +@@ -42,9 +39,6 @@ + "./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'c': function() { return c; } +-}); + /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); + __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); diff --git a/crates/rspack/tests/tree-shaking/export_star2/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/export_star2/snapshot/new_treeshaking.snap index 96b153177e4..6c118c52652 100644 --- a/crates/rspack/tests/tree-shaking/export_star2/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/export_star2/snapshot/new_treeshaking.snap @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./bar.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; } -}); /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); @@ -20,9 +17,6 @@ __webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__) "./foo.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; } -}); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); @@ -47,9 +41,6 @@ __webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_2_, __webpack_exports__) "./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'c': function() { return c; } -}); /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); diff --git a/crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff deleted file mode 100644 index d7ca199ffb3..00000000000 --- a/crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff +++ /dev/null @@ -1,32 +0,0 @@ ---- expected -+++ actual -@@ -6,6 +6,9 @@ - "./bar.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; } -+}); - /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); - __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); -@@ -17,6 +20,9 @@ - "./foo.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; } -+}); - /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); - __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - /* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); -@@ -41,6 +47,9 @@ - "./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'c': function() { return c; } -+}); - /* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); - __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); diff --git a/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/new_treeshaking.snap index d6d41d93874..312f1ee2784 100644 --- a/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/new_treeshaking.snap @@ -20,10 +20,6 @@ __webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports "./foo.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; }, - 'b': function() { return b; } -}); /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar.js */"./bar.js"); __webpack_require__.es(_bar_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); /* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result.js */"./result.js"); @@ -43,10 +39,6 @@ __webpack_require__.r(__webpack_exports__); "./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'c': function() { return c; }, - 'b': function() { return b; } -}); /* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo.js */"./foo.js"); __webpack_require__.es(_foo_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar.js */"./bar.js"); diff --git a/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/snap.diff deleted file mode 100644 index 6c18e49db31..00000000000 --- a/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/snap.diff +++ /dev/null @@ -1,24 +0,0 @@ ---- expected -+++ actual -@@ -20,6 +20,10 @@ - "./foo.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; }, -+ 'b': function() { return b; } -+}); - /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar.js */"./bar.js"); - __webpack_require__.es(_bar_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - /* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result.js */"./result.js"); -@@ -39,6 +43,10 @@ - "./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'c': function() { return c; }, -+ 'b': function() { return b; } -+}); - /* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo.js */"./foo.js"); - __webpack_require__.es(_foo_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar.js */"./bar.js"); diff --git a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/new_treeshaking.snap index 22e845132f5..96e8895fe2f 100644 --- a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/new_treeshaking.snap @@ -43,10 +43,6 @@ module.exports = result; "../../../../../node_modules/@swc/helpers/esm/_class_call_check.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - '_class_call_check': function() { return _class_call_check; }, - '_': function() { return _class_call_check; } -}); function _class_call_check(instance, Constructor) { if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); } @@ -55,10 +51,6 @@ __webpack_require__.d(__webpack_exports__, { "../../../../../node_modules/@swc/helpers/esm/_create_class.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - '_create_class': function() { return _create_class; }, - '_': function() { return _create_class; } -}); function _defineProperties(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; diff --git a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/snap.diff index bbb9b95f4c7..c76e4471032 100644 --- a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/snap.diff @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -6,9 +6,75 @@ +@@ -6,9 +6,67 @@ "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -41,10 +41,6 @@ +"../../../../../node_modules/@swc/helpers/esm/_class_call_check.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ '_class_call_check': function() { return _class_call_check; }, -+ '_': function() { return _class_call_check; } -+}); + function _class_call_check(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); +} @@ -53,10 +49,6 @@ +"../../../../../node_modules/@swc/helpers/esm/_create_class.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ '_create_class': function() { return _create_class; }, -+ '_': function() { return _create_class; } -+}); +function _defineProperties(target, props) { + for(var i = 0; i < props.length; i++){ + var descriptor = props[i]; diff --git a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-required/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/rspack/tests/tree-shaking/import-as-default/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/import-as-default/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 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 deleted file mode 100644 index e69de29bb2d..00000000000 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 f6e653b7e11..d456ee9b668 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 @@ -23,9 +23,6 @@ _app__WEBPACK_IMPORTED_MODULE_0_.app; "./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; } -}); const a = 20000; }, 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 index e69de29bb2d..778e4801e50 100644 --- 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 @@ -0,0 +1,12 @@ +--- expected ++++ actual +@@ -23,9 +23,6 @@ + "./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; } +-}); + const a = 20000; + }, + 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 dafbc5f05fa..2adaf1e2869 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 @@ -6,17 +6,11 @@ source: crates/rspack_testing/src/run_fixture.rs "./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__, { - 'default': function() { return Something; } -}); class Something { } }, @@ -43,9 +37,6 @@ __webpack_require__.r(__webpack_exports__); "./layout_export.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); /* harmony import */var _Layout_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout.js */"./Layout.js"); /* harmony import */var _Something_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something.js */"./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 index eb20630bb66..13169ed56cd 100644 --- 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 @@ -1,21 +1,24 @@ --- expected +++ actual -@@ -3,6 +3,14 @@ +@@ -3,12 +3,14 @@ --- ```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__); -@@ -16,8 +24,10 @@ +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return Something; } +-}); + class Something { + } + }, +@@ -16,8 +18,10 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -26,16 +29,13 @@ /* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); -@@ -30,6 +40,19 @@ +@@ -30,6 +34,16 @@ (0, _export__WEBPACK_IMPORTED_MODULE_0_.Sider)(); }, +"./layout_export.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -+}); +/* harmony import */var _Layout_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout.js */"./Layout.js"); +/* harmony import */var _Something_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something.js */"./Something.js"); + diff --git a/crates/rspack/tests/tree-shaking/inherit_export_map_should_lookup_in_dfs_order/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/inherit_export_map_should_lookup_in_dfs_order/snapshot/new_treeshaking.snap index 0d76bd78548..a85308807b4 100644 --- a/crates/rspack/tests/tree-shaking/inherit_export_map_should_lookup_in_dfs_order/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/inherit_export_map_should_lookup_in_dfs_order/snapshot/new_treeshaking.snap @@ -6,18 +6,11 @@ source: crates/rspack_testing/src/run_fixture.rs "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'c': function() { return c; } -}); const c = 'a'; }, "./bar.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; }, - 'c': function() { return c; } -}); const a = 'bar'; const c = 'bar'; }, @@ -38,10 +31,6 @@ __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); "./foo.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; }, - 'b': function() { return b; } -}); /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); __webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); diff --git a/crates/rspack/tests/tree-shaking/inherit_export_map_should_lookup_in_dfs_order/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/inherit_export_map_should_lookup_in_dfs_order/snapshot/snap.diff index bd4a509ef22..b10a0a5deb4 100644 --- a/crates/rspack/tests/tree-shaking/inherit_export_map_should_lookup_in_dfs_order/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/inherit_export_map_should_lookup_in_dfs_order/snapshot/snap.diff @@ -1,21 +1,22 @@ --- expected +++ actual -@@ -14,6 +14,10 @@ - "./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -6,9 +6,6 @@ + "./a.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; }, -+ 'c': function() { return c; } -+}); - const a = 'bar'; - const c = 'bar'; +-__webpack_require__.d(__webpack_exports__, { +- 'c': function() { return c; } +-}); + const c = 'a'; }, -@@ -35,6 +39,7 @@ + "./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -34,9 +31,6 @@ + "./foo.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; }, - 'b': function() { return b; } - }); +-__webpack_require__.d(__webpack_exports__, { +- 'b': function() { return b; } +-}); /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); + __webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + diff --git a/crates/rspack/tests/tree-shaking/issues_3198/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/issues_3198/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/rspack/tests/tree-shaking/local-binding-reachable1/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/local-binding-reachable1/snapshot/new_treeshaking.snap index b1ce669183a..2554928597f 100644 --- a/crates/rspack/tests/tree-shaking/local-binding-reachable1/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/local-binding-reachable1/snapshot/new_treeshaking.snap @@ -17,8 +17,6 @@ __webpack_require__.d(__webpack_exports__, { 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'callit': function() { return callit; }, - 'Sider': function() { return Sider; }, 'Something': function() { return Something; } }); /* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); diff --git a/crates/rspack/tests/tree-shaking/local-binding-reachable1/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/local-binding-reachable1/snapshot/snap.diff deleted file mode 100644 index dcb2f9ff816..00000000000 --- a/crates/rspack/tests/tree-shaking/local-binding-reachable1/snapshot/snap.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- expected -+++ actual -@@ -17,6 +17,8 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'callit': function() { return callit; }, -+ 'Sider': function() { return Sider; }, - 'Something': function() { return Something; } - }); - /* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); diff --git a/crates/rspack/tests/tree-shaking/local-binding-reachable2/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/local-binding-reachable2/snapshot/new_treeshaking.snap index f86e6cfea2e..ee52c108f58 100644 --- a/crates/rspack/tests/tree-shaking/local-binding-reachable2/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/local-binding-reachable2/snapshot/new_treeshaking.snap @@ -17,7 +17,6 @@ __webpack_require__.d(__webpack_exports__, { 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'Sider': function() { return Sider; }, 'Something': function() { return Something; } }); /* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); diff --git a/crates/rspack/tests/tree-shaking/local-binding-reachable2/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/local-binding-reachable2/snapshot/snap.diff deleted file mode 100644 index 45410ebfe58..00000000000 --- a/crates/rspack/tests/tree-shaking/local-binding-reachable2/snapshot/snap.diff +++ /dev/null @@ -1,10 +0,0 @@ ---- expected -+++ actual -@@ -17,6 +17,7 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'Sider': function() { return Sider; }, - 'Something': function() { return Something; } - }); - /* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); 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 8c1cdb837d3..26be6ac5643 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 @@ -14,17 +14,11 @@ __webpack_require__.d(__webpack_exports__, { "./b.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; } -}); const b = 30; }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'c': function() { return c; } -}); const c = 300; }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/snap.diff index 8ab4099bd79..cf7b5b7d6e9 100644 --- a/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/snap.diff @@ -1,26 +1,18 @@ --- expected +++ actual -@@ -11,15 +11,27 @@ +@@ -11,6 +11,11 @@ }); const a = 3; }, +"./b.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; } -+}); + const b = 30; +}, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'c': function() { return c; } -+}); - const c = 300; - }, - "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -20,6 +25,7 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.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 8c1cdb837d3..26be6ac5643 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 @@ -14,17 +14,11 @@ __webpack_require__.d(__webpack_exports__, { "./b.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; } -}); const b = 30; }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'c': function() { return c; } -}); const c = 300; }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __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 index 270cb710e98..4a02621d726 100644 --- 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 @@ -1,20 +1,12 @@ --- expected +++ actual -@@ -14,13 +14,25 @@ - "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; +@@ -16,11 +16,17 @@ __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'b': function() { return b; } -+}); const b = 30; }, +"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'c': function() { return c; } -+}); + const c = 300; +}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __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 a8ba1f8e885..ea1b9a9cb4f 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 @@ -22,17 +22,13 @@ __webpack_require__.d(__webpack_exports__, { "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - '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; }, - 'LL': function() { return LL; } + '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"); 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 745fd8e1d37..e5ffb0a33f5 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,12 +1,12 @@ --- expected +++ actual -@@ -31,7 +31,8 @@ +@@ -22,9 +22,6 @@ + "./c.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; } -+ 'cccc': function() { return _c__WEBPACK_IMPORTED_MODULE_2_.cccc; }, -+ 'LL': function() { return LL; } - }); - /* 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"); +-__webpack_require__.d(__webpack_exports__, { +- 'cccc': function() { return cccc; } +-}); + function cccc() {} + }, + "./export.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 a71131d359a..4a5710ab73e 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 @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./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__) { diff --git a/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/snap.diff index 0641f18eee7..a1a19200ba3 100644 --- a/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/snap.diff @@ -1,21 +1,18 @@ --- expected +++ actual -@@ -3,6 +3,14 @@ +@@ -3,6 +3,11 @@ --- ```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__); -@@ -17,6 +25,7 @@ +@@ -17,6 +22,7 @@ __webpack_require__.d(__webpack_exports__, { 'default': function() { return a; } }); 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 0af6f7c1f62..7075199e11a 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 @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./a.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; } -}); const a = { a: '' }; @@ -16,9 +13,6 @@ __webpack_require__.d(__webpack_exports__, { "./b.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; } -}); const b = { b: "" }; @@ -53,9 +47,7 @@ console.log(_lib__WEBPACK_IMPORTED_MODULE_0_.getDocPermissionTextSendMe); 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'code2CreateChatDocPermission': function() { return code2CreateChatDocPermission; }, - 'getDocPermissionTextSendMe': function() { return getDocPermissionTextSendMe; }, - 'Doc': function() { return Doc; } + 'getDocPermissionTextSendMe': function() { return getDocPermissionTextSendMe; } }); /* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./enum.js */"./enum.js"); 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 index 3a7242af11b..bd51f2cbf90 100644 --- 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 @@ -1,13 +1,22 @@ --- expected +++ actual -@@ -53,7 +53,9 @@ +@@ -6,9 +6,6 @@ + "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'getDocPermissionTextSendMe': function() { return getDocPermissionTextSendMe; } -+ 'code2CreateChatDocPermission': function() { return code2CreateChatDocPermission; }, -+ 'getDocPermissionTextSendMe': function() { return getDocPermissionTextSendMe; }, -+ 'Doc': function() { return Doc; } - }); - /* harmony import */var _enum_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./enum.js */"./enum.js"); - +-__webpack_require__.d(__webpack_exports__, { +- 'a': function() { return a; } +-}); + const a = { + a: '' + }; +@@ -16,9 +13,6 @@ + "./b.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; } +-}); + const b = { + b: "" + }; 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 ef9927e4c40..414d1d8efb6 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 @@ -6,10 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./answer.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; }, - 'b': function() { return b; } -}); const a = 103330; const b = 103330; }, 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 index 091fa6afd83..f2cd8fe2f01 100644 --- a/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/nested-import-3/snapshot/snap.diff @@ -1,12 +1,12 @@ --- expected +++ actual -@@ -7,7 +7,8 @@ +@@ -6,9 +6,6 @@ + "./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +-__webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; } -+ 'a': function() { return a; }, -+ 'b': function() { return b; } - }); +-}); const a = 103330; const b = 103330; + }, 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 0f88efb840a..e7be25eed34 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 @@ -6,10 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./answer.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; }, - 'b': function() { return b; } -}); const a = 103330; const b = 103330; }, 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 index 091fa6afd83..f2cd8fe2f01 100644 --- a/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/nested-import-4/snapshot/snap.diff @@ -1,12 +1,12 @@ --- expected +++ actual -@@ -7,7 +7,8 @@ +@@ -6,9 +6,6 @@ + "./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +-__webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; } -+ 'a': function() { return a; }, -+ 'b': function() { return b; } - }); +-}); const a = 103330; const b = 103330; + }, 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 6dd21a78035..09fab6f8765 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 @@ -6,27 +6,17 @@ source: crates/rspack_testing/src/run_fixture.rs "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); var __WEBPACK_DEFAULT_EXPORT__ = 300; }, "./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 app; }, - 'test': function() { return test; } -}); function app() {} function test() {} }, "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); __webpack_require__(/* ./app.js */"./app.js"); var __WEBPACK_DEFAULT_EXPORT__ = 200; }, 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 index d905d81fe72..96d627e8475 100644 --- a/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/prune-bailout-module/snapshot/snap.diff @@ -1,32 +1,30 @@ --- expected +++ actual -@@ -11,6 +11,25 @@ - }); +@@ -6,11 +6,20 @@ + "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } +-}); var __WEBPACK_DEFAULT_EXPORT__ = 300; }, +"./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 app; }, -+ 'test': function() { return test; } -+}); + function app() {} + function test() {} +}, +"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -+}); +__webpack_require__(/* ./app.js */"./app.js"); +var __WEBPACK_DEFAULT_EXPORT__ = 200; +}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -@@ -22,9 +41,11 @@ +@@ -22,9 +31,11 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 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 53296bf75e2..b3864dc2e01 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 @@ -19,9 +19,6 @@ __webpack_require__.d(__webpack_exports__, { "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'batch': function() { return batch; } -}); /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js"); __webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); @@ -39,18 +36,12 @@ _foo__WEBPACK_IMPORTED_MODULE_0_.useSelector; "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); function Provider() {} var __WEBPACK_DEFAULT_EXPORT__ = Provider; }, "./selector.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return useSelector; } -}); function useSelector() { return ""; } 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 index 6ebd490b2f6..475420f67a4 100644 --- a/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/snap.diff @@ -1,12 +1,21 @@ --- expected +++ actual -@@ -19,6 +19,9 @@ - "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -36,18 +36,12 @@ + "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'batch': function() { return batch; } -+}); - /* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js"); - __webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } +-}); + function Provider() {} + var __WEBPACK_DEFAULT_EXPORT__ = Provider; + }, + "./selector.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return useSelector; } +-}); + function useSelector() { + return ""; + } 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 0f4d94fd95f..9be3ebf3428 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 @@ -7,8 +7,6 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; }, - 'dddd': function() { return dddd; }, 'aa': function() { return _aa__WEBPACK_IMPORTED_MODULE_0_; } }); /* harmony import */var _aa__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./aa */"./package/autogen/aa.js"); @@ -20,27 +18,17 @@ __webpack_require__.d(__webpack_exports__, { "./package/autogen/aa.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'aa': function() { return aa; }, - 'cc': function() { return cc; } -}); const aa = 3; const cc = 3; }, "./package/autogen/b.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; } -}); function b() {} }, "./package/autogen/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'c': function() { return c; } -}); function c() {} }, "./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __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 index 30c568a09f6..83ea39fa783 100644 --- 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 @@ -1,38 +1,31 @@ --- expected +++ actual -@@ -8,6 +8,7 @@ +@@ -7,7 +7,6 @@ + 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; }, -+ 'dddd': function() { return dddd; }, +- 'a': function() { return a; }, 'aa': function() { return _aa__WEBPACK_IMPORTED_MODULE_0_; } }); /* harmony import */var _aa__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./aa */"./package/autogen/aa.js"); -@@ -20,18 +21,39 @@ +@@ -19,19 +18,30 @@ + "./package/autogen/aa.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +-__webpack_require__.d(__webpack_exports__, { - 'aa': function() { return aa; } -+ 'aa': function() { return aa; }, -+ 'cc': function() { return cc; } - }); +-}); const aa = 3; const cc = 3; }, +"./package/autogen/b.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; } -+}); + function b() {} +}, +"./package/autogen/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'c': function() { return c; } -+}); + function c() {} +}, "./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __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 b9e9fbccc89..ce0a1504009 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 @@ -6,27 +6,17 @@ source: crates/rspack_testing/src/run_fixture.rs "./package/autogen/a.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; }, - 'dddd': function() { return dddd; } -}); function a() {} function dddd() {} }, "./package/autogen/b.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; } -}); function b() {} }, "./package/autogen/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'c': function() { return c; } -}); function c() {} }, "./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __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 index 138769fe639..8391c8da673 100644 --- a/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/reexport-all-as/snapshot/snap.diff @@ -1,30 +1,23 @@ --- expected +++ actual -@@ -7,18 +7,39 @@ +@@ -6,19 +6,30 @@ + "./package/autogen/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +-__webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; } -+ 'a': function() { return a; }, -+ 'dddd': function() { return dddd; } - }); +-}); function a() {} function dddd() {} }, +"./package/autogen/b.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; } -+}); + function b() {} +}, +"./package/autogen/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'c': function() { return c; } -+}); + function c() {} +}, "./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/reexport_default_as/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/reexport_default_as/snapshot/new_treeshaking.snap index 8350ac468b4..66e8b084535 100644 --- a/crates/rspack/tests/tree-shaking/reexport_default_as/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/reexport_default_as/snapshot/new_treeshaking.snap @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return test; } -}); function test() {} }, "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/reexport_default_as/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/reexport_default_as/snapshot/snap.diff index e69de29bb2d..7cc41478805 100644 --- a/crates/rspack/tests/tree-shaking/reexport_default_as/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/reexport_default_as/snapshot/snap.diff @@ -0,0 +1,12 @@ +--- expected ++++ actual +@@ -6,9 +6,6 @@ + "./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return test; } +-}); + function test() {} + }, + "./foo.js": function (__unused_webpack_module, __webpack_exports__, __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 199de953be0..30772feef30 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 @@ -18,9 +18,6 @@ __webpack_require__.d(__webpack_exports__, { "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); var __WEBPACK_DEFAULT_EXPORT__ = 2000 + _c_js__WEBPACK_IMPORTED_MODULE_0_["default"]; @@ -28,9 +25,6 @@ var __WEBPACK_DEFAULT_EXPORT__ = 2000 + _c_js__WEBPACK_IMPORTED_MODULE_0_["defau "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); var __WEBPACK_DEFAULT_EXPORT__ = 10; }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __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 index 8799bc0a456..ff1e3a953a2 100644 --- a/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/snap.diff @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -7,9 +7,11 @@ +@@ -7,18 +7,17 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -13,3 +13,22 @@ }, + "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } +-}); + /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); + + var __WEBPACK_DEFAULT_EXPORT__ = 2000 + _c_js__WEBPACK_IMPORTED_MODULE_0_["default"]; +@@ -26,9 +25,6 @@ + "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } +-}); + var __WEBPACK_DEFAULT_EXPORT__ = 10; + }, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/rename-export-from-import/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/rename-export-from-import/snapshot/new_treeshaking.snap index c63dc1d96c3..7862ba9701b 100644 --- a/crates/rspack/tests/tree-shaking/rename-export-from-import/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/rename-export-from-import/snapshot/new_treeshaking.snap @@ -24,10 +24,6 @@ _app__WEBPACK_IMPORTED_MODULE_0_.q; "./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; }, - 'question': function() { return question; } -}); const answer = "1"; const question = "2"; }, diff --git a/crates/rspack/tests/tree-shaking/rename-export-from-import/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/rename-export-from-import/snapshot/snap.diff index f1d80c42b76..ba5b5c84f5c 100644 --- a/crates/rspack/tests/tree-shaking/rename-export-from-import/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/rename-export-from-import/snapshot/snap.diff @@ -8,11 +8,13 @@ 'q': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_.question; } }); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); -@@ -24,6 +25,7 @@ +@@ -23,9 +24,6 @@ + "./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; }, - 'question': function() { return question; } - }); +-__webpack_require__.d(__webpack_exports__, { +- 'question': function() { return question; } +-}); const answer = "1"; + const question = "2"; + }, diff --git a/crates/rspack/tests/tree-shaking/rollup-unmodified-default-exports-function-argument/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/rollup-unmodified-default-exports-function-argument/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/rspack/tests/tree-shaking/rollup-unmodified-default-exports/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/rollup-unmodified-default-exports/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/rspack/tests/tree-shaking/rollup-unused-called-import/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/rollup-unused-called-import/snapshot/new_treeshaking.snap index 7c30724477a..efd6bf481f5 100644 --- a/crates/rspack/tests/tree-shaking/rollup-unused-called-import/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/rollup-unused-called-import/snapshot/new_treeshaking.snap @@ -17,8 +17,7 @@ function __WEBPACK_DEFAULT_EXPORT__(){ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }, - 'foodead': function() { return foodead; } + 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); /* harmony import */var _dead__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dead */"./dead.js"); diff --git a/crates/rspack/tests/tree-shaking/rollup-unused-called-import/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/rollup-unused-called-import/snapshot/snap.diff index bd4daf144bf..ea0a1343b8d 100644 --- a/crates/rspack/tests/tree-shaking/rollup-unused-called-import/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/rollup-unused-called-import/snapshot/snap.diff @@ -10,17 +10,7 @@ function __WEBPACK_DEFAULT_EXPORT__(){ return "dead"; } -@@ -14,7 +17,8 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }, -+ 'foodead': function() { return foodead; } - }); - /* harmony import */var _dead__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dead */"./dead.js"); - -@@ -22,7 +26,7 @@ +@@ -22,7 +25,7 @@ return "foo"; } function foodead() { diff --git a/crates/rspack/tests/tree-shaking/rollup-unused-default-exports/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/rollup-unused-default-exports/snapshot/new_treeshaking.snap index cc553ff9c40..779a255cc84 100644 --- a/crates/rspack/tests/tree-shaking/rollup-unused-default-exports/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/rollup-unused-default-exports/snapshot/new_treeshaking.snap @@ -7,8 +7,7 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'foo': function() { return foo; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } + 'foo': function() { return foo; } }); var foo = { value: 1 diff --git a/crates/rspack/tests/tree-shaking/rollup-unused-default-exports/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/rollup-unused-default-exports/snapshot/snap.diff deleted file mode 100644 index 2e6ab76ed28..00000000000 --- a/crates/rspack/tests/tree-shaking/rollup-unused-default-exports/snapshot/snap.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- expected -+++ actual -@@ -7,7 +7,8 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'foo': function() { return foo; } -+ 'foo': function() { return foo; }, -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } - }); - var foo = { - value: 1 diff --git a/crates/rspack/tests/tree-shaking/rollup-unused-inner-functions-and-classes/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/rollup-unused-inner-functions-and-classes/snapshot/new_treeshaking.snap index ba6e0597e98..a6bd608acf6 100644 --- a/crates/rspack/tests/tree-shaking/rollup-unused-inner-functions-and-classes/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/rollup-unused-inner-functions-and-classes/snapshot/new_treeshaking.snap @@ -26,10 +26,7 @@ console.log(getClass().name); 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'foo': function() { return foo; }, 'bar': function() { return bar; }, - 'bog': function() { return bog; }, - 'boo': function() { return boo; }, 'baz': function() { return Baz; } }); function foo() { diff --git a/crates/rspack/tests/tree-shaking/rollup-unused-inner-functions-and-classes/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/rollup-unused-inner-functions-and-classes/snapshot/snap.diff deleted file mode 100644 index f155507d00a..00000000000 --- a/crates/rspack/tests/tree-shaking/rollup-unused-inner-functions-and-classes/snapshot/snap.diff +++ /dev/null @@ -1,13 +0,0 @@ ---- expected -+++ actual -@@ -26,7 +26,10 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'foo': function() { return foo; }, - 'bar': function() { return bar; }, -+ 'bog': function() { return bog; }, -+ 'boo': function() { return boo; }, - 'baz': function() { return Baz; } - }); - function foo() { diff --git a/crates/rspack/tests/tree-shaking/rollup-unused-var/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/rollup-unused-var/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 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 f30755f3e34..f30553cc4df 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 @@ -25,12 +25,6 @@ __webpack_require__.r(__webpack_exports__); "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'secret': function() { return secret; }, - 'result': function() { return result; }, - 'something': function() { return something; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); const secret = "888"; const result = 20000; const something = function() {}; @@ -39,9 +33,6 @@ function __WEBPACK_DEFAULT_EXPORT__(){} "./src/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); var __WEBPACK_DEFAULT_EXPORT__ = (()=>{ console.log(""); }); 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 index 3afd2d1c82c..e185ae7797b 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/side-effects-analyzed/snapshot/snap.diff @@ -13,26 +13,21 @@ }, -@@ -24,6 +26,9 @@ +@@ -23,14 +25,18 @@ + "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'secret': function() { return secret; }, -+ 'result': function() { return result; }, -+ 'something': function() { return something; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } - }); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } +-}); const secret = "888"; -@@ -31,6 +36,16 @@ + const result = 20000; const something = function() {}; function __WEBPACK_DEFAULT_EXPORT__(){} }, +"./src/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -+}); +var __WEBPACK_DEFAULT_EXPORT__ = (()=>{ + console.log(""); +}); diff --git a/crates/rspack/tests/tree-shaking/side-effects-export-default-expr/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/side-effects-export-default-expr/snapshot/new_treeshaking.snap index c8bb959b63f..2ee7d7a2e9d 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-export-default-expr/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/side-effects-export-default-expr/snapshot/new_treeshaking.snap @@ -7,7 +7,6 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }, 'b': function() { return b; } }); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); diff --git a/crates/rspack/tests/tree-shaking/side-effects-export-default-expr/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/side-effects-export-default-expr/snapshot/snap.diff index 12acb879db7..667caf9856a 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-export-default-expr/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/side-effects-export-default-expr/snapshot/snap.diff @@ -1,10 +1,7 @@ --- expected +++ actual -@@ -7,10 +7,12 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -9,8 +9,9 @@ __webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }, 'b': function() { return b; } }); +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); @@ -14,7 +11,7 @@ const b = 1; }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -@@ -20,6 +22,14 @@ +@@ -20,6 +21,14 @@ _app__WEBPACK_IMPORTED_MODULE_0_.b; }, diff --git a/crates/rspack/tests/tree-shaking/side-effects-flagged-only/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/side-effects-flagged-only/snapshot/new_treeshaking.snap index f30755f3e34..f30553cc4df 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-flagged-only/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/side-effects-flagged-only/snapshot/new_treeshaking.snap @@ -25,12 +25,6 @@ __webpack_require__.r(__webpack_exports__); "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'secret': function() { return secret; }, - 'result': function() { return result; }, - 'something': function() { return something; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); const secret = "888"; const result = 20000; const something = function() {}; @@ -39,9 +33,6 @@ function __WEBPACK_DEFAULT_EXPORT__(){} "./src/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); var __WEBPACK_DEFAULT_EXPORT__ = (()=>{ console.log(""); }); diff --git a/crates/rspack/tests/tree-shaking/side-effects-flagged-only/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/side-effects-flagged-only/snapshot/snap.diff index f87f429d763..a8f1dc798d2 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-flagged-only/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/side-effects-flagged-only/snapshot/snap.diff @@ -10,23 +10,13 @@ }); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); /* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./src/a */"./src/a.js"); -@@ -25,6 +26,9 @@ +@@ -24,9 +25,6 @@ + "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'secret': function() { return secret; }, -+ 'result': function() { return result; }, -+ 'something': function() { return something; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } - }); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } +-}); const secret = "888"; -@@ -35,6 +39,9 @@ - "./src/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -+}); - var __WEBPACK_DEFAULT_EXPORT__ = (()=>{ - console.log(""); - }); + const result = 20000; + const something = function() {}; 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 407a7d3223d..4dbef1807bb 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 @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "../node_modules/side-effects-module/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'test': function() { return test; } -}); function test() { console.log('something'); } @@ -35,11 +32,6 @@ __webpack_require__.r(__webpack_exports__); "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'secret': function() { return secret; }, - 'result': function() { return result; }, - 'something': function() { return something; } -}); const secret = "888"; const result = 20000; const something = function() {}; @@ -47,9 +39,6 @@ __webpack_require__.d(__webpack_exports__, { "./src/a.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; } -}); /* harmony import */var _d_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./d.js */"./src/d.js"); const a = ()=>{ @@ -62,8 +51,7 @@ __webpack_require__.d(__webpack_exports__, { 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'test': function() { return _c_js__WEBPACK_IMPORTED_MODULE_0_.test; }, - 'b': function() { return b; } + 'test': function() { return _c_js__WEBPACK_IMPORTED_MODULE_0_.test; } }); /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./src/c.js"); 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 index abd577506a8..50316c9cd0c 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/snap.diff @@ -1,15 +1,12 @@ --- expected +++ actual -@@ -3,11 +3,23 @@ +@@ -3,11 +3,20 @@ --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"../node_modules/side-effects-module/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'test': function() { return test; } -+}); + function test() { + console.log('something'); +} @@ -24,14 +21,13 @@ // export { // result as test -@@ -24,12 +36,58 @@ +@@ -23,13 +32,50 @@ + "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'secret': function() { return secret; }, -+ 'result': function() { return result; }, - 'something': function() { return something; } - }); +-__webpack_require__.d(__webpack_exports__, { +- 'something': function() { return something; } +-}); const secret = "888"; const result = 20000; const something = function() {}; @@ -39,9 +35,6 @@ +"./src/a.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; } -+}); +/* harmony import */var _d_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./d.js */"./src/d.js"); + + const a = ()=>{ @@ -54,8 +47,7 @@ +'use strict'; +__webpack_require__.r(__webpack_exports__); +__webpack_require__.d(__webpack_exports__, { -+ 'test': function() { return _c_js__WEBPACK_IMPORTED_MODULE_0_.test; }, -+ 'b': function() { return b; } ++ 'test': function() { return _c_js__WEBPACK_IMPORTED_MODULE_0_.test; } +}); +/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./src/c.js"); + 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 04a486706c5..e44fe5db447 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 @@ -27,12 +27,6 @@ __webpack_require__.r(__webpack_exports__); "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'secret': function() { return secret; }, - 'result': function() { return result; }, - 'something': function() { return something; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); const secret = "888"; const result = 20000; const something = function() {}; @@ -41,9 +35,6 @@ function __WEBPACK_DEFAULT_EXPORT__(){} "./src/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -}); var __WEBPACK_DEFAULT_EXPORT__ = (()=>{ console.log(''); }); 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 index 1fb58588865..d4b294baedb 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/side-effects-two/snapshot/snap.diff @@ -13,26 +13,21 @@ // export { // result as test -@@ -26,6 +28,9 @@ +@@ -25,14 +27,18 @@ + "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'secret': function() { return secret; }, -+ 'result': function() { return result; }, -+ 'something': function() { return something; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } - }); +-__webpack_require__.d(__webpack_exports__, { +- 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } +-}); const secret = "888"; -@@ -33,6 +38,16 @@ + const result = 20000; const something = function() {}; function __WEBPACK_DEFAULT_EXPORT__(){} }, +"./src/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } -+}); +var __WEBPACK_DEFAULT_EXPORT__ = (()=>{ + console.log(''); +}); diff --git a/crates/rspack/tests/tree-shaking/simple-namespace-access/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/simple-namespace-access/snapshot/new_treeshaking.snap index 2a0dff41502..d114893021c 100644 --- a/crates/rspack/tests/tree-shaking/simple-namespace-access/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/simple-namespace-access/snapshot/new_treeshaking.snap @@ -16,8 +16,7 @@ console.log(_maths_js__WEBPACK_IMPORTED_MODULE_0_.square); __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'xxx': function() { return _test_js__WEBPACK_IMPORTED_MODULE_0_; }, - 'square': function() { return square; }, - 'cube': function() { return cube; } + 'square': function() { return square; } }); /* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./test.js */"./test.js"); // maths.js @@ -37,10 +36,6 @@ __webpack_require__.d(__webpack_exports__, { "./test.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'test': function() { return test; }, - 'ccc': function() { return ccc; } -}); function test() {} function ccc() {} }, diff --git a/crates/rspack/tests/tree-shaking/simple-namespace-access/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/simple-namespace-access/snapshot/snap.diff index 81cfb2c40b0..abbd04f63d0 100644 --- a/crates/rspack/tests/tree-shaking/simple-namespace-access/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/simple-namespace-access/snapshot/snap.diff @@ -1,22 +1,12 @@ --- expected +++ actual -@@ -16,7 +16,8 @@ - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { - 'xxx': function() { return _test_js__WEBPACK_IMPORTED_MODULE_0_; }, -- 'square': function() { return square; } -+ 'square': function() { return square; }, -+ 'cube': function() { return cube; } - }); - /* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./test.js */"./test.js"); - // maths.js -@@ -37,7 +38,8 @@ +@@ -36,9 +36,6 @@ + "./test.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +-__webpack_require__.d(__webpack_exports__, { - 'test': function() { return test; } -+ 'test': function() { return test; }, -+ 'ccc': function() { return ccc; } - }); +-}); function test() {} function ccc() {} + }, diff --git a/crates/rspack/tests/tree-shaking/static-class/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/static-class/snapshot/new_treeshaking.snap index 3f3b2d94f89..ac9525a6ba2 100644 --- a/crates/rspack/tests/tree-shaking/static-class/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/static-class/snapshot/new_treeshaking.snap @@ -7,8 +7,6 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'Test': function() { return Test; }, - 'default': function() { return Result; }, 'a': function() { return a; } }); /* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); diff --git a/crates/rspack/tests/tree-shaking/static-class/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/static-class/snapshot/snap.diff index da0b5a078fe..f22ddcfe0ed 100644 --- a/crates/rspack/tests/tree-shaking/static-class/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/static-class/snapshot/snap.diff @@ -1,15 +1,6 @@ --- expected +++ actual -@@ -7,6 +7,8 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'Test': function() { return Test; }, -+ 'default': function() { return Result; }, - 'a': function() { return a; } - }); - /* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); -@@ -19,7 +21,7 @@ +@@ -19,7 +19,7 @@ } class Result { static test() { @@ -18,7 +9,7 @@ } } const a = 3; -@@ -28,7 +30,8 @@ +@@ -28,7 +28,8 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { diff --git a/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/new_treeshaking.snap index b9825408c42..771258395ce 100644 --- a/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/new_treeshaking.snap @@ -6,10 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./a.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; }, - 'b': function() { return b; } -}); const a = 3; const b = 3; }, diff --git a/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/snap.diff index e69de29bb2d..72cc586767a 100644 --- a/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/snap.diff @@ -0,0 +1,13 @@ +--- expected ++++ actual +@@ -6,10 +6,6 @@ + "./a.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; }, +- 'b': function() { return b; } +-}); + const a = 3; + const b = 3; + }, 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 ec46cae3b4d..422c045ba38 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 @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./a.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; } -}); const a = 3; }, "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/snap.diff index c280646d921..6bee0952b6e 100644 --- a/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/snap.diff @@ -1,15 +1,12 @@ --- expected +++ actual -@@ -3,12 +3,21 @@ +@@ -3,12 +3,18 @@ --- ```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__, { -+ 'a': function() { return a; } -+}); + const a = 3; +}, "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/tree-shaking-false-with-side-effect-true/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/tree-shaking-false-with-side-effect-true/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/rspack/tests/tree-shaking/tree-shaking-interop/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/tree-shaking-interop/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/rspack/tests/tree-shaking/tree-shaking-lazy-import/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/tree-shaking-lazy-import/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 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 bc113919ff0..21f8bed113c 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 @@ -7,7 +7,6 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - '_async_to_generator': function() { return _async_to_generator; }, '_': function() { return _async_to_generator; } }); function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { @@ -51,37 +50,6 @@ __webpack_require__.d(__webpack_exports__, { "../../../../../node_modules/tslib/tslib.es6.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - '__extends': function() { return __extends; }, - '__assign': function() { return __assign; }, - '__rest': function() { return __rest; }, - '__decorate': function() { return __decorate; }, - '__param': function() { return __param; }, - '__esDecorate': function() { return __esDecorate; }, - '__runInitializers': function() { return __runInitializers; }, - '__propKey': function() { return __propKey; }, - '__setFunctionName': function() { return __setFunctionName; }, - '__metadata': function() { return __metadata; }, - '__awaiter': function() { return __awaiter; }, - '__generator': function() { return __generator; }, - '__createBinding': function() { return __createBinding; }, - '__exportStar': function() { return __exportStar; }, - '__values': function() { return __values; }, - '__read': function() { return __read; }, - '__spread': function() { return __spread; }, - '__spreadArrays': function() { return __spreadArrays; }, - '__spreadArray': function() { return __spreadArray; }, - '__await': function() { return __await; }, - '__asyncGenerator': function() { return __asyncGenerator; }, - '__asyncDelegator': function() { return __asyncDelegator; }, - '__asyncValues': function() { return __asyncValues; }, - '__makeTemplateObject': function() { return __makeTemplateObject; }, - '__importStar': function() { return __importStar; }, - '__importDefault': function() { return __importDefault; }, - '__classPrivateFieldGet': function() { return __classPrivateFieldGet; }, - '__classPrivateFieldSet': function() { return __classPrivateFieldSet; }, - '__classPrivateFieldIn': function() { return __classPrivateFieldIn; } -}); /****************************************************************************** Copyright (c) Microsoft Corporation. @@ -512,9 +480,6 @@ var __setModuleDefault = Object.create ? function(o, v) { "./index.ts": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - '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"); 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 608da05c0b5..0e1aa172d28 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,14 +1,6 @@ --- expected +++ actual -@@ -7,6 +7,7 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ '_async_to_generator': function() { return _async_to_generator; }, - '_': function() { return _async_to_generator; } - }); - function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { -@@ -41,7 +42,8 @@ +@@ -41,7 +41,8 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -18,40 +10,23 @@ }); /* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); -@@ -50,7 +52,35 @@ +@@ -49,9 +50,6 @@ + "../../../../../node_modules/tslib/tslib.es6.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +-__webpack_require__.d(__webpack_exports__, { - '__generator': function() { return __generator; } -+ '__extends': function() { return __extends; }, -+ '__assign': function() { return __assign; }, -+ '__rest': function() { return __rest; }, -+ '__decorate': function() { return __decorate; }, -+ '__param': function() { return __param; }, -+ '__esDecorate': function() { return __esDecorate; }, -+ '__runInitializers': function() { return __runInitializers; }, -+ '__propKey': function() { return __propKey; }, -+ '__setFunctionName': function() { return __setFunctionName; }, -+ '__metadata': function() { return __metadata; }, -+ '__awaiter': function() { return __awaiter; }, -+ '__generator': function() { return __generator; }, -+ '__createBinding': function() { return __createBinding; }, -+ '__exportStar': function() { return __exportStar; }, -+ '__values': function() { return __values; }, -+ '__read': function() { return __read; }, -+ '__spread': function() { return __spread; }, -+ '__spreadArrays': function() { return __spreadArrays; }, -+ '__spreadArray': function() { return __spreadArray; }, -+ '__await': function() { return __await; }, -+ '__asyncGenerator': function() { return __asyncGenerator; }, -+ '__asyncDelegator': function() { return __asyncDelegator; }, -+ '__asyncValues': function() { return __asyncValues; }, -+ '__makeTemplateObject': function() { return __makeTemplateObject; }, -+ '__importStar': function() { return __importStar; }, -+ '__importDefault': function() { return __importDefault; }, -+ '__classPrivateFieldGet': function() { return __classPrivateFieldGet; }, -+ '__classPrivateFieldSet': function() { return __classPrivateFieldSet; }, -+ '__classPrivateFieldIn': function() { return __classPrivateFieldIn; } - }); +-}); /****************************************************************************** Copyright (c) Microsoft Corporation. + +@@ -482,9 +480,6 @@ + "./index.ts": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- '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"); + diff --git a/crates/rspack/tests/tree-shaking/var-function-expr/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/var-function-expr/snapshot/new_treeshaking.snap index c07e2ce1be9..1198b349d2a 100644 --- a/crates/rspack/tests/tree-shaking/var-function-expr/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/var-function-expr/snapshot/new_treeshaking.snap @@ -7,11 +7,7 @@ source: crates/rspack_testing/src/run_fixture.rs 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'app': function() { return app; }, - 'app2': function() { return app2; }, - 'app4': function() { return app4; }, - 'app5': function() { return app5; }, - 'app3': function() { return app3; } + 'app': function() { return app; } }); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); diff --git a/crates/rspack/tests/tree-shaking/var-function-expr/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/var-function-expr/snapshot/snap.diff index 4bd6c6be065..07a1eb82343 100644 --- a/crates/rspack/tests/tree-shaking/var-function-expr/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/var-function-expr/snapshot/snap.diff @@ -1,19 +1,6 @@ --- expected +++ actual -@@ -7,7 +7,11 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'app': function() { return app; } -+ 'app': function() { return app; }, -+ 'app2': function() { return app2; }, -+ 'app4': function() { return app4; }, -+ 'app5': function() { return app5; }, -+ 'app3': function() { return app3; } - }); - /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); - -@@ -15,7 +19,7 @@ +@@ -15,7 +15,7 @@ _lib__WEBPACK_IMPORTED_MODULE_0_.result; }; var app2 = ()=>{ @@ -22,7 +9,7 @@ }; var app4 = (0, _lib__WEBPACK_IMPORTED_MODULE_0_.something)('app4'), app5 = 10000; var app3 = (0, _lib__WEBPACK_IMPORTED_MODULE_0_.something)('app3'); -@@ -31,6 +35,7 @@ +@@ -31,6 +31,7 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { diff --git a/crates/rspack/tests/tree-shaking/webpack-inner-graph-export-default-named/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-inner-graph-export-default-named/snapshot/new_treeshaking.snap index 1c586c6793e..e85621e7bc4 100644 --- a/crates/rspack/tests/tree-shaking/webpack-inner-graph-export-default-named/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/webpack-inner-graph-export-default-named/snapshot/new_treeshaking.snap @@ -18,9 +18,6 @@ function abc() { "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return abc; } -}); /* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?b */"./dep.js?b"); function abc() { @@ -30,9 +27,6 @@ function abc() { "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return abc; } -}); /* harmony import */var _dep_c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?c */"./dep.js?c"); function abc() { @@ -117,9 +111,6 @@ var __WEBPACK_DEFAULT_EXPORT__ = false; "./e.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return def; } -}); /* harmony import */var _dep_e__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?e */"./dep.js?e"); class def { @@ -131,9 +122,6 @@ class def { "./f.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'default': function() { return def; } -}); /* harmony import */var _dep_f__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?f */"./dep.js?f"); class def { diff --git a/crates/rspack/tests/tree-shaking/webpack-inner-graph-export-default-named/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-inner-graph-export-default-named/snapshot/snap.diff index 9fd075470dc..d7a576dd834 100644 --- a/crates/rspack/tests/tree-shaking/webpack-inner-graph-export-default-named/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/webpack-inner-graph-export-default-named/snapshot/snap.diff @@ -1,12 +1,6 @@ --- expected +++ actual -@@ -18,15 +18,21 @@ - "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return abc; } -+}); +@@ -21,7 +21,7 @@ /* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?b */"./dep.js?b"); function abc() { @@ -15,15 +9,7 @@ } }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return abc; } -+}); - /* harmony import */var _dep_c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?c */"./dep.js?c"); - - function abc() { -@@ -56,12 +62,13 @@ +@@ -56,12 +56,13 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -38,7 +24,7 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; -@@ -75,7 +82,7 @@ +@@ -75,7 +76,7 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -47,7 +33,7 @@ }, "./dep.js?d": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; -@@ -85,12 +92,13 @@ +@@ -85,12 +86,13 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -62,7 +48,7 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; -@@ -104,22 +112,28 @@ +@@ -104,7 +106,7 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -71,11 +57,7 @@ }, "./e.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; - __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return def; } -+}); - /* harmony import */var _dep_e__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?e */"./dep.js?e"); +@@ -113,7 +115,7 @@ class def { method() { @@ -84,12 +66,3 @@ } } }, - "./f.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return def; } -+}); - /* harmony import */var _dep_f__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?f */"./dep.js?f"); - - class def { diff --git a/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/new_treeshaking.snap index 383ba37e745..2f479dc3076 100644 --- a/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/new_treeshaking.snap @@ -42,7 +42,6 @@ it("should generate correct code when pure expressions are in dead branches", () 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'useDocument': function() { return useDocument; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); /* harmony import */var _some_module__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./some-module */"./some-module.js"); diff --git a/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/snap.diff index 7f27c5d8727..2004564657b 100644 --- a/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/snap.diff @@ -8,11 +8,3 @@ }, -@@ -41,6 +42,7 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'useDocument': function() { return useDocument; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } - }); - /* harmony import */var _some_module__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./some-module */"./some-module.js"); diff --git a/crates/rspack/tests/tree-shaking/webpack-innergraph-circular/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-innergraph-circular/snapshot/new_treeshaking.snap index 0f830bf3d77..51d5ba52f34 100644 --- a/crates/rspack/tests/tree-shaking/webpack-innergraph-circular/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/webpack-innergraph-circular/snapshot/new_treeshaking.snap @@ -58,7 +58,6 @@ __webpack_require__.d(__webpack_exports__, { 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'x': function() { return x; }, 'y': function() { return y; } }); /* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./inner */"./inner.js"); diff --git a/crates/rspack/tests/tree-shaking/webpack-innergraph-circular/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-innergraph-circular/snapshot/snap.diff index 25c383c9d44..21e5a17af8b 100644 --- a/crates/rspack/tests/tree-shaking/webpack-innergraph-circular/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/webpack-innergraph-circular/snapshot/snap.diff @@ -8,7 +8,7 @@ 'exportAUsed': function() { return exportAUsed; }, 'exportBUsed': function() { return exportBUsed; }, 'exportCUsed': function() { return exportCUsed; } -@@ -49,14 +50,15 @@ +@@ -49,8 +50,8 @@ function C(s) { return s + "C"; } @@ -19,14 +19,7 @@ const exportCUsed = false; }, "./module.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'x': function() { return x; }, - 'y': function() { return y; } - }); - /* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./inner */"./inner.js"); -@@ -84,7 +86,7 @@ +@@ -84,7 +85,7 @@ } function withC(v) { const value = x(v); diff --git a/crates/rspack/tests/tree-shaking/webpack-innergraph-circular2/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-innergraph-circular2/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/rspack/tests/tree-shaking/webpack-innergraph-no-side-effects/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-innergraph-no-side-effects/snapshot/new_treeshaking.snap index b1cced82633..a205ad5ae0d 100644 --- a/crates/rspack/tests/tree-shaking/webpack-innergraph-no-side-effects/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/webpack-innergraph-no-side-effects/snapshot/new_treeshaking.snap @@ -24,8 +24,7 @@ var __WEBPACK_DEFAULT_EXPORT__ = _package__WEBPACK_IMPORTED_MODULE_0_.a; 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; }, - 'b': function() { return b; } + 'a': function() { return a; } }); /* harmony import */var _unusedModule__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./unusedModule */"./package/unusedModule.js"); diff --git a/crates/rspack/tests/tree-shaking/webpack-innergraph-no-side-effects/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-innergraph-no-side-effects/snapshot/snap.diff index cb9cc141363..fdc2abc2f26 100644 --- a/crates/rspack/tests/tree-shaking/webpack-innergraph-no-side-effects/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/webpack-innergraph-no-side-effects/snapshot/snap.diff @@ -1,12 +1,8 @@ --- expected +++ actual -@@ -24,16 +24,26 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -26,14 +26,23 @@ __webpack_require__.d(__webpack_exports__, { -- 'a': function() { return a; } -+ 'a': function() { return a; }, -+ 'b': function() { return b; } + 'a': function() { return a; } }); +/* harmony import */var _unusedModule__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./unusedModule */"./package/unusedModule.js"); diff --git a/crates/rspack/tests/tree-shaking/webpack-innergraph-try-globals/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-innergraph-try-globals/snapshot/new_treeshaking.snap index 0567a44101b..1926f323acf 100644 --- a/crates/rspack/tests/tree-shaking/webpack-innergraph-try-globals/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/webpack-innergraph-try-globals/snapshot/new_treeshaking.snap @@ -20,9 +20,6 @@ it("should not threat globals as pure", ()=>{ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'x': function() { return x; }, - 'y': function() { return y; }, - 'c': function() { return c; }, 'ok': function() { return ok; }, 'ok2': function() { return ok2; } }); diff --git a/crates/rspack/tests/tree-shaking/webpack-innergraph-try-globals/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-innergraph-try-globals/snapshot/snap.diff deleted file mode 100644 index 338f19c0de5..00000000000 --- a/crates/rspack/tests/tree-shaking/webpack-innergraph-try-globals/snapshot/snap.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- expected -+++ actual -@@ -20,6 +20,9 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'x': function() { return x; }, -+ 'y': function() { return y; }, -+ 'c': function() { return c; }, - 'ok': function() { return ok; }, - 'ok2': function() { return ok2; } - }); 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 7cbab06d6ef..c3e5a48c507 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 @@ -41,7 +41,6 @@ __webpack_require__.d(__webpack_exports__, { 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }, 'exportDefaultUsed': function() { return exportDefaultUsed; } }); /* harmony import */var _script1__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script1 */"./package1/script1.js"); @@ -66,7 +65,6 @@ var __WEBPACK_DEFAULT_EXPORT__ = 1; 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }, 'exportDefaultUsed': function() { return exportDefaultUsed; } }); /* harmony import */var _script3__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script3 */"./package1/script3.js"); diff --git a/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/snap.diff index 155c744f514..a7fc803a3f3 100644 --- a/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/snap.diff @@ -1,12 +1,6 @@ --- expected +++ actual -@@ -41,18 +41,22 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }, - 'exportDefaultUsed': function() { return exportDefaultUsed; } - }); +@@ -46,13 +46,16 @@ /* harmony import */var _script1__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script1 */"./package1/script1.js"); __webpack_require__.es(_script1__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); @@ -24,11 +18,8 @@ /* harmony import */var _script2__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script2 */"./package1/script2.js"); __webpack_require__.es(_script2__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -@@ -62,15 +66,26 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -64,13 +67,23 @@ __webpack_require__.d(__webpack_exports__, { -+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }, 'exportDefaultUsed': function() { return exportDefaultUsed; } }); +/* harmony import */var _script3__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script3 */"./package1/script3.js"); @@ -52,7 +43,7 @@ "./package2/script.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -@@ -83,7 +98,7 @@ +@@ -83,7 +96,7 @@ var __WEBPACK_DEFAULT_EXPORT__ = _script1__WEBPACK_IMPORTED_MODULE_0_["default"]; 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 dfcd0b35a61..0e552f932e1 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 @@ -6,11 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "../node_modules/pmodule/a.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; }, - 'b': function() { return b; }, - 'c': function() { return c; } -}); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var a = "a"; var b = "b"; @@ -23,9 +18,7 @@ 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; }, - 'y': function() { return y; } + 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; } }); /* 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"); @@ -39,9 +32,6 @@ var y = "y"; "../node_modules/pmodule/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'z': function() { return z; } -}); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var z = "z"; @@ -72,8 +62,7 @@ var __WEBPACK_DEFAULT_EXPORT__ = "def"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'track': function() { return track; }, - 'log': function() { return log; }, - 'reset': function() { return reset; } + 'log': function() { return log; } }); function track(file) { log.push(file); 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 index 9ed6ddb1bda..f424ef4f502 100644 --- 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 @@ -1,27 +1,36 @@ --- expected +++ actual -@@ -7,7 +7,9 @@ +@@ -6,9 +6,6 @@ + "../node_modules/pmodule/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +-__webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; } -+ 'a': function() { return a; }, -+ 'b': function() { return b; }, -+ 'c': function() { return c; } - }); +-}); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var a = "a"; -@@ -22,7 +24,8 @@ + var b = "b"; +@@ -21,8 +18,7 @@ + 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, +- 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, - 'x': function() { return x; } -+ 'x': function() { return x; }, -+ 'y': function() { return y; } ++ 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; } }); /* 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"); -@@ -50,6 +53,7 @@ +@@ -36,9 +32,6 @@ + "../node_modules/pmodule/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'z': function() { return z; } +-}); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + var z = "z"; + +@@ -50,6 +43,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'x': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.x; }, @@ -29,13 +38,3 @@ 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); -@@ -68,7 +72,8 @@ - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { - 'track': function() { return track; }, -- 'log': function() { return log; } -+ 'log': function() { return log; }, -+ 'reset': function() { return reset; } - }); - function track(file) { - log.push(file); 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 6fdd11ae4ea..871b7bc537c 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 @@ -6,11 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "../node_modules/pmodule/a.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; }, - 'b': function() { return b; }, - 'c': function() { return c; } -}); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var a = "a"; var b = "b"; @@ -23,9 +18,7 @@ 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; }, - 'y': function() { return y; } + 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; } }); /* 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"); @@ -39,9 +32,6 @@ var y = "y"; "../node_modules/pmodule/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'z': function() { return z; } -}); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var z = "z"; @@ -72,8 +62,7 @@ var __WEBPACK_DEFAULT_EXPORT__ = "def"; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'track': function() { return track; }, - 'log': function() { return log; }, - 'reset': function() { return reset; } + 'log': function() { return log; } }); function track(file) { log.push(file); 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 index 0378b75e896..49706d21142 100644 --- 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 @@ -1,17 +1,12 @@ --- expected +++ actual -@@ -3,12 +3,29 @@ +@@ -3,12 +3,22 @@ --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"../node_modules/pmodule/a.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; }, -+ 'b': function() { return b; }, -+ 'c': function() { return c; } -+}); +/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); +var a = "a"; +var b = "b"; @@ -24,14 +19,23 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, +- 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, - 'x': function() { return x; } -+ 'x': function() { return x; }, -+ 'y': function() { return y; } ++ 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; } }); /* 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"); -@@ -36,9 +53,12 @@ +@@ -22,9 +32,6 @@ + "../node_modules/pmodule/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'z': function() { return z; } +-}); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + var z = "z"; + +@@ -36,9 +43,12 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'x': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.x; }, @@ -44,13 +48,3 @@ /* 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"); -@@ -52,7 +72,8 @@ - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { - 'track': function() { return track; }, -- 'log': function() { return log; } -+ 'log': function() { return log; }, -+ 'reset': function() { return reset; } - }); - function track(file) { - log.push(file); diff --git a/crates/rspack/tests/tree-shaking/with-assets/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/with-assets/snapshot/snap.diff deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 88634bd7247..70b767e28c1 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -1158,6 +1158,10 @@ 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); + // } + let start = logger.time("create chunks"); use_code_splitting_cache(self, |compilation| async { build_chunk_graph(compilation)?; diff --git a/crates/rspack_core/src/compiler/mod.rs b/crates/rspack_core/src/compiler/mod.rs index 60a8b2b8c02..8b74168a32b 100644 --- a/crates/rspack_core/src/compiler/mod.rs +++ b/crates/rspack_core/src/compiler/mod.rs @@ -197,12 +197,12 @@ where }; match exports_info_map.entry(importer) { Entry::Occupied(mut occ) => { - let export_info = ExportInfo::new(name.clone(), UsageState::Used, None); + let export_info = ExportInfo::new(Some(name.clone()), UsageState::Used, None); occ.get_mut().insert(name.clone(), export_info); } Entry::Vacant(vac) => { let mut map = HashMap::default(); - let export_info = ExportInfo::new(name.clone(), UsageState::Used, None); + let export_info = ExportInfo::new(Some(name.clone()), UsageState::Used, None); map.insert(name.clone(), export_info); vac.insert(map); } diff --git a/crates/rspack_core/src/compiler/queue.rs b/crates/rspack_core/src/compiler/queue.rs index bcdd48157c0..01ab9ace47c 100644 --- a/crates/rspack_core/src/compiler/queue.rs +++ b/crates/rspack_core/src/compiler/queue.rs @@ -118,9 +118,12 @@ impl WorkerTask for FactorizeTask { } }; - let other_exports_info = ExportInfo::new("null".into(), UsageState::Unknown, None); - let side_effects_only_info = - ExportInfo::new("*side effects only*".into(), UsageState::Unknown, None); + let other_exports_info = ExportInfo::new(None, UsageState::Unknown, None); + let side_effects_only_info = ExportInfo::new( + Some("*side effects only*".into()), + UsageState::Unknown, + None, + ); let exports_info = ExportsInfo::new(other_exports_info.id, side_effects_only_info.id); let mgm = ModuleGraphModule::new( result.module.identifier(), diff --git a/crates/rspack_core/src/dependency/mod.rs b/crates/rspack_core/src/dependency/mod.rs index eee0e88aefc..25798baf4ba 100644 --- a/crates/rspack_core/src/dependency/mod.rs +++ b/crates/rspack_core/src/dependency/mod.rs @@ -364,7 +364,7 @@ pub trait ModuleDependency: Dependency { None } - fn get_condition(&self, _module_graph: &ModuleGraph) -> Option { + fn get_condition(&self) -> Option { None } diff --git a/crates/rspack_core/src/exports_info.rs b/crates/rspack_core/src/exports_info.rs index 613d5a11fcd..2adda61cdf0 100644 --- a/crates/rspack_core/src/exports_info.rs +++ b/crates/rspack_core/src/exports_info.rs @@ -126,7 +126,7 @@ impl ExportsInfoId { changed = true; } if let Some(ref exclude_exports) = exclude_exports { - if exclude_exports.contains(&export_info.name) { + if let Some(ref export_name) = export_info.name && exclude_exports.contains(export_name) { continue; } } @@ -140,8 +140,8 @@ impl ExportsInfoId { if let Some(target_key) = target_key { export_info.set_target( &target_key, - target_module.clone(), - Some(&vec![export_info.name.clone()]), + target_module, + export_info.name.clone().map(|name| vec![name]).as_ref(), priority, ); } @@ -247,7 +247,11 @@ impl ExportsInfoId { .export_info_map .get(&other_exports_info) .expect("should have export_info"); - let new_info = ExportInfo::new(name.clone(), UsageState::Unknown, Some(other_export_info)); + let new_info = ExportInfo::new( + Some(name.clone()), + UsageState::Unknown, + Some(other_export_info), + ); let new_info_id = new_info.id; mg.export_info_map.insert(new_info_id, new_info); @@ -324,10 +328,39 @@ impl ExportsInfoId { pub fn set_used_in_unknown_way( &self, - _mg: &mut ModuleGraph, - _runtime: Option<&RuntimeSpec>, + mg: &mut ModuleGraph, + runtime: Option<&RuntimeSpec>, ) -> bool { - todo!() + let mut changed = false; + let exports_info = mg.get_exports_info_by_id(self); + let export_info_id_list = exports_info.exports.values().cloned().collect::>(); + let redirect_to_id = exports_info.redirect_to; + let other_exports_info_id = exports_info.other_exports_info; + for export_info_id in export_info_id_list { + if export_info_id.set_used_in_unknown_way(mg, runtime) { + changed = true; + } + } + if let Some(redirect_to) = redirect_to_id { + if redirect_to.set_used_in_unknown_way(mg, runtime) { + changed = true; + } + } else { + if other_exports_info_id.set_used_conditionally( + mg, + Box::new(|value| value < &UsageState::Unknown), + UsageState::Unknown, + runtime, + ) { + changed = true; + } + let other_exports_info = mg.get_export_info_mut_by_id(&other_exports_info_id); + if other_exports_info.can_mangle_use != Some(false) { + other_exports_info.can_mangle_use = Some(false); + changed = true; + } + } + changed } pub fn set_used_for_side_effects_only( @@ -344,6 +377,21 @@ impl ExportsInfoId { runtime, ) } + + pub fn get_used_name( + &self, + mg: &ModuleGraph, + runtime: Option<&RuntimeSpec>, + name: UsedName, + ) -> Option { + match name { + UsedName::Str(name) => { + let info = self.get_read_only_export_info(&name, mg); + info.get_used_name(&name, runtime).map(UsedName::Str) + } + UsedName::Vec(_) => todo!(), + } + } } impl Default for ExportsInfoId { @@ -408,7 +456,8 @@ impl ExportsInfo { } } - pub fn get_used_exports(&self) -> HashSet<&JsWord> { + /// only used for old version tree shaking + pub fn old_get_used_exports(&self) -> HashSet<&JsWord> { self.exports.keys().collect::>() } @@ -480,6 +529,7 @@ impl ExportsInfo { } } +#[derive(Debug)] pub enum UsedName { Str(JsWord), Vec(Vec), @@ -583,6 +633,25 @@ impl ExportInfoId { let export_info = mg.get_export_info_by_id(self); export_info.exports_info } + + fn set_used_in_unknown_way(&self, mg: &mut ModuleGraph, runtime: Option<&RuntimeSpec>) -> bool { + let mut changed = false; + + if self.set_used_conditionally( + mg, + Box::new(|value| value < &UsageState::Unknown), + UsageState::Unknown, + runtime, + ) { + changed = true; + } + let export_info = mg.get_export_info_mut_by_id(self); + if export_info.can_mangle_use != Some(false) { + export_info.can_mangle_use = Some(false); + changed = true; + } + changed + } } impl Default for ExportInfoId { fn default() -> Self { @@ -607,10 +676,11 @@ impl From for ExportInfoId { #[derive(Debug, Clone, Default)] #[allow(unused)] pub struct ExportInfo { - pub name: JsWord, + pub name: Option, module_identifier: Option, pub usage_state: UsageState, - used_name: Option, + /// this is mangled name,https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/ExportsInfo.js#L1181-L1188 + used_name: Option, target: HashMap, max_target: HashMap, pub provided: Option, @@ -625,6 +695,7 @@ pub struct ExportInfo { pub has_use_in_runtime_info: bool, pub can_mangle_use: Option, pub global_used: Option, + pub used_in_runtime: Option>, } impl ExportsHash for ExportInfo { @@ -704,19 +775,25 @@ impl Clone for Box> { impl ExportInfo { // TODO: remove usage_state in the future - pub fn new(name: JsWord, usage_state: UsageState, init_from: Option<&ExportInfo>) -> Self { + pub fn new( + name: Option, + usage_state: UsageState, + init_from: Option<&ExportInfo>, + ) -> Self { let has_use_in_runtime_info = if let Some(init_from) = init_from { init_from.has_use_in_runtime_info } else { false }; let can_mangle_use = init_from.and_then(|init_from| init_from.can_mangle_use); + let used_in_runtime = init_from.and_then(|init_from| init_from.used_in_runtime.clone()); Self { name, module_identifier: None, usage_state, used_name: None, + used_in_runtime, // TODO: init this target: HashMap::default(), provided: None, @@ -739,6 +816,33 @@ impl ExportInfo { UsageState::Unused } + /// Webpack returns `false | string`, we use `Option` to avoid declare a redundant enum + /// type + pub fn get_used_name( + &self, + fallback_name: &JsWord, + _runtime: Option<&RuntimeSpec>, + ) -> Option { + if self.has_use_in_runtime_info { + if let Some(usage) = self.global_used { + if matches!(usage, UsageState::Unused) { + return None; + } + } else { + self.used_in_runtime.as_ref()?; + // TODO: runtime optimization + } + } + if let Some(used_name) = self.used_name.as_ref() { + return Some(used_name.clone()); + } + if let Some(name) = self.name.as_ref() { + Some(name.clone()) + } else { + Some(fallback_name.clone()) + } + } + pub fn get_exports_info<'a>(&self, module_graph: &'a ModuleGraph) -> Option<&'a ExportsInfo> { self .module_identifier @@ -914,7 +1018,7 @@ impl ExportInfo { .get_max_target() .values() .map(|item| UnResolvedExportInfoTarget { - connection: item.connection.clone(), + connection: item.connection, exports: item.exports.clone(), }) .clone(); @@ -1005,9 +1109,12 @@ impl ExportInfo { .expect("should have exports_info when exports_info is true"); } - let other_exports_info = ExportInfo::new("null".into(), UsageState::Unknown, None); - let side_effects_only_info = - ExportInfo::new("*side effects only*".into(), UsageState::Unknown, None); + let other_exports_info = ExportInfo::new(None, UsageState::Unknown, None); + let side_effects_only_info = ExportInfo::new( + Some("*side effects only*".into()), + UsageState::Unknown, + None, + ); let new_exports_info = ExportsInfo::new(other_exports_info.id, side_effects_only_info.id); let new_exports_info_id = new_exports_info.id; @@ -1028,12 +1135,20 @@ impl ExportInfo { } } -#[derive(Debug, PartialEq, Copy, Clone, Default, Hash)] +#[derive(Debug, PartialEq, Copy, Clone, Default, Hash, PartialOrd)] pub enum UsageState { - Unused, + Unused = 0, + OnlyPropertiesUsed = 1, + NoInfo = 2, + #[default] + Unknown = 3, + Used = 4, +} + +#[derive(Debug, PartialEq, Copy, Clone, Hash)] +pub enum RuntimeUsageStateType { OnlyPropertiesUsed, NoInfo, - #[default] Unknown, Used, } @@ -1048,18 +1163,17 @@ pub enum UsedByExports { // https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/optimize/InnerGraph.js#L319-L338 pub fn get_dependency_used_by_exports_condition( - dependency_id: &DependencyId, + dependency_id: DependencyId, used_by_exports: &UsedByExports, - module_graph: &ModuleGraph, ) -> Option { match used_by_exports { UsedByExports::Set(used_by_exports) => { - let module_identifier = module_graph - .parent_module_by_dependency_id(dependency_id) - .expect("should have parent module"); let used_by_exports = Arc::new(used_by_exports.clone()); Some(DependencyCondition::Fn(Box::new( - move |_, runtime, module_graph| { + move |_, runtime, module_graph: &ModuleGraph| { + let module_identifier = module_graph + .parent_module_by_dependency_id(&dependency_id) + .expect("should have parent module"); let exports_info = module_graph.get_exports_info(&module_identifier); for export_name in used_by_exports.iter() { if exports_info.get_used(UsedName::Str(export_name.clone()), runtime, module_graph) @@ -1084,7 +1198,7 @@ pub fn get_dependency_used_by_exports_condition( } /// refer https://github.com/webpack/webpack/blob/d15c73469fd71cf98734685225250148b68ddc79/lib/FlagDependencyUsagePlugin.js#L64 -#[derive(Clone)] +#[derive(Clone, Debug)] pub enum ExtendedReferencedExport { Array(Vec), Export(ReferencedExport), @@ -1117,7 +1231,7 @@ impl From for ExtendedReferencedExport { } } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct ReferencedExport { pub name: Vec, pub can_mangle: bool, @@ -1182,11 +1296,19 @@ pub fn process_export_info( module_graph, runtime, referenced_export, - if default_points_to_self && &export_info.name == "default" { + if default_points_to_self + && export_info + .name + .as_ref() + .map(|name| name == "default") + .unwrap_or_default() + { prefix.clone() } else { let mut value = prefix.clone(); - value.push(export_info.name.clone()); + if let Some(name) = export_info.name.as_ref() { + value.push(name.clone()); + } value }, Some(export_info.id), diff --git a/crates/rspack_core/src/module_graph/connection.rs b/crates/rspack_core/src/module_graph/connection.rs index f2b84606def..7009a3110c1 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)] +#[derive(Debug, Clone, Copy)] pub struct ModuleGraphConnection { /// The referencing module identifier pub original_module_identifier: Option, @@ -31,7 +31,6 @@ pub struct ModuleGraphConnection { pub dependency_id: DependencyId, active: bool, conditional: bool, - condition: Option, } /// implementing hash by hand because condition maybe a function, which can't be hash @@ -65,17 +64,15 @@ impl ModuleGraphConnection { original_module_identifier: Option, dependency_id: DependencyId, module_identifier: ModuleIdentifier, - condition: Option, + active: bool, + conditional: bool, ) -> Self { - let active = !matches!(condition, Some(DependencyCondition::False)); - let conditional = condition.is_some(); Self { original_module_identifier, module_identifier, dependency_id, active, conditional, - condition, } } @@ -123,13 +120,18 @@ impl ModuleGraphConnection { module_graph: &ModuleGraph, runtime: Option<&RuntimeSpec>, ) -> ConnectionState { - match self.condition.as_ref().expect("should have condition") { + match module_graph + .connection_to_condition + .get(self) + .expect("should have condition") + { DependencyCondition::False => ConnectionState::Bool(false), DependencyCondition::Fn(f) => f(self, runtime, module_graph), } } } +#[derive(Debug)] pub enum ConnectionState { Bool(bool), CircularConnection, diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index 73614dc3552..af2f748336b 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -42,11 +42,11 @@ pub struct ModuleGraph { /// Module graph connections table index for `ConnectionId` connections_map: HashMap, - connection_to_condition: HashMap, import_var_map: IdentifierMap, pub exports_info_map: HashMap, pub export_info_map: HashMap, + connection_to_condition: HashMap, } impl ModuleGraph { @@ -82,13 +82,6 @@ impl ModuleGraph { self.dependencies.insert(*dependency.id(), dependency); } - pub fn get_condition_by_connection_id( - &self, - connection_id: &ConnectionId, - ) -> Option<&DependencyCondition> { - self.connection_to_condition.get(connection_id) - } - pub fn dependency_by_id(&self, dependency_id: &DependencyId) -> Option<&BoxDependency> { self.dependencies.get(dependency_id) } @@ -122,35 +115,45 @@ impl ModuleGraph { dependency: BoxDependency, module_identifier: ModuleIdentifier, ) -> Result<()> { - let module_dependency = dependency.as_module_dependency().is_some(); + let is_module_dependency = dependency.as_module_dependency().is_some(); let dependency_id = *dependency.id(); + let condition = dependency + .as_module_dependency() + .and_then(|dep| dep.get_condition()); self.add_dependency(dependency); self .dependency_id_to_module_identifier .insert(dependency_id, module_identifier); - if !module_dependency { + if !is_module_dependency { return Ok(()); } + let active = !matches!(condition, Some(DependencyCondition::False)); + let conditional = condition.is_some(); // TODO: just a placeholder here, finish this when we have basic `getCondition` logic - let condition: Option = None; let new_connection = ModuleGraphConnection::new( original_module_identifier, dependency_id, module_identifier, - condition, + active, + conditional, ); let connection_id = if let Some(connection_id) = self.connections_map.get(&new_connection) { *connection_id } else { let new_connection_id = ConnectionId::from(self.connections.len()); - self.connections.push(Some(new_connection.clone())); + self.connections.push(Some(new_connection)); self .connections_map .insert(new_connection, new_connection_id); new_connection_id }; + if let Some(condition) = condition { + self + .connection_to_condition + .insert(new_connection, condition); + } self .dependency_id_to_connection_id @@ -681,9 +684,12 @@ mod test { impl_noop_trait_dep_type!(Edge); fn add_module_to_graph(mg: &mut ModuleGraph, m: Box) { - let other_exports_info = ExportInfo::new("null".into(), UsageState::Unknown, None); - let side_effects_only_info = - ExportInfo::new("*side effects only*".into(), UsageState::Unknown, None); + let other_exports_info = ExportInfo::new(None, UsageState::Unknown, None); + let side_effects_only_info = ExportInfo::new( + Some("*side effects only*".into()), + UsageState::Unknown, + None, + ); let exports_info = ExportsInfo::new(other_exports_info.id, side_effects_only_info.id); let mgm = ModuleGraphModule::new(m.identifier(), ModuleType::Js, exports_info.id); mg.add_module_graph_module(mgm); 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 0d72b9c4966..a7338e84c83 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,10 @@ use rspack_core::{ create_exports_object_referenced, create_no_exports_referenced, export_from_import, get_exports_type, process_export_info, ConnectionState, Dependency, DependencyCategory, - DependencyId, DependencyTemplate, DependencyType, ErrorSpan, ExportInfoId, ExportInfoProvided, - ExportsType, ExtendedReferencedExport, HarmonyExportInitFragment, ModuleDependency, ModuleGraph, - ModuleIdentifier, RuntimeSpec, TemplateContext, TemplateReplaceSource, UsageState, + DependencyCondition, DependencyId, DependencyTemplate, DependencyType, ErrorSpan, ExportInfoId, + ExportInfoProvided, ExportsType, ExtendedReferencedExport, HarmonyExportInitFragment, + ModuleDependency, ModuleGraph, ModuleIdentifier, RuntimeSpec, TemplateContext, + TemplateReplaceSource, UsageState, }; use rustc_hash::FxHashSet as HashSet; use swc_core::ecma::atoms::JsWord; @@ -75,10 +76,7 @@ impl HarmonyExportImportedSpecifierDependency { { imported_module_identifier } else { - return ExportMode { - kind: ExportModeType::Missing, - ..Default::default() - }; + return ExportMode::new(ExportModeType::Missing); }; let parent_module = module_graph @@ -92,11 +90,16 @@ impl HarmonyExportImportedSpecifierDependency { if let Some(name) = name.as_ref() && !ids.is_empty() && let Some(id) = ids.get(0) && id == "default" { match exports_type { ExportsType::Dynamic => { - return ExportMode { kind: ExportModeType::ReexportDynamicDefault, name: Some(name.clone()), ..Default::default() } + let mut export_mode = ExportMode::new(ExportModeType::ReexportDynamicDefault, ); + export_mode.name = Some(name.clone()); + return export_mode; }, ExportsType::DefaultOnly | ExportsType::DefaultWithNamed => { let export_info = exports_info.id.get_read_only_export_info(name, module_graph).id; - return ExportMode { kind: ExportModeType::ReexportNamedDefault, name: Some(name.clone()), partial_namespace_export_info: Some(export_info), ..Default::default() } + let mut export_mode = ExportMode::new( ExportModeType::ReexportNamedDefault); + export_mode.name = Some(name.clone()); + export_mode.partial_namespace_export_info = Some(export_info); + return export_mode; }, _ => {} } @@ -112,54 +115,44 @@ impl HarmonyExportImportedSpecifierDependency { // export { name as name } match exports_type { ExportsType::DefaultOnly => { - return ExportMode { - kind: ExportModeType::ReexportUndefined, - name: Some(name), - ..Default::default() - } + let mut export_mode = ExportMode::new(ExportModeType::ReexportUndefined); + export_mode.name = Some(name); + return export_mode; } _ => { - return ExportMode { - kind: ExportModeType::NormalReexport, - items: Some(vec![NormalReexportItem { - name, - ids: ids.to_vec(), - hidden: false, - checked: false, - export_info, - }]), - ..Default::default() - } + let mut export_mode = ExportMode::new(ExportModeType::NormalReexport); + export_mode.items = Some(vec![NormalReexportItem { + name, + ids: ids.to_vec(), + hidden: false, + checked: false, + export_info, + }]); + return export_mode; } } } else { // export * as name match exports_type { ExportsType::DefaultOnly => { - return ExportMode { - kind: ExportModeType::ReexportFakeNamespaceObject, - name: Some(name), - partial_namespace_export_info: Some(export_info), - fake_type: Some(0), - ..Default::default() - } + let mut export_mode = ExportMode::new(ExportModeType::ReexportFakeNamespaceObject); + export_mode.name = Some(name); + export_mode.partial_namespace_export_info = Some(export_info); + export_mode.fake_type = 0; + return export_mode; } ExportsType::DefaultWithNamed => { - return ExportMode { - kind: ExportModeType::ReexportFakeNamespaceObject, - name: Some(name), - partial_namespace_export_info: Some(export_info), - fake_type: Some(2), - ..Default::default() - } + let mut export_mode = ExportMode::new(ExportModeType::ReexportFakeNamespaceObject); + export_mode.name = Some(name); + export_mode.partial_namespace_export_info = Some(export_info); + export_mode.fake_type = 2; + return export_mode; } _ => { - return ExportMode { - kind: ExportModeType::ReexportNamespaceObject, - name: Some(name), - partial_namespace_export_info: Some(export_info), - ..Default::default() - } + let mut export_mode = ExportMode::new(ExportModeType::ReexportNamespaceObject); + export_mode.name = Some(name); + export_mode.partial_namespace_export_info = Some(export_info); + return export_mode; } } } @@ -174,11 +167,9 @@ impl HarmonyExportImportedSpecifierDependency { if let Some(exports) = exports { if exports.is_empty() { - return ExportMode { - kind: ExportModeType::EmptyStar, - hidden, - ..Default::default() - }; + let mut export_mode = ExportMode::new(ExportModeType::EmptyStar); + export_mode.hidden = hidden; + return export_mode; } let mut items = exports @@ -209,19 +200,14 @@ impl HarmonyExportImportedSpecifierDependency { }); } } - - ExportMode { - kind: ExportModeType::NormalReexport, - items: Some(items), - ..Default::default() - } + let mut export_mode = ExportMode::new(ExportModeType::NormalReexport); + export_mode.items = Some(items); + export_mode } else { - ExportMode { - kind: ExportModeType::DynamicReexport, - ignored: Some(ignored_exports), - hidden, - ..Default::default() - } + let mut export_mode = ExportMode::new(ExportModeType::DynamicReexport); + export_mode.ignored = Some(ignored_exports); + export_mode.hidden = hidden; + export_mode } } @@ -275,14 +261,15 @@ impl HarmonyExportImportedSpecifierDependency { .export_info_map .get(export_info_id) .expect("should have export info"); - if ignored_exports.contains(&export_info.name) + let export_name = export_info.name.clone().unwrap_or_default(); + if ignored_exports.contains(&export_name) || matches!(export_info.get_used(runtime), UsageState::Unused) { continue; } let imported_export_info = imported_exports_info .id - .get_read_only_export_info(&export_info.name, module_graph); + .get_read_only_export_info(&export_name, module_graph); if matches!( imported_export_info.provided, Some(ExportInfoProvided::False) @@ -290,20 +277,20 @@ impl HarmonyExportImportedSpecifierDependency { continue; } if let Some(hidden) = hidden.as_mut() && hidden_exports.as_ref() - .map(|hidden_exports| hidden_exports.contains(&export_info.name)) + .map(|hidden_exports| hidden_exports.contains(&export_name)) .is_some() { - hidden.insert(export_info.name.clone()); + hidden.insert(export_name.clone()); continue; } - exports.insert(export_info.name.clone()); + exports.insert(export_name.clone()); if matches!( imported_export_info.provided, Some(ExportInfoProvided::True) ) { continue; } - checked.insert(export_info.name.clone()); + checked.insert(export_name); } } else if no_extra_exports { for import_export_info_id in imported_exports_info.get_ordered_exports() { @@ -311,29 +298,30 @@ impl HarmonyExportImportedSpecifierDependency { .export_info_map .get(import_export_info_id) .expect("should have export info"); - if ignored_exports.contains(&import_export_info.name) + let import_export_info_name = import_export_info.name.clone().unwrap_or_default(); + if ignored_exports.contains(&import_export_info_name) || matches!(import_export_info.provided, Some(ExportInfoProvided::False)) { continue; } let export_info = exports_info .id - .get_read_only_export_info(&import_export_info.name, module_graph); + .get_read_only_export_info(&import_export_info_name, module_graph); if matches!(export_info.get_used(runtime), UsageState::Unused) { continue; } if let Some(hidden) = hidden.as_mut() && hidden_exports.as_ref() - .map(|hidden_exports| hidden_exports.contains(&import_export_info.name)) + .map(|hidden_exports| hidden_exports.contains(&import_export_info_name)) .is_some() { - hidden.insert(import_export_info.name.clone()); + hidden.insert(import_export_info_name.clone()); continue; } - exports.insert(import_export_info.name.clone()); + exports.insert(import_export_info_name.clone()); if matches!(import_export_info.provided, Some(ExportInfoProvided::True)) { continue; } - checked.insert(import_export_info.name.clone()); + checked.insert(import_export_info_name); } } @@ -388,7 +376,7 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { compilation .module_graph .get_exports_info(&module.identifier()) - .get_used_exports(), + .old_get_used_exports(), ) } else { None @@ -455,6 +443,35 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { Some(&self.resource_identifier) } + fn get_condition(&self) -> Option { + let id = self.id; + Some(DependencyCondition::Fn(Box::new( + move |_mc, runtime, module_graph: &ModuleGraph| { + let dep = module_graph + .dependency_by_id(&id) + .expect("should have dependency"); + let down_casted_dep = dep + .downcast_ref::() + .expect("should be HarmonyExportImportedSpecifierDependency"); + let mode = down_casted_dep.get_mode( + down_casted_dep.name.clone(), + &down_casted_dep + .ids + .iter() + .map(|id| id.0.clone()) + .collect::>(), + module_graph, + &down_casted_dep.id, + runtime, + ); + ConnectionState::Bool(!matches!( + mode.ty, + ExportModeType::Unused | ExportModeType::EmptyStar + )) + }, + ))) + } + fn get_module_evaluation_side_effects_state( &self, _module_graph: &ModuleGraph, @@ -475,7 +492,7 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { &self.id, runtime, ); - match mode.kind { + match mode.ty { ExportModeType::Missing | ExportModeType::Unused | ExportModeType::EmptyStar @@ -494,7 +511,7 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { &mut referenced_exports, vec![], Some(*partial_namespace_export_info), - mode.kind == ExportModeType::ReexportFakeNamespaceObject, + mode.ty == ExportModeType::ReexportFakeNamespaceObject, &mut Default::default(), ); referenced_exports @@ -528,18 +545,13 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { .map(ExtendedReferencedExport::Array) .collect::>() } - ExportModeType::Unset => { - unreachable!("should not export mode unset"); - } } } } #[allow(unused)] -#[derive(Debug, Default, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq)] pub enum ExportModeType { - #[default] - Unset, Missing, Unused, EmptyStar, @@ -561,17 +573,32 @@ pub struct NormalReexportItem { pub export_info: ExportInfoId, } -#[derive(Debug, Default)] +#[derive(Debug)] pub struct ExportMode { - pub kind: ExportModeType, + /// corresponding to `type` field in webpack's `EpxortMode` + pub ty: ExportModeType, pub items: Option>, pub name: Option, - pub fake_type: Option, + pub fake_type: u8, pub partial_namespace_export_info: Option, pub ignored: Option>, pub hidden: Option>, } +impl ExportMode { + pub fn new(ty: ExportModeType) -> Self { + Self { + ty, + items: None, + name: None, + fake_type: 0, + partial_namespace_export_info: None, + ignored: None, + hidden: None, + } + } +} + #[derive(Debug, Default)] pub struct StarReexportsInfo { exports: Option>, @@ -599,11 +626,13 @@ fn determine_export_assignments( .export_info_map .get(export_info_id) .expect("should have export info"); + // This is safe because a real export can't export empty string + let export_name = export_info.name.clone().unwrap_or_default(); if matches!(export_info.provided, Some(ExportInfoProvided::True)) - && &export_info.name != "default" - && !names.contains(&export_info.name) + && &export_name != "default" + && !names.contains(&export_name) { - names.insert(export_info.name.clone()); + names.insert(export_name.clone()); } } } diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs index fc44da3b8e2..9a53e2d0c2e 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_specifier_dependency.rs @@ -1,7 +1,7 @@ use rspack_core::{ AsModuleDependency, Dependency, DependencyCategory, DependencyId, DependencyTemplate, DependencyType, ExportNameOrSpec, ExportsOfExportsSpec, ExportsSpec, HarmonyExportInitFragment, - TemplateContext, TemplateReplaceSource, + TemplateContext, TemplateReplaceSource, UsedName, }; use swc_core::ecma::atoms::JsWord; @@ -69,8 +69,25 @@ impl DependencyTemplate for HarmonyExportSpecifierDependency { compilation .module_graph .get_exports_info(&module.identifier()) - .get_used_exports() + .old_get_used_exports() .contains(&self.name) + } else if compilation.options.is_new_tree_shaking() { + let exports_info_id = compilation + .module_graph + .get_exports_info(&module.identifier()) + .id; + let used_name = exports_info_id.get_used_name( + &compilation.module_graph, + None, + UsedName::Str(self.name.clone()), + ); + // dbg!(&used_name); + used_name + .map(|item| match item { + UsedName::Str(name) => name == self.name, + UsedName::Vec(vec) => vec.contains(&self.name), + }) + .unwrap_or_default() } else { true }; 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 bf8e91fd756..9b847e9858b 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 @@ -240,21 +240,22 @@ impl ModuleDependency for HarmonyImportDependency { vec![] } - // It's from HarmonyImportSideEffectDependency. - fn get_condition(&self, _module_graph: &ModuleGraph) -> Option { - let id = self.id; - Some(DependencyCondition::Fn(Box::new( - move |_, _, module_graph| { - if let Some(module) = module_graph - .parent_module_by_dependency_id(&id) - .and_then(|module_identifier| module_graph.module_by_identifier(&module_identifier)) - { - module.get_side_effects_connection_state(module_graph, &mut HashSet::default()) - } else { - ConnectionState::Bool(true) - } - }, - ))) + // TODO: It's from HarmonyImportSideEffectDependency. + fn get_condition(&self) -> Option { + None + // let id = self.id; + // Some(DependencyCondition::Fn(Box::new( + // move |_, _, module_graph| { + // if let Some(module) = module_graph + // .parent_module_by_dependency_id(&id) + // .and_then(|module_identifier| module_graph.module_by_identifier(&module_identifier)) + // { + // module.get_side_effects_connection_state(module_graph, &mut HashSet::default()) + // } else { + // ConnectionState::Bool(true) + // } + // }, + // ))) } // It's from HarmonyImportSideEffectDependency. 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 d9d1ca26ae4..6e788f26868 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 @@ -81,12 +81,12 @@ impl HarmonyImportSpecifierDependency { Specifier::Default(_) => compilation .module_graph .get_exports_info(&reference_mgm.module_identifier) - .get_used_exports() + .old_get_used_exports() .contains(&DEFAULT_JS_WORD), Specifier::Named(local, imported) => compilation .module_graph .get_exports_info(&reference_mgm.module_identifier) - .get_used_exports() + .old_get_used_exports() .contains(imported.as_ref().unwrap_or(local)), } } @@ -200,8 +200,8 @@ impl ModuleDependency for HarmonyImportSpecifierDependency { Some(&self.resource_identifier) } - fn get_condition(&self, module_graph: &ModuleGraph) -> Option { - get_dependency_used_by_exports_condition(&self.id, &self.used_by_exports, module_graph) + fn get_condition(&self) -> Option { + get_dependency_used_by_exports_condition(self.id, &self.used_by_exports) } fn get_module_evaluation_side_effects_state( diff --git a/crates/rspack_plugin_javascript/src/dependency/url/mod.rs b/crates/rspack_plugin_javascript/src/dependency/url/mod.rs index 717fbc46a38..5165cbc4db0 100644 --- a/crates/rspack_plugin_javascript/src/dependency/url/mod.rs +++ b/crates/rspack_plugin_javascript/src/dependency/url/mod.rs @@ -1,8 +1,7 @@ use rspack_core::{ get_dependency_used_by_exports_condition, module_id, Dependency, DependencyCategory, DependencyCondition, DependencyId, DependencyTemplate, DependencyType, ErrorSpan, - ModuleDependency, ModuleGraph, RuntimeGlobals, TemplateContext, TemplateReplaceSource, - UsedByExports, + ModuleDependency, RuntimeGlobals, TemplateContext, TemplateReplaceSource, UsedByExports, }; use swc_core::ecma::atoms::JsWord; @@ -60,8 +59,8 @@ impl ModuleDependency for URLDependency { self.request = request.into(); } - fn get_condition(&self, module_graph: &ModuleGraph) -> Option { - get_dependency_used_by_exports_condition(&self.id, &self.used_by_exports, module_graph) + fn get_condition(&self) -> Option { + get_dependency_used_by_exports_condition(self.id, &self.used_by_exports) } } diff --git a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs index 8d15d7c5f2b..d42b4c8f06b 100644 --- a/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/flag_dependency_exports_plugin.rs @@ -199,7 +199,7 @@ impl<'a> FlagDependencyExportsProxy<'a> { .unwrap_or(global_export_info.terminal_binding), spec.exports.as_ref(), if spec.from.is_some() { - spec.from.clone() + spec.from } else { global_export_info.from.cloned() }, 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 f1b8d17f132..ff9f9bfcb7f 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 @@ -68,6 +68,7 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { force_side_effects: bool, q: &mut VecDeque<(ModuleIdentifier, Option)>, ) { + #[derive(Debug, Clone)] enum ProcessModuleReferencedExports { Map(HashMap), ExtendRef(Vec), @@ -84,6 +85,7 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { .module_graph_module_by_identifier(&module_id) .expect("should have module graph module"); let dep_id_list = mgm.dependencies.clone(); + // dbg!(&module_id); for dep_id in dep_id_list.into_iter() { let connection = self .compilation @@ -117,6 +119,12 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { } else { continue; }; + + // dbg!( + // &connection, + // dep.as_module_dependency().unwrap().dependency_type() + // ); + // dbg!(&referenced_exports, &old_referenced_exports); if old_referenced_exports.is_none() || matches!(old_referenced_exports.as_ref().expect("should be some"), ProcessModuleReferencedExports::ExtendRef(v) if is_no_exports_referenced(v)) || is_exports_object_referenced(&referenced_exports) @@ -125,33 +133,30 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { connection.module_identifier, ProcessModuleReferencedExports::ExtendRef(referenced_exports), ); - } else if old_referenced_exports.is_some() && is_no_exports_referenced(&referenced_exports) - { - continue; - } else { - let mut exports_map = if let Some(old_referenced_exports) = old_referenced_exports { - match old_referenced_exports { - ProcessModuleReferencedExports::Map(map) => map, - ProcessModuleReferencedExports::ExtendRef(ref_items) => { - let mut exports_map = HashMap::default(); - for item in ref_items.iter() { - match item { - ExtendedReferencedExport::Array(arr) => { - exports_map.insert(join_jsword(arr, "\n"), item.clone()); - } - ExtendedReferencedExport::Export(export) => { - exports_map.insert(join_jsword(&export.name, "\n"), item.clone()); - } + } else if let Some(old_referenced_exports) = old_referenced_exports { + if is_no_exports_referenced(&referenced_exports) { + map.insert(connection.module_identifier, old_referenced_exports.clone()); + continue; + } + + let mut exports_map = match old_referenced_exports { + ProcessModuleReferencedExports::Map(map) => map, + ProcessModuleReferencedExports::ExtendRef(ref_items) => { + let mut exports_map = HashMap::default(); + for item in ref_items.iter() { + match item { + ExtendedReferencedExport::Array(arr) => { + exports_map.insert(join_jsword(arr, "\n"), item.clone()); + } + ExtendedReferencedExport::Export(export) => { + exports_map.insert(join_jsword(&export.name, "\n"), item.clone()); } } - exports_map } + exports_map } - } else { - // in else branch above old_referenced_exports must be `Some(T)`, use if let Pattern - // just avoid rust clippy complain - unreachable!() }; + for mut item in referenced_exports.into_iter() { match item { ExtendedReferencedExport::Array(ref arr) => { @@ -182,9 +187,16 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { } } } + // dbg!(&exports_map); + map.insert( + connection.module_identifier, + ProcessModuleReferencedExports::Map(exports_map), + ); + } else { } } } + for (module_id, referenced_exports) in map { let normalized_refs = match referenced_exports { ProcessModuleReferencedExports::Map(map) => map.into_values().collect::>(), @@ -303,6 +315,7 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { runtime.as_ref(), ); if changed_flag { + // dbg!(¤t_exports_info_id); let current_module = if current_exports_info_id == mgm_exports_info_id { Some(module_id) } else { @@ -328,9 +341,9 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { { return; } - let flag = mgm_exports_info_id + let changed_flag = mgm_exports_info_id .set_used_for_side_effects_only(&mut self.compilation.module_graph, runtime.as_ref()); - if flag { + if changed_flag { queue.push_back((module_id, runtime)); } } @@ -346,7 +359,6 @@ impl Plugin for FlagDependencyUsagePlugin { // TODO: `global` is always `true`, until we finished runtime optimization. let mut proxy = FlagDependencyUsagePluginProxy::new(true, compilation); proxy.apply(); - println!("optimize_dependencies"); Ok(None) } } diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_import_dependency_scanner.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_import_dependency_scanner.rs index 141df218b50..65c2c0a9997 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_import_dependency_scanner.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_import_dependency_scanner.rs @@ -259,6 +259,14 @@ impl Visit for HarmonyImportDependencyScanner<'_> { fn visit_export_all(&mut self, export_all: &ExportAll) { let key = (export_all.src.value.clone(), DependencyType::EsmExport); + + // self + // .dependencies + // .push(Box::new(HarmonyExportImportedSpecifierDependency::new( + // key.0.clone(), + // vec![], + // None, + // ))); if let Some(importer_info) = self.imports.get_mut(&key) { importer_info.exports_all = true; } else { @@ -266,6 +274,7 @@ impl Visit for HarmonyImportDependencyScanner<'_> { .imports .insert(key, ImporterInfo::new(export_all.span, vec![], true)); } + self .presentational_dependencies .push(Box::new(ConstDependency::new( diff --git a/crates/rspack_testing/src/run_fixture.rs b/crates/rspack_testing/src/run_fixture.rs index c4b0279495f..0b137def679 100644 --- a/crates/rspack_testing/src/run_fixture.rs +++ b/crates/rspack_testing/src/run_fixture.rs @@ -11,7 +11,7 @@ use rspack_tracing::enable_tracing_by_env; use crate::{eval_raw::evaluate_to_json, test_config::TestConfig}; -pub type MutTestOptionsFn = dyn FnMut(&mut Settings, &mut CompilerOptions); +pub type MutTestOptionsFn = dyn FnMut(&mut Vec, &mut CompilerOptions); pub fn apply_from_fixture(fixture_path: &Path) -> (CompilerOptions, Vec) { let js_config = fixture_path.join("test.config.js"); @@ -106,9 +106,10 @@ pub async fn test_fixture_share( settings.set_omit_expression(true); settings.set_prepend_module_to_snapshot(false); - let (mut options, plugins) = apply_from_fixture(fixture_path); + let (mut options, mut plugins) = apply_from_fixture(fixture_path); + + mut_settings(&mut plugins, &mut options); - mut_settings(&mut settings, &mut options); // clean output if options.output.path.exists() { std::fs::remove_dir_all(&options.output.path).expect("should remove output"); diff --git a/crates/rspack_testing/src/test_config.rs b/crates/rspack_testing/src/test_config.rs index dc2a8bf5705..21ff49c894a 100644 --- a/crates/rspack_testing/src/test_config.rs +++ b/crates/rspack_testing/src/test_config.rs @@ -470,6 +470,7 @@ impl TestConfig { plugins .push(rspack_plugin_dev_friendly_split_chunks::DevFriendlySplitChunksPlugin::new().boxed()); } + for html in self.builtins.html { plugins.push(rspack_plugin_html::HtmlRspackPlugin::new(html).boxed()); } diff --git a/crates/rspack_testing/test.config.scheme.json b/crates/rspack_testing/test.config.scheme.json index 539757d2b2d..24c028270c8 100644 --- a/crates/rspack_testing/test.config.scheme.json +++ b/crates/rspack_testing/test.config.scheme.json @@ -76,7 +76,7 @@ "html": { "type": "array", "items": { - "$ref": "#/definitions/HtmlPluginConfig" + "$ref": "#/definitions/HtmlRspackPluginOptions" } }, "minifyOptions": { @@ -89,9 +89,6 @@ } ] }, - "postcss": { - "$ref": "#/definitions/Postcss" - }, "presetEnv": { "anyOf": [ { @@ -113,8 +110,8 @@ } }, "treeShaking": { - "default": false, - "type": "boolean" + "default": "false", + "type": "string" } }, "additionalProperties": false @@ -172,7 +169,15 @@ }, "additionalProperties": false }, - "HtmlPluginConfig": { + "HtmlInject": { + "type": "string", + "enum": [ + "head", + "body", + "false" + ] + }, + "HtmlRspackPluginOptions": { "type": "object", "properties": { "chunks": { @@ -206,13 +211,10 @@ "type": "string" }, "inject": { - "description": "`head`, `body` or None", - "anyOf": [ - { - "$ref": "#/definitions/HtmlPluginConfigInject" - }, + "description": "`head`, `body`, `false`", + "allOf": [ { - "type": "null" + "$ref": "#/definitions/HtmlInject" } ] }, @@ -243,7 +245,7 @@ "description": "`blocking`, `defer`, or `module`", "allOf": [ { - "$ref": "#/definitions/HtmlPluginConfigScriptLoading" + "$ref": "#/definitions/HtmlScriptLoading" } ] }, @@ -289,14 +291,7 @@ }, "additionalProperties": false }, - "HtmlPluginConfigInject": { - "type": "string", - "enum": [ - "head", - "body" - ] - }, - "HtmlPluginConfigScriptLoading": { + "HtmlScriptLoading": { "type": "string", "enum": [ "blocking", @@ -346,14 +341,6 @@ "default": false, "type": "boolean" }, - "keepClassNames": { - "default": false, - "type": "boolean" - }, - "keepFnNames": { - "default": false, - "type": "boolean" - }, "extractComments": { "default": null, "type": [ @@ -451,17 +438,33 @@ "Optimization": { "type": "object", "properties": { + "chunkIds": { + "default": "named", + "type": "string" + }, "moduleIds": { "default": "named", "type": "string" }, + "providedExports": { + "default": true, + "type": "boolean" + }, "removeAvailableModules": { "default": true, "type": "boolean" }, + "removeEmptyChunks": { + "default": true, + "type": "boolean" + }, "sideEffects": { "default": "false", "type": "string" + }, + "usedExports": { + "default": "false", + "type": "string" } }, "additionalProperties": false @@ -470,7 +473,7 @@ "type": "object", "properties": { "chunkFilename": { - "default": "[name][ext]", + "default": "[name].js", "type": "string" }, "clean": { @@ -478,15 +481,15 @@ "type": "boolean" }, "cssChunkFilename": { - "default": "[name][ext]", + "default": "[name].css", "type": "string" }, "cssFilename": { - "default": "[name][ext]", + "default": "[name].css", "type": "string" }, "filename": { - "default": "[name][ext]", + "default": "[name].js", "type": "string" }, "library": { @@ -504,28 +507,12 @@ "type": "string" }, "sourceMapFilename": { - "default": "[name][ext]", + "default": "[file].map", "type": "string" } }, "additionalProperties": false }, - "Postcss": { - "type": "object", - "properties": { - "pxtorem": { - "anyOf": [ - { - "$ref": "#/definitions/PxToRem" - }, - { - "type": "null" - } - ] - } - }, - "additionalProperties": false - }, "PresetEnv": { "type": "object", "required": [ @@ -553,72 +540,6 @@ }, "additionalProperties": false }, - "PxToRem": { - "type": "object", - "properties": { - "mediaQuery": { - "default": null, - "type": [ - "boolean", - "null" - ] - }, - "minPixelValue": { - "default": null, - "type": [ - "number", - "null" - ], - "format": "double" - }, - "propList": { - "default": null, - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - }, - "replace": { - "default": null, - "type": [ - "boolean", - "null" - ] - }, - "rootValue": { - "default": null, - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0.0 - }, - "selectorBlackList": { - "default": null, - "type": [ - "array", - "null" - ], - "items": { - "type": "string" - } - }, - "unitPrecision": { - "default": null, - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, "Rule": { "type": "object", "properties": {