From 19a2ec3f089a259f7bbf3d111f6d8a186d32f7fc Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Mon, 18 Sep 2023 19:52:30 +0800 Subject: [PATCH 01/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/parser_and_generator/mod.rs | 14 ++ .../src/plugin/side_effects_flag_plugin.rs | 121 +++++++++--------- 2 files changed, 75 insertions(+), 60 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index 11bda0fcc56..c0aa5cd0522 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -10,9 +10,11 @@ use rspack_core::{ ParserAndGenerator, SourceType, TemplateContext, }; use rspack_error::{internal_error, IntoTWithDiagnosticArray, Result, TWithDiagnosticArray}; +use swc_core::common::SyntaxContext; use crate::utils::syntax_by_module_type; use crate::visitors::{run_before_pass, scan_dependencies, swc_visitor::resolver}; +use crate::{SideEffectsFlagPluginVisitor, SyntaxContextInfo}; #[derive(Debug)] pub struct JavaScriptParserAndGenerator; @@ -144,6 +146,18 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { OptimizeAnalyzeResult::default() }; + if compiler_options.is_new_tree_shaking() + && compiler_options.optimization.side_effects.is_true() + { + ast.transform(|program, context| { + let unresolved_ctxt = SyntaxContext::empty().apply_mark(context.unresolved_mark); + let mut visitor = + SideEffectsFlagPluginVisitor::new(SyntaxContextInfo::new(unresolved_ctxt)); + program.visit_with(&mut visitor); + build_meta.side_effect_free = Some(visitor.side_effects_span.is_none()); + }); + } + let source = if let Some(map) = output.map { SourceMapSource::new(SourceMapSourceOptions { value: output.code, diff --git a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs index cd00c175af2..b660ae69c38 100644 --- a/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs +++ b/crates/rspack_plugin_javascript/src/plugin/side_effects_flag_plugin.rs @@ -8,7 +8,7 @@ use swc_core::ecma::visit::{noop_visit_type, Visit, VisitWith}; #[derive(Debug)] pub struct SideEffectsFlagPluginVisitor { unresolved_ctxt: SyntaxContext, - side_effects_span: Option, + pub side_effects_span: Option, is_top_level: bool, } @@ -99,77 +99,78 @@ impl SideEffectsFlagPluginVisitor { /// If we find a stmt that has side effects, we will skip the rest of the stmts. /// And mark the module as having side effects. fn analyze_stmt_side_effects(&mut self, ele: &Stmt) { - if self.side_effects_span.is_none() { - match ele { - Stmt::If(stmt) => { - if !is_pure_expression(&stmt.test, self.unresolved_ctxt) { - self.side_effects_span = Some(stmt.span); - } + if self.side_effects_span.is_some() { + return; + } + match ele { + Stmt::If(stmt) => { + if !is_pure_expression(&stmt.test, self.unresolved_ctxt) { + self.side_effects_span = Some(stmt.span); } - Stmt::While(stmt) => { - if !is_pure_expression(&stmt.test, self.unresolved_ctxt) { - self.side_effects_span = Some(stmt.span); - } + } + Stmt::While(stmt) => { + if !is_pure_expression(&stmt.test, self.unresolved_ctxt) { + self.side_effects_span = Some(stmt.span); } - Stmt::DoWhile(stmt) => { - if !is_pure_expression(&stmt.test, self.unresolved_ctxt) { - self.side_effects_span = Some(stmt.span); - } + } + Stmt::DoWhile(stmt) => { + if !is_pure_expression(&stmt.test, self.unresolved_ctxt) { + self.side_effects_span = Some(stmt.span); } - Stmt::For(stmt) => { - let pure_init = match stmt.init { - Some(ref init) => match init { - VarDeclOrExpr::VarDecl(decl) => is_pure_var_decl(decl, self.unresolved_ctxt), - VarDeclOrExpr::Expr(expr) => is_pure_expression(expr, self.unresolved_ctxt), - }, - None => true, - }; + } + Stmt::For(stmt) => { + let pure_init = match stmt.init { + Some(ref init) => match init { + VarDeclOrExpr::VarDecl(decl) => is_pure_var_decl(decl, self.unresolved_ctxt), + VarDeclOrExpr::Expr(expr) => is_pure_expression(expr, self.unresolved_ctxt), + }, + None => true, + }; - if !pure_init { - self.side_effects_span = Some(stmt.span); - return; - } + if !pure_init { + self.side_effects_span = Some(stmt.span); + return; + } - let pure_test = match stmt.test { - Some(box ref test) => is_pure_expression(test, self.unresolved_ctxt), - None => true, - }; + let pure_test = match stmt.test { + Some(box ref test) => is_pure_expression(test, self.unresolved_ctxt), + None => true, + }; - if !pure_test { - self.side_effects_span = Some(stmt.span); - return; - } + if !pure_test { + self.side_effects_span = Some(stmt.span); + return; + } - let pure_update = match stmt.update { - Some(ref expr) => is_pure_expression(expr, self.unresolved_ctxt), - None => true, - }; + let pure_update = match stmt.update { + Some(ref expr) => is_pure_expression(expr, self.unresolved_ctxt), + None => true, + }; - if !pure_update { - self.side_effects_span = Some(stmt.span); - } + if !pure_update { + self.side_effects_span = Some(stmt.span); } - Stmt::Expr(stmt) => { - if !is_pure_expression(&stmt.expr, self.unresolved_ctxt) { - self.side_effects_span = Some(stmt.span); - } + } + Stmt::Expr(stmt) => { + if !is_pure_expression(&stmt.expr, self.unresolved_ctxt) { + self.side_effects_span = Some(stmt.span); } - Stmt::Switch(stmt) => { - if !is_pure_expression(&stmt.discriminant, self.unresolved_ctxt) { - self.side_effects_span = Some(stmt.span); - } + } + Stmt::Switch(stmt) => { + if !is_pure_expression(&stmt.discriminant, self.unresolved_ctxt) { + self.side_effects_span = Some(stmt.span); } - Stmt::Decl(stmt) => { - if !is_pure_decl(stmt, self.unresolved_ctxt) { - self.side_effects_span = Some(stmt.span()); - } + } + Stmt::Decl(stmt) => { + if !is_pure_decl(stmt, self.unresolved_ctxt) { + self.side_effects_span = Some(stmt.span()); } - Stmt::Empty(_) => {} - Stmt::Labeled(_) => {} - Stmt::Block(_) => {} - _ => self.side_effects_span = Some(ele.span()), - }; - } + } + Stmt::Empty(_) => {} + Stmt::Labeled(_) => {} + Stmt::Block(_) => {} + _ => self.side_effects_span = Some(ele.span()), + }; } } From d45cf9383d0d241dea6aec780f3d00da58b4b65f Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Mon, 18 Sep 2023 21:48:29 +0800 Subject: [PATCH 02/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20opt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/fixtures.rs | 2 +- crates/rspack/tests/tree-shaking/bb/a.js | 11 +++---- .../bb/snapshot/new_treeshaking.snap | 22 ++++++-------- .../tests/tree-shaking/bb/snapshot/snap.diff | 12 +++++++- .../src/chunk_graph/chunk_graph_chunk.rs | 17 +++++++---- crates/rspack_core/src/chunk_graph/mod.rs | 2 +- .../rspack_core/src/compiler/compilation.rs | 11 +++++-- crates/rspack_core/src/module_graph_module.rs | 29 +++++++++++++++++-- 8 files changed, 74 insertions(+), 32 deletions(-) diff --git a/crates/rspack/tests/fixtures.rs b/crates/rspack/tests/fixtures.rs index 17fe026b90f..10297c6b27a 100644 --- a/crates/rspack/tests/fixtures.rs +++ b/crates/rspack/tests/fixtures.rs @@ -24,7 +24,7 @@ fn samples(fixture_path: PathBuf) { fn tree_shaking(fixture_path: PathBuf) { // For each test case // First test is old version tree shaking snapshot test - test_fixture(&fixture_path, Box::new(|_, _| {}), None); + // test_fixture(&fixture_path, Box::new(|_, _| {}), None); // second test is webpack based tree shaking test_fixture( &fixture_path, diff --git a/crates/rspack/tests/tree-shaking/bb/a.js b/crates/rspack/tests/tree-shaking/bb/a.js index fee8526f563..dbd131df79b 100644 --- a/crates/rspack/tests/tree-shaking/bb/a.js +++ b/crates/rspack/tests/tree-shaking/bb/a.js @@ -1,6 +1,7 @@ -import { d, c } from "./b.js"; +// import { d, c } from "./b.js"; export * from "./c.js"; -export const a = 3; - -d; -export { c }; +export * from './b.js' +// export const a = 3; +// +// d; +// export { c }; 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 47d7edd5c33..aa334162ff8 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -6,24 +6,20 @@ 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 _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__); - - - const a = 3; -_b_js__WEBPACK_IMPORTED_MODULE_0_.d; +/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); +__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); +__webpack_require__.es(_b_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +// import { d, c } from "./b.js"; + // export const a = 3; + // + // d; + // export { c }; }, "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'd': function() { return d; } -}); const d = 3; const c = 100; }, diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index e652df29d17..098d71717c6 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -6,6 +6,9 @@ +@@ -6,30 +6,26 @@ "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -10,3 +10,13 @@ /* 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__); +@@ -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__, { +- 'ccc': function() { return ccc; } +-}); + const ccc = 30; + }, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { diff --git a/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs b/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs index 04ca683d74a..8c749485f2e 100644 --- a/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs +++ b/crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs @@ -297,11 +297,18 @@ impl ChunkGraph { .module_by_identifier(&module) .expect("should exist"); for connection in module_graph.get_outgoing_connections(module) { - // TODO: consider activeState - // if (activeState === ModuleGraphConnection.TRANSITIVE_ONLY) { - // add_dependencies(connection.module_identifier, set, module_graph); - // continue; - // } + // TODO: add runtime after runtime opt + let active_state = connection.get_active_state(module_graph, None); + match active_state { + crate::ConnectionState::Bool(false) => { + continue; + } + crate::ConnectionState::TransitiveOnly => { + add_dependencies(connection.module_identifier, set, module_graph); + continue; + } + _ => {} + } set.insert(connection.module_identifier); } } diff --git a/crates/rspack_core/src/chunk_graph/mod.rs b/crates/rspack_core/src/chunk_graph/mod.rs index 3d7f9c7fdeb..156c0f1b6ea 100644 --- a/crates/rspack_core/src/chunk_graph/mod.rs +++ b/crates/rspack_core/src/chunk_graph/mod.rs @@ -1,7 +1,7 @@ use rspack_identifier::IdentifierMap; use rustc_hash::FxHashMap as HashMap; -use crate::{ChunkGroupUkey, ChunkUkey}; +use crate::{ChunkGroupUkey, ChunkUkey, CompilerOptions}; pub mod chunk_graph_chunk; pub mod chunk_graph_module; diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 70b767e28c1..131d29d5e1d 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -1158,9 +1158,14 @@ 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); - // } + if self.options.is_new_tree_shaking() { + // self + // .module_graph + // .module_graph_modules() + // .values() + // .foreach(|item| {}); + // debug_exports_info(&self.module_graph); + } let start = logger.time("create chunks"); use_code_splitting_cache(self, |compilation| async { diff --git a/crates/rspack_core/src/module_graph_module.rs b/crates/rspack_core/src/module_graph_module.rs index a1bbfb89290..3a67e765c41 100644 --- a/crates/rspack_core/src/module_graph_module.rs +++ b/crates/rspack_core/src/module_graph_module.rs @@ -124,8 +124,16 @@ impl ModuleGraphModule { pub fn depended_modules<'a>(&self, module_graph: &'a ModuleGraph) -> Vec<&'a ModuleIdentifier> { self - .dependencies - .iter() + .outgoing_connections_unordered(module_graph) + .unwrap() + .filter_map(|con: &ModuleGraphConnection| { + // TODO: runtime opt + let active_state = con.get_active_state(module_graph, None); + match active_state { + crate::ConnectionState::Bool(false) => None, + _ => Some(con.dependency_id), + } + }) .filter(|id| { if let Some(dep) = module_graph .dependency_by_id(id) @@ -136,8 +144,23 @@ impl ModuleGraphModule { } false }) - .filter_map(|id| module_graph.module_identifier_by_dependency_id(id)) + .filter_map(|id| module_graph.module_identifier_by_dependency_id(&id)) .collect() + // self + // .dependencies + // .iter() + // .filter(|id| { + // if let Some(dep) = module_graph + // .dependency_by_id(id) + // .expect("should have id") + // .as_module_dependency() + // { + // return !is_async_dependency(dep) && !dep.weak(); + // } + // false + // }) + // .filter_map(|id| module_graph.module_identifier_by_dependency_id(id)) + // .collect() } pub fn dynamic_depended_modules<'a>( From 3440ee593b22c5bfade96a2a0cd608a717667328 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Mon, 18 Sep 2023 17:38:00 +0800 Subject: [PATCH 03/24] chore: more tree shaking test2 (#4208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 🤖 add export all star * chore: 🤖 snapshot * chore: 🤖 update snapshot * chore: 🤖 update snap * chore: 🤖 lint * chore: 🤖 lint * chore: 🤖 temp use wrong star list --- .../tests/tree-shaking/bb/snapshot/snap.diff | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index 098d71717c6..1e24850c6c1 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -4,13 +4,33 @@ "./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 _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__); -@@ -27,9 +30,6 @@ +-/* 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__); ++/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); ++__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); ++/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); ++__webpack_require__.es(_b_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); ++// import { d, c } from "./b.js"; + +- +- const a = 3; +-_b_js__WEBPACK_IMPORTED_MODULE_0_.d; +- ++ // export const a = 3; ++ // ++ // d; ++ // export { c }; + }, + "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'd': function() { return d; } +-}); + const d = 3; + const c = 100; + }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); From 37f7012c79b6f6dce68997353db676e5d46eed6a Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Mon, 18 Sep 2023 23:25:35 +0800 Subject: [PATCH 04/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20side=20e?= =?UTF-8?q?ffects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/tree-shaking/bb/c.js | 2 +- .../rspack/tests/tree-shaking/bb/package.json | 3 +- .../bb/snapshot/new_treeshaking.snap | 8 +--- .../tests/tree-shaking/bb/snapshot/snap.diff | 37 ++++++++----------- .../rspack_core/src/compiler/compilation.rs | 8 ++++ crates/rspack_core/src/dependency/mod.rs | 4 ++ crates/rspack_core/src/module_graph_module.rs | 8 +++- crates/rspack_core/src/normal_module.rs | 4 +- .../esm/harmony_import_dependency.rs | 31 +++++++++------- 9 files changed, 58 insertions(+), 47 deletions(-) diff --git a/crates/rspack/tests/tree-shaking/bb/c.js b/crates/rspack/tests/tree-shaking/bb/c.js index 2f351adf71c..21febfe8994 100644 --- a/crates/rspack/tests/tree-shaking/bb/c.js +++ b/crates/rspack/tests/tree-shaking/bb/c.js @@ -1 +1 @@ -export const ccc = 30; \ No newline at end of file +export const ccc = 30; diff --git a/crates/rspack/tests/tree-shaking/bb/package.json b/crates/rspack/tests/tree-shaking/bb/package.json index 7a73a41bfdf..3802144dedb 100644 --- a/crates/rspack/tests/tree-shaking/bb/package.json +++ b/crates/rspack/tests/tree-shaking/bb/package.json @@ -1,2 +1,3 @@ { -} \ No newline at end of file + "sideEffects": true +} 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 aa334162ff8..311f3555af4 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -8,7 +8,7 @@ source: crates/rspack_testing/src/run_fixture.rs __webpack_require__.r(__webpack_exports__); /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); __webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); +/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './b.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_b_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); // import { d, c } from "./b.js"; @@ -17,12 +17,6 @@ __webpack_require__.es(_b_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); // d; // export { c }; }, -"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const d = 3; - const c = 100; -}, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index 1e24850c6c1..e8b9ffa4e2a 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -1,42 +1,35 @@ --- expected +++ actual -@@ -6,30 +6,26 @@ +@@ -6,23 +6,16 @@ "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./c.js */"./c.js"); -__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- +- +- const a = 3; +-_b_js__WEBPACK_IMPORTED_MODULE_0_.d; +/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); +__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -+/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); ++/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './b.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +__webpack_require__.es(_b_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +// import { d, c } from "./b.js"; -- -- const a = 3; --_b_js__WEBPACK_IMPORTED_MODULE_0_.d; -- +-}, +-"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'd': function() { return d; } +-}); +- const d = 3; +- const c = 100; + // export const a = 3; + // + // d; + // export { c }; }, - "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); --__webpack_require__.d(__webpack_exports__, { -- 'd': function() { return d; } --}); - const d = 3; - const c = 100; - }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; - __webpack_require__.r(__webpack_exports__); --__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_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 131d29d5e1d..8eefba1f84f 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -1159,6 +1159,14 @@ impl Compilation { logger.time_end(start); if self.options.is_new_tree_shaking() { + for module in self.module_graph.module_graph_modules().values() { + dbg!(&module.module_identifier); + dbg!(&module + .factory_meta + .as_ref() + .map(|item| item.side_effect_free)); + dbg!(&module.build_meta.as_ref().map(|item| item.side_effect_free)); + } // self // .module_graph // .module_graph_modules() diff --git a/crates/rspack_core/src/dependency/mod.rs b/crates/rspack_core/src/dependency/mod.rs index 25798baf4ba..656a8272c9d 100644 --- a/crates/rspack_core/src/dependency/mod.rs +++ b/crates/rspack_core/src/dependency/mod.rs @@ -388,6 +388,10 @@ pub trait ModuleDependency: Dependency { fn resource_identifier(&self) -> Option<&str> { None } + + fn is_export_all(&self) -> bool { + false + } } impl dyn Dependency + '_ { diff --git a/crates/rspack_core/src/module_graph_module.rs b/crates/rspack_core/src/module_graph_module.rs index 3a67e765c41..a809dbbb796 100644 --- a/crates/rspack_core/src/module_graph_module.rs +++ b/crates/rspack_core/src/module_graph_module.rs @@ -123,12 +123,18 @@ impl ModuleGraphModule { // } pub fn depended_modules<'a>(&self, module_graph: &'a ModuleGraph) -> Vec<&'a ModuleIdentifier> { + dbg!(&self.module_identifier); self .outgoing_connections_unordered(module_graph) .unwrap() .filter_map(|con: &ModuleGraphConnection| { // TODO: runtime opt let active_state = con.get_active_state(module_graph, None); + dbg!(&con, &active_state,); + dbg!(&module_graph + .dependency_by_id(&con.dependency_id) + .and_then(|dep| dep.as_module_dependency())) + .map(|item| item.dependency_type()); match active_state { crate::ConnectionState::Bool(false) => None, _ => Some(con.dependency_id), @@ -140,7 +146,7 @@ impl ModuleGraphModule { .expect("should have id") .as_module_dependency() { - return !is_async_dependency(dep) && !dep.weak(); + return !is_async_dependency(dep) && !dep.weak() && !dep.is_export_all(); } false }) diff --git a/crates/rspack_core/src/normal_module.rs b/crates/rspack_core/src/normal_module.rs index edab59323ad..d1411845e6e 100644 --- a/crates/rspack_core/src/normal_module.rs +++ b/crates/rspack_core/src/normal_module.rs @@ -511,12 +511,14 @@ impl Module for NormalModule { let state = dependency.get_module_evaluation_side_effects_state(module_graph, module_chain); if matches!(state, ConnectionState::Bool(true)) { // TODO add optimization bailout + module_chain.remove(&self.identifier()); return ConnectionState::Bool(true); - } else if matches!(state, ConnectionState::CircularConnection) { + } else if !matches!(state, ConnectionState::CircularConnection) { current = add_connection_states(current, state); } } } + module_chain.remove(&self.identifier()); return current; } } 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 9b847e9858b..9d7b447cb81 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 @@ -212,6 +212,10 @@ impl Dependency for HarmonyImportDependency { } impl ModuleDependency for HarmonyImportDependency { + fn is_export_all(&self) -> bool { + self.export_all + } + fn request(&self) -> &str { &self.request } @@ -242,20 +246,19 @@ impl ModuleDependency for HarmonyImportDependency { // 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) - // } - // }, - // ))) + let id = self.id; + Some(DependencyCondition::Fn(Box::new( + move |_, _, module_graph: &ModuleGraph| { + 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. From cb497c3585dda584c12e3391fd079719909609e0 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 14:24:41 +0800 Subject: [PATCH 05/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20ck=20poing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rspack/tests/tree-shaking/bb/package.json | 1 - .../bb/snapshot/new_treeshaking.snap.new | 41 +++++++++++++++++++ .../rspack_core/src/compiler/compilation.rs | 9 +--- .../dependency/context_element_dependency.rs | 4 ++ crates/rspack_core/src/dependency/entry.rs | 4 ++ crates/rspack_core/src/dependency/mod.rs | 2 + crates/rspack_core/src/module_graph_module.rs | 5 ++- .../src/dependency/compose.rs | 4 ++ .../src/dependency/import.rs | 4 ++ .../rspack_plugin_css/src/dependency/url.rs | 4 ++ .../commonjs/common_js_require_dependency.rs | 4 ++ .../commonjs/require_resolve_dependency.rs | 4 ++ .../common_js_require_context_dependency.rs | 4 ++ .../context/import_context_dependency.rs | 4 ++ .../context/require_context_dependency.rs | 4 ++ ...ny_export_imported_specifier_dependency.rs | 4 ++ .../esm/harmony_import_dependency.rs | 23 +++++++---- .../harmony_import_specifier_dependency.rs | 4 ++ .../src/dependency/esm/import_dependency.rs | 4 ++ .../dependency/hmr/import_meta_hot_accept.rs | 4 ++ .../dependency/hmr/import_meta_hot_decline.rs | 4 ++ .../src/dependency/hmr/module_hot_accept.rs | 4 ++ .../src/dependency/hmr/module_hot_decline.rs | 4 ++ .../src/dependency/url/mod.rs | 4 ++ .../src/dependency/worker/mod.rs | 4 ++ crates/rspack_plugin_wasm/src/dependency.rs | 4 ++ 26 files changed, 143 insertions(+), 18 deletions(-) create mode 100644 crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap.new diff --git a/crates/rspack/tests/tree-shaking/bb/package.json b/crates/rspack/tests/tree-shaking/bb/package.json index 3802144dedb..2c63c085104 100644 --- a/crates/rspack/tests/tree-shaking/bb/package.json +++ b/crates/rspack/tests/tree-shaking/bb/package.json @@ -1,3 +1,2 @@ { - "sideEffects": true } diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap.new b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap.new new file mode 100644 index 00000000000..172ab0000b9 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap.new @@ -0,0 +1,41 @@ +--- +source: crates/rspack_testing/src/run_fixture.rs +assertion_line: 146 +--- +```js title=main.js +(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); +/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './b.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +// import { d, c } from "./b.js"; + + // export const a = 3; + // + // d; + // export { c }; +}, +"./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__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); + +_a_js__WEBPACK_IMPORTED_MODULE_0_.ccc; +}, + +},function(__webpack_require__) { +var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } +var __webpack_exports__ = (__webpack_exec__("./index.js")); + +} +]); +``` diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index 8eefba1f84f..b55f9cf7eb7 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -1159,14 +1159,7 @@ impl Compilation { logger.time_end(start); if self.options.is_new_tree_shaking() { - for module in self.module_graph.module_graph_modules().values() { - dbg!(&module.module_identifier); - dbg!(&module - .factory_meta - .as_ref() - .map(|item| item.side_effect_free)); - dbg!(&module.build_meta.as_ref().map(|item| item.side_effect_free)); - } + for module in self.module_graph.module_graph_modules().values() {} // self // .module_graph // .module_graph_modules() diff --git a/crates/rspack_core/src/dependency/context_element_dependency.rs b/crates/rspack_core/src/dependency/context_element_dependency.rs index 5c05084d12d..45074be4ee7 100644 --- a/crates/rspack_core/src/dependency/context_element_dependency.rs +++ b/crates/rspack_core/src/dependency/context_element_dependency.rs @@ -80,6 +80,10 @@ impl ModuleDependency for ContextElementDependency { vec![ExtendedReferencedExport::Array(vec![])] } } + + fn dependency_debug_name(&self) -> &'static str { + "ContextElementDependency" + } } impl AsDependencyTemplate for ContextElementDependency {} diff --git a/crates/rspack_core/src/dependency/entry.rs b/crates/rspack_core/src/dependency/entry.rs index d8379b2649d..81ea7345cb1 100644 --- a/crates/rspack_core/src/dependency/entry.rs +++ b/crates/rspack_core/src/dependency/entry.rs @@ -54,6 +54,10 @@ impl ModuleDependency for EntryDependency { fn set_request(&mut self, request: String) { self.request = request; } + + fn dependency_debug_name(&self) -> &'static str { + "EntryDependency" + } } impl AsDependencyTemplate for EntryDependency {} diff --git a/crates/rspack_core/src/dependency/mod.rs b/crates/rspack_core/src/dependency/mod.rs index 656a8272c9d..33af0dc19af 100644 --- a/crates/rspack_core/src/dependency/mod.rs +++ b/crates/rspack_core/src/dependency/mod.rs @@ -343,6 +343,8 @@ impl Debug for DependencyCondition { } pub trait ModuleDependency: Dependency { + /// name of the original struct or enum + fn dependency_debug_name(&self) -> &'static str; fn request(&self) -> &str; fn user_request(&self) -> &str; fn span(&self) -> Option<&ErrorSpan>; diff --git a/crates/rspack_core/src/module_graph_module.rs b/crates/rspack_core/src/module_graph_module.rs index a809dbbb796..bbc7998bc27 100644 --- a/crates/rspack_core/src/module_graph_module.rs +++ b/crates/rspack_core/src/module_graph_module.rs @@ -133,8 +133,9 @@ impl ModuleGraphModule { dbg!(&con, &active_state,); dbg!(&module_graph .dependency_by_id(&con.dependency_id) - .and_then(|dep| dep.as_module_dependency())) - .map(|item| item.dependency_type()); + .and_then(|dep| dep + .as_module_dependency() + .map(|item| item.dependency_debug_name()))); match active_state { crate::ConnectionState::Bool(false) => None, _ => Some(con.dependency_id), diff --git a/crates/rspack_plugin_css/src/dependency/compose.rs b/crates/rspack_plugin_css/src/dependency/compose.rs index 2cd9659f98f..ce6c0c5c9e6 100644 --- a/crates/rspack_plugin_css/src/dependency/compose.rs +++ b/crates/rspack_plugin_css/src/dependency/compose.rs @@ -50,6 +50,10 @@ impl ModuleDependency for CssComposeDependency { fn set_request(&mut self, request: String) { self.request = request; } + + fn dependency_debug_name(&self) -> &'static str { + "CssComposeDependency" + } } impl AsDependencyTemplate for CssComposeDependency {} diff --git a/crates/rspack_plugin_css/src/dependency/import.rs b/crates/rspack_plugin_css/src/dependency/import.rs index 0c5fb74cc24..35463bdff55 100644 --- a/crates/rspack_plugin_css/src/dependency/import.rs +++ b/crates/rspack_plugin_css/src/dependency/import.rs @@ -54,6 +54,10 @@ impl ModuleDependency for CssImportDependency { fn set_request(&mut self, request: String) { self.request = request; } + + fn dependency_debug_name(&self) -> &'static str { + "CssImportDependency" + } } impl DependencyTemplate for CssImportDependency { diff --git a/crates/rspack_plugin_css/src/dependency/url.rs b/crates/rspack_plugin_css/src/dependency/url.rs index 75db055930a..800f4c989af 100644 --- a/crates/rspack_plugin_css/src/dependency/url.rs +++ b/crates/rspack_plugin_css/src/dependency/url.rs @@ -86,6 +86,10 @@ impl ModuleDependency for CssUrlDependency { fn set_request(&mut self, request: String) { self.request = request; } + + fn dependency_debug_name(&self) -> &'static str { + "CssUrlDependency" + } } impl DependencyTemplate for CssUrlDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_require_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_require_dependency.rs index 406ffd3ead3..4313771b6df 100644 --- a/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_require_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_require_dependency.rs @@ -68,6 +68,10 @@ impl ModuleDependency for CommonJsRequireDependency { fn set_request(&mut self, request: String) { self.request = request.into(); } + + fn dependency_debug_name(&self) -> &'static str { + "CommonJsRequireDependency" + } } impl DependencyTemplate for CommonJsRequireDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/commonjs/require_resolve_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/commonjs/require_resolve_dependency.rs index 678d36cacfe..60b56d9fc55 100644 --- a/crates/rspack_plugin_javascript/src/dependency/commonjs/require_resolve_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/commonjs/require_resolve_dependency.rs @@ -86,6 +86,10 @@ impl ModuleDependency for RequireResolveDependency { ) -> Vec { vec![] } + + fn dependency_debug_name(&self) -> &'static str { + "RequireResolveDependency" + } } impl DependencyTemplate for RequireResolveDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/context/common_js_require_context_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/context/common_js_require_context_dependency.rs index ae113cd9906..c9723ffe0a4 100644 --- a/crates/rspack_plugin_javascript/src/dependency/context/common_js_require_context_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/context/common_js_require_context_dependency.rs @@ -74,6 +74,10 @@ impl ModuleDependency for CommonJsRequireContextDependency { fn resource_identifier(&self) -> Option<&str> { Some(&self.resource_identifier) } + + fn dependency_debug_name(&self) -> &'static str { + "CommonJsRequireContextDependency" + } } impl DependencyTemplate for CommonJsRequireContextDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/context/import_context_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/context/import_context_dependency.rs index 8e10e1e4c78..a2f74d2df0f 100644 --- a/crates/rspack_plugin_javascript/src/dependency/context/import_context_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/context/import_context_dependency.rs @@ -74,6 +74,10 @@ impl ModuleDependency for ImportContextDependency { fn resource_identifier(&self) -> Option<&str> { Some(&self.resource_identifier) } + + fn dependency_debug_name(&self) -> &'static str { + "ImportContextDependency" + } } impl DependencyTemplate for ImportContextDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/context/require_context_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/context/require_context_dependency.rs index a400d175d3a..94d8e95b479 100644 --- a/crates/rspack_plugin_javascript/src/dependency/context/require_context_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/context/require_context_dependency.rs @@ -66,6 +66,10 @@ impl ModuleDependency for RequireContextDependency { fn resource_identifier(&self) -> Option<&str> { Some(&self.resource_identifier) } + + fn dependency_debug_name(&self) -> &'static str { + "RequireContextDependency" + } } impl DependencyTemplate for RequireContextDependency { 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 2766499e876..2ba0d7ef66f 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 @@ -555,6 +555,10 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { } } } + + fn dependency_debug_name(&self) -> &'static str { + "HarmonyExportImportedSpecifierDependency" + } } #[allow(unused)] 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 9d7b447cb81..9da746e7efa 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 @@ -174,6 +174,14 @@ impl DependencyTemplate for HarmonyImportDependency { ))); } if self.export_all { + let connection = compilation.module_graph.connection_by_dependency(&self.id); + if let Some(con) = connection { + // TODO: runtime opt + let active = con.is_target_active(&compilation.module_graph, None); + if !active { + return; + } + } runtime_requirements.insert(RuntimeGlobals::EXPORT_STAR); let exports_argument = compilation .module_graph @@ -246,13 +254,10 @@ impl ModuleDependency for HarmonyImportDependency { // TODO: It's from HarmonyImportSideEffectDependency. fn get_condition(&self) -> Option { - let id = self.id; Some(DependencyCondition::Fn(Box::new( - move |_, _, module_graph: &ModuleGraph| { - if let Some(module) = module_graph - .parent_module_by_dependency_id(&id) - .and_then(|module_identifier| module_graph.module_by_identifier(&module_identifier)) - { + move |con, _, module_graph: &ModuleGraph| { + let id = con.module_identifier; + if let Some(module) = module_graph.module_by_identifier(&id) { module.get_side_effects_connection_state(module_graph, &mut HashSet::default()) } else { ConnectionState::Bool(true) @@ -268,7 +273,7 @@ impl ModuleDependency for HarmonyImportDependency { module_chain: &mut HashSet, ) -> ConnectionState { if let Some(module) = module_graph - .parent_module_by_dependency_id(&self.id) + .module_identifier_by_dependency_id(&self.id) .and_then(|module_identifier| module_graph.module_by_identifier(&module_identifier)) { module.get_side_effects_connection_state(module_graph, module_chain) @@ -276,4 +281,8 @@ impl ModuleDependency for HarmonyImportDependency { ConnectionState::Bool(true) } } + + fn dependency_debug_name(&self) -> &'static str { + "HarmonyImportDependency" + } } 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 6e788f26868..5889b8c0e18 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 @@ -252,4 +252,8 @@ impl ModuleDependency for HarmonyImportSpecifierDependency { self.get_referenced_exports_in_destructuring(Some(&self.ids)) } + + fn dependency_debug_name(&self) -> &'static str { + "HarmonyImportSpecifierDependency" + } } diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/import_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/import_dependency.rs index ff0f4d00584..271e3353410 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/import_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/import_dependency.rs @@ -86,6 +86,10 @@ impl ModuleDependency for ImportDependency { vec![ExtendedReferencedExport::Array(vec![])] } } + + fn dependency_debug_name(&self) -> &'static str { + "ImportDependency" + } } impl DependencyTemplate for ImportDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/hmr/import_meta_hot_accept.rs b/crates/rspack_plugin_javascript/src/dependency/hmr/import_meta_hot_accept.rs index f7774f9cfe6..75564c994c5 100644 --- a/crates/rspack_plugin_javascript/src/dependency/hmr/import_meta_hot_accept.rs +++ b/crates/rspack_plugin_javascript/src/dependency/hmr/import_meta_hot_accept.rs @@ -55,6 +55,10 @@ impl ModuleDependency for ImportMetaHotAcceptDependency { fn set_request(&mut self, request: String) { self.request = request.into(); } + + fn dependency_debug_name(&self) -> &'static str { + "ImportMetaHotAcceptDependency" + } } impl DependencyTemplate for ImportMetaHotAcceptDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/hmr/import_meta_hot_decline.rs b/crates/rspack_plugin_javascript/src/dependency/hmr/import_meta_hot_decline.rs index bb010fc3135..246e5e42aaa 100644 --- a/crates/rspack_plugin_javascript/src/dependency/hmr/import_meta_hot_decline.rs +++ b/crates/rspack_plugin_javascript/src/dependency/hmr/import_meta_hot_decline.rs @@ -55,6 +55,10 @@ impl ModuleDependency for ImportMetaHotDeclineDependency { fn set_request(&mut self, request: String) { self.request = request.into(); } + + fn dependency_debug_name(&self) -> &'static str { + "ImportMetaHotDeclineDependency" + } } impl DependencyTemplate for ImportMetaHotDeclineDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/hmr/module_hot_accept.rs b/crates/rspack_plugin_javascript/src/dependency/hmr/module_hot_accept.rs index c438b6df02a..cf1d1361857 100644 --- a/crates/rspack_plugin_javascript/src/dependency/hmr/module_hot_accept.rs +++ b/crates/rspack_plugin_javascript/src/dependency/hmr/module_hot_accept.rs @@ -55,6 +55,10 @@ impl ModuleDependency for ModuleHotAcceptDependency { fn set_request(&mut self, request: String) { self.request = request.into(); } + + fn dependency_debug_name(&self) -> &'static str { + "ModuleHotAcceptDependency" + } } impl DependencyTemplate for ModuleHotAcceptDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/hmr/module_hot_decline.rs b/crates/rspack_plugin_javascript/src/dependency/hmr/module_hot_decline.rs index 3b2861b62c7..86b2bb3457e 100644 --- a/crates/rspack_plugin_javascript/src/dependency/hmr/module_hot_decline.rs +++ b/crates/rspack_plugin_javascript/src/dependency/hmr/module_hot_decline.rs @@ -55,6 +55,10 @@ impl ModuleDependency for ModuleHotDeclineDependency { fn set_request(&mut self, request: String) { self.request = request.into(); } + + fn dependency_debug_name(&self) -> &'static str { + "ModuleHotDeclineDependency" + } } impl DependencyTemplate for ModuleHotDeclineDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/url/mod.rs b/crates/rspack_plugin_javascript/src/dependency/url/mod.rs index 5165cbc4db0..0d03441f81b 100644 --- a/crates/rspack_plugin_javascript/src/dependency/url/mod.rs +++ b/crates/rspack_plugin_javascript/src/dependency/url/mod.rs @@ -62,6 +62,10 @@ impl ModuleDependency for URLDependency { fn get_condition(&self) -> Option { get_dependency_used_by_exports_condition(self.id, &self.used_by_exports) } + + fn dependency_debug_name(&self) -> &'static str { + "URLDependency" + } } impl DependencyTemplate for URLDependency { diff --git a/crates/rspack_plugin_javascript/src/dependency/worker/mod.rs b/crates/rspack_plugin_javascript/src/dependency/worker/mod.rs index 0955efb08e4..0491ffade6d 100644 --- a/crates/rspack_plugin_javascript/src/dependency/worker/mod.rs +++ b/crates/rspack_plugin_javascript/src/dependency/worker/mod.rs @@ -78,6 +78,10 @@ impl ModuleDependency for WorkerDependency { ) -> Vec { vec![] } + + fn dependency_debug_name(&self) -> &'static str { + "WorkerDependency" + } } impl DependencyTemplate for WorkerDependency { diff --git a/crates/rspack_plugin_wasm/src/dependency.rs b/crates/rspack_plugin_wasm/src/dependency.rs index 59506941efc..07e58a3a89d 100644 --- a/crates/rspack_plugin_wasm/src/dependency.rs +++ b/crates/rspack_plugin_wasm/src/dependency.rs @@ -72,6 +72,10 @@ impl ModuleDependency for WasmImportDependency { ) -> Vec { vec![ExtendedReferencedExport::Array(vec![self.name.clone()])] } + + fn dependency_debug_name(&self) -> &'static str { + "WasmImportDependency" + } } impl AsDependencyTemplate for WasmImportDependency {} From 781624e36a1a1d4bd687b36e41541eef66d03068 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 14:32:47 +0800 Subject: [PATCH 06/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bb/snapshot/new_treeshaking.snap | 5 --- .../bb/snapshot/new_treeshaking.snap.new | 41 ------------------- .../esm/harmony_import_dependency.rs | 24 +++++++---- 3 files changed, 16 insertions(+), 54 deletions(-) delete mode 100644 crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap.new 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 311f3555af4..0786f055778 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/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__); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); -__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './b.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); -__webpack_require__.es(_b_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); // import { d, c } from "./b.js"; // export const a = 3; @@ -28,7 +24,6 @@ __webpack_require__.d(__webpack_exports__, { "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); _a_js__WEBPACK_IMPORTED_MODULE_0_.ccc; }, diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap.new b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap.new deleted file mode 100644 index 172ab0000b9..00000000000 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap.new +++ /dev/null @@ -1,41 +0,0 @@ ---- -source: crates/rspack_testing/src/run_fixture.rs -assertion_line: 146 ---- -```js title=main.js -(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './b.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); -// import { d, c } from "./b.js"; - - // export const a = 3; - // - // d; - // export { c }; -}, -"./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__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); - -_a_js__WEBPACK_IMPORTED_MODULE_0_.ccc; -}, - -},function(__webpack_require__) { -var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } -var __webpack_exports__ = (__webpack_exec__("./index.js")); - -} -]); -``` 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 9da746e7efa..75d4152918d 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 @@ -61,6 +61,14 @@ impl DependencyTemplate for HarmonyImportDependency { let compilation = &code_generatable_context.compilation; let module = &code_generatable_context.module; + let connection = compilation.module_graph.connection_by_dependency(&self.id); + if let Some(con) = connection { + // TODO: runtime opt + let active = con.is_target_active(&compilation.module_graph, None); + if !active { + return; + } + } let ref_mgm = compilation .module_graph .module_graph_module_by_dependency_id(&self.id) @@ -174,14 +182,14 @@ impl DependencyTemplate for HarmonyImportDependency { ))); } if self.export_all { - let connection = compilation.module_graph.connection_by_dependency(&self.id); - if let Some(con) = connection { - // TODO: runtime opt - let active = con.is_target_active(&compilation.module_graph, None); - if !active { - return; - } - } + // let connection = compilation.module_graph.connection_by_dependency(&self.id); + // if let Some(con) = connection { + // // TODO: runtime opt + // let active = con.is_target_active(&compilation.module_graph, None); + // if !active { + // return; + // } + // } runtime_requirements.insert(RuntimeGlobals::EXPORT_STAR); let exports_argument = compilation .module_graph From 1b1450d39cb2a506bdcf10fbf011befad8195e36 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 14:48:26 +0800 Subject: [PATCH 07/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/tree-shaking/bb/snapshot/snap.diff | 33 +++++++++++-------- .../esm/harmony_import_dependency.rs | 26 ++++++++------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index e8b9ffa4e2a..a573baf36e8 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -6,23 +6,16 @@ +@@ -6,24 +6,13 @@ "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -8,16 +8,16 @@ -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./c.js */"./c.js"); -__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - -- -- const a = 3; --_b_js__WEBPACK_IMPORTED_MODULE_0_.d; -+/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); -+__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -+/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './b.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); -+__webpack_require__.es(_b_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +// import { d, c } from "./b.js"; --}, +- const a = 3; +-_b_js__WEBPACK_IMPORTED_MODULE_0_.d; +- ++ // export const a = 3; ++ // ++ // d; ++ // export { c }; + }, -"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); @@ -26,10 +26,15 @@ -}); - const d = 3; - const c = 100; -+ // export const a = 3; -+ // -+ // d; -+ // export { c }; - }, +-}, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; + __webpack_require__.r(__webpack_exports__); +@@ -35,7 +24,6 @@ + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); + + _a_js__WEBPACK_IMPORTED_MODULE_0_.ccc; + }, 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 75d4152918d..ac1dfbf4f15 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 @@ -61,22 +61,24 @@ impl DependencyTemplate for HarmonyImportDependency { let compilation = &code_generatable_context.compilation; let module = &code_generatable_context.module; - let connection = compilation.module_graph.connection_by_dependency(&self.id); - if let Some(con) = connection { - // TODO: runtime opt - let active = con.is_target_active(&compilation.module_graph, None); - if !active { - return; - } - } let ref_mgm = compilation .module_graph .module_graph_module_by_dependency_id(&self.id) .expect("should have ref module"); - if !compilation - .include_module_ids - .contains(&ref_mgm.module_identifier) - { + let is_target_active = if compilation.options.is_new_tree_shaking() { + let connection = compilation.module_graph.connection_by_dependency(&self.id); + if let Some(con) = connection { + // TODO: runtime opt + con.is_target_active(&compilation.module_graph, None) + } else { + true + } + } else { + compilation + .include_module_ids + .contains(&ref_mgm.module_identifier) + }; + if !is_target_active { return; } From 9d036036deca5c1a5117a9a28b2ac9be615a6020 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 16:46:38 +0800 Subject: [PATCH 08/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20ckpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/tree-shaking/bb/a.js | 7 ++- .../bb/snapshot/new_treeshaking.snap | 21 +++++---- crates/rspack_core/src/dependency/mod.rs | 16 +++---- crates/rspack_core/src/normal_module.rs | 2 +- .../harmony_export_expression_dependency.rs | 43 ++++++++++++++++++- ...ny_export_imported_specifier_dependency.rs | 16 +++---- .../harmony_export_specifier_dependency.rs | 10 ++++- .../esm/harmony_import_dependency.rs | 29 +++++++------ .../harmony_import_specifier_dependency.rs | 16 +++---- 9 files changed, 106 insertions(+), 54 deletions(-) diff --git a/crates/rspack/tests/tree-shaking/bb/a.js b/crates/rspack/tests/tree-shaking/bb/a.js index dbd131df79b..58fd4577a01 100644 --- a/crates/rspack/tests/tree-shaking/bb/a.js +++ b/crates/rspack/tests/tree-shaking/bb/a.js @@ -1,7 +1,10 @@ // import { d, c } from "./b.js"; -export * from "./c.js"; -export * from './b.js' +// export * from "./c.js"; +// export * from './b.js' // export const a = 3; // // d; // export { c }; +// +export const ccc = 3; +export const b = 3; 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 0786f055778..9b4d42a2fd9 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -6,20 +6,19 @@ 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__); -// import { d, c } from "./b.js"; - - // export const a = 3; - // - // d; - // export { c }; -}, -"./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; +// import { d, c } from "./b.js"; +// export * from "./c.js"; +// export * from './b.js' +// export const a = 3; +// +// d; +// export { c }; +// + const ccc = 3; + const b = 3; }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; diff --git a/crates/rspack_core/src/dependency/mod.rs b/crates/rspack_core/src/dependency/mod.rs index 33af0dc19af..5208fbf0021 100644 --- a/crates/rspack_core/src/dependency/mod.rs +++ b/crates/rspack_core/src/dependency/mod.rs @@ -190,6 +190,14 @@ pub trait Dependency: fn get_exports(&self) -> Option { None } + + fn get_module_evaluation_side_effects_state( + &self, + _module_graph: &ModuleGraph, + _module_chain: &mut HashSet, + ) -> ConnectionState { + ConnectionState::Bool(true) + } } #[derive(Debug, Default)] @@ -370,14 +378,6 @@ pub trait ModuleDependency: Dependency { None } - fn get_module_evaluation_side_effects_state( - &self, - _module_graph: &ModuleGraph, - _module_chain: &mut HashSet, - ) -> ConnectionState { - ConnectionState::Bool(true) - } - fn get_referenced_exports( &self, _module_graph: &ModuleGraph, diff --git a/crates/rspack_core/src/normal_module.rs b/crates/rspack_core/src/normal_module.rs index d1411845e6e..560cdabe92e 100644 --- a/crates/rspack_core/src/normal_module.rs +++ b/crates/rspack_core/src/normal_module.rs @@ -507,7 +507,7 @@ impl Module for NormalModule { module_chain.insert(self.identifier()); let mut current = ConnectionState::Bool(false); for dependency_id in mgm.dependencies.iter() { - if let Some(dependency) = module_graph.dependency_by_id(dependency_id).expect("should have dependency").as_module_dependency() { + if let Some(dependency) = module_graph.dependency_by_id(dependency_id) { let state = dependency.get_module_evaluation_side_effects_state(module_graph, module_chain); if matches!(state, ConnectionState::Bool(true)) { // TODO add optimization bailout diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs index 5c2667ecd83..7b3c38ce068 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs @@ -1,4 +1,7 @@ -use rspack_core::{DependencyTemplate, TemplateContext, TemplateReplaceSource}; +use rspack_core::{ + Dependency, DependencyId, DependencyTemplate, ModuleDependency, TemplateContext, + TemplateReplaceSource, +}; pub const DEFAULT_EXPORT: &str = "__WEBPACK_DEFAULT_EXPORT__"; // pub const NAMESPACE_OBJECT_EXPORT: &'static str = "__WEBPACK_NAMESPACE_OBJECT__"; @@ -17,6 +20,7 @@ pub struct HarmonyExportExpressionDependency { pub end: u32, pub declaration: bool, pub function: Option, + pub id: DependencyId, } impl HarmonyExportExpressionDependency { @@ -31,10 +35,47 @@ impl HarmonyExportExpressionDependency { end, declaration, function, + id: DependencyId::default(), } } } +impl ModuleDependency for HarmonyExportExpressionDependency { + fn dependency_debug_name(&self) -> &'static str { + "HarmonyExportExpressionDependency" + } + + fn request(&self) -> &str { + "" + } + + fn user_request(&self) -> &str { + todo!() + } + + fn span(&self) -> Option<&rspack_core::ErrorSpan> { + todo!() + } + + fn set_request(&mut self, request: String) { + todo!() + } +} + +impl Dependency for HarmonyExportExpressionDependency { + fn id(&self) -> &rspack_core::DependencyId { + &self.id + } + + fn get_module_evaluation_side_effects_state( + &self, + _module_graph: &rspack_core::ModuleGraph, + _module_chain: &mut rustc_hash::FxHashSet, + ) -> rspack_core::ConnectionState { + rspack_core::ConnectionState::Bool(false) + } +} + impl DependencyTemplate for HarmonyExportExpressionDependency { fn apply( &self, 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 2ba0d7ef66f..8e796587789 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 @@ -428,6 +428,14 @@ impl Dependency for HarmonyExportImportedSpecifierDependency { fn dependency_type(&self) -> &DependencyType { &DependencyType::EsmExportImportedSpecifier } + + fn get_module_evaluation_side_effects_state( + &self, + _module_graph: &ModuleGraph, + _module_chain: &mut HashSet, + ) -> ConnectionState { + ConnectionState::Bool(false) + } } impl ModuleDependency for HarmonyExportImportedSpecifierDependency { @@ -480,14 +488,6 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { ))) } - fn get_module_evaluation_side_effects_state( - &self, - _module_graph: &ModuleGraph, - _module_chain: &mut HashSet, - ) -> ConnectionState { - ConnectionState::Bool(false) - } - fn get_referenced_exports( &self, module_graph: &ModuleGraph, 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 9a53e2d0c2e..7d65f629e49 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, UsedName, + ModuleDependency, TemplateContext, TemplateReplaceSource, UsedName, }; use swc_core::ecma::atoms::JsWord; @@ -48,6 +48,14 @@ impl Dependency for HarmonyExportSpecifierDependency { exclude_exports: None, }) } + + fn get_module_evaluation_side_effects_state( + &self, + _module_graph: &rspack_core::ModuleGraph, + _module_chain: &mut rustc_hash::FxHashSet, + ) -> rspack_core::ConnectionState { + rspack_core::ConnectionState::Bool(false) + } } impl AsModuleDependency for HarmonyExportSpecifierDependency {} 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 ac1dfbf4f15..30546bcc7c3 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 @@ -227,6 +227,21 @@ impl Dependency for HarmonyImportDependency { fn dependency_type(&self) -> &DependencyType { &self.dependency_type } + + fn get_module_evaluation_side_effects_state( + &self, + module_graph: &ModuleGraph, + module_chain: &mut HashSet, + ) -> ConnectionState { + if let Some(module) = module_graph + .module_identifier_by_dependency_id(&self.id) + .and_then(|module_identifier| module_graph.module_by_identifier(&module_identifier)) + { + module.get_side_effects_connection_state(module_graph, module_chain) + } else { + ConnectionState::Bool(true) + } + } } impl ModuleDependency for HarmonyImportDependency { @@ -277,20 +292,6 @@ impl ModuleDependency for HarmonyImportDependency { } // It's from HarmonyImportSideEffectDependency. - fn get_module_evaluation_side_effects_state( - &self, - module_graph: &ModuleGraph, - module_chain: &mut HashSet, - ) -> ConnectionState { - if let Some(module) = module_graph - .module_identifier_by_dependency_id(&self.id) - .and_then(|module_identifier| module_graph.module_by_identifier(&module_identifier)) - { - module.get_side_effects_connection_state(module_graph, module_chain) - } else { - ConnectionState::Bool(true) - } - } fn dependency_debug_name(&self) -> &'static str { "HarmonyImportDependency" 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 5889b8c0e18..d26b8dc480f 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 @@ -177,6 +177,14 @@ impl Dependency for HarmonyImportSpecifierDependency { fn dependency_type(&self) -> &DependencyType { &DependencyType::EsmImportSpecifier } + + fn get_module_evaluation_side_effects_state( + &self, + _module_graph: &ModuleGraph, + _module_chain: &mut HashSet, + ) -> ConnectionState { + ConnectionState::Bool(false) + } } impl ModuleDependency for HarmonyImportSpecifierDependency { @@ -204,14 +212,6 @@ impl ModuleDependency for HarmonyImportSpecifierDependency { get_dependency_used_by_exports_condition(self.id, &self.used_by_exports) } - fn get_module_evaluation_side_effects_state( - &self, - _module_graph: &ModuleGraph, - _module_chain: &mut HashSet, - ) -> ConnectionState { - ConnectionState::Bool(false) - } - fn get_referenced_exports( &self, module_graph: &ModuleGraph, From 07a2f51d01a0105b6e104957e1007ad958b04bc4 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 18:08:47 +0800 Subject: [PATCH 09/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20snap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simple-with-query/snapshot/output.snap | 1 + .../snapshot/new_treeshaking.snap | 1 - .../array-side-effects/snapshot/snap.diff | 10 - crates/rspack/tests/tree-shaking/bb/a.js | 6 +- .../bb/snapshot/new_treeshaking.snap | 23 +- .../tests/tree-shaking/bb/snapshot/snap.diff | 24 +- .../snapshot/new_treeshaking.snap | 22 -- .../cjs-tree-shaking-basic/snapshot/snap.diff | 34 +- .../snapshot/new_treeshaking.snap | 15 +- .../snapshot/snap.diff | 28 ++ .../snapshot/new_treeshaking.snap | 7 +- .../snapshot/snap.diff | 22 ++ .../snapshot/new_treeshaking.snap | 7 +- .../snapshot/snap.diff | 23 ++ .../snapshot/new_treeshaking.snap | 18 -- .../snapshot/snap.diff | 31 +- .../snapshot/new_treeshaking.snap | 1 - .../export-named-decl-as/snapshot/snap.diff | 10 +- .../snapshot/new_treeshaking.snap | 71 ----- .../export-star-chain/snapshot/snap.diff | 112 ++++--- .../export_star/snapshot/new_treeshaking.snap | 28 +- .../export_star/snapshot/snap.diff | 52 ++- .../snapshot/new_treeshaking.snap | 39 +-- .../export_star2/snapshot/snap.diff | 55 ++++ .../snapshot/new_treeshaking.snap | 28 +- .../snapshot/snap.diff | 47 +++ .../snapshot/new_treeshaking.snap | 58 ---- .../snapshot/snap.diff | 70 ----- .../snapshot/new_treeshaking.snap | 2 - .../snapshot/snap.diff | 11 + .../snapshot/new_treeshaking.snap | 1 - .../snapshot/snap.diff | 10 +- .../snapshot/new_treeshaking.snap | 16 +- .../snapshot/snap.diff | 58 ++-- .../snapshot/new_treeshaking.snap | 7 +- .../snapshot/snap.diff | 18 +- .../snapshot/new_treeshaking.snap | 8 +- .../snapshot/snap.diff | 14 +- .../snapshot/new_treeshaking.snap | 28 -- .../snapshot/snap.diff | 52 ++- .../snapshot/new_treeshaking.snap | 15 - .../nested-import-3/snapshot/snap.diff | 34 +- .../snapshot/new_treeshaking.snap | 1 - .../nested-import-4/snapshot/snap.diff | 8 + .../snapshot/new_treeshaking.snap | 2 - .../prune-bailout-module/snapshot/snap.diff | 5 +- .../snapshot/new_treeshaking.snap | 28 -- .../react-redux-like/snapshot/snap.diff | 54 +++- .../snapshot/new_treeshaking.snap | 45 --- .../snapshot/snap.diff | 74 ++--- .../snapshot/new_treeshaking.snap | 33 -- .../reexport-all-as/snapshot/snap.diff | 55 ++-- .../snapshot/new_treeshaking.snap | 2 - .../side-effects-analyzed/snapshot/snap.diff | 7 +- .../snapshot/new_treeshaking.snap | 51 --- .../side-effects-prune/snapshot/snap.diff | 65 +--- .../snapshot/new_treeshaking.snap | 2 - .../side-effects-two/snapshot/snap.diff | 7 +- .../snapshot/new_treeshaking.snap | 8 - .../transitive-bailout/snapshot/snap.diff | 27 +- .../snapshot/new_treeshaking.snap | 6 - .../snapshot/snap.diff | 21 -- .../snapshot/new_treeshaking.snap | 1 - .../ts-target-es5/snapshot/snap.diff | 8 +- .../snapshot/new_treeshaking.snap | 1 + .../snapshot/snap.diff | 14 +- crates/rspack_core/src/module_graph_module.rs | 14 +- .../esm/harmony_import_dependency.rs | 297 +++++++++--------- .../harmony_import_specifier_dependency.rs | 31 +- 69 files changed, 856 insertions(+), 1128 deletions(-) delete mode 100644 crates/rspack/tests/tree-shaking/array-side-effects/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/snap.diff diff --git a/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap b/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap index 5df0503681c..03249a42d9c 100644 --- a/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap +++ b/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap @@ -16,6 +16,7 @@ __webpack_require__.d(__webpack_exports__, { __webpack_require__.r(__webpack_exports__); /* harmony import */var _b_jsx__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.jsx */"./b.jsx"); /* harmony import */var _b_js_x__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js?x */"./b.js?x"); +/* harmony import */var _b_jsx__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.jsx */"./b.jsx"); _b_js_x__WEBPACK_IMPORTED_MODULE_1_.a; 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 8fda05d7224..949dbc6c732 100644 --- a/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/new_treeshaking.snap @@ -17,7 +17,6 @@ app.prototype.result = _lib__WEBPACK_IMPORTED_MODULE_0_.result; "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js"); /* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./src/a */"./src/a.js"); 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 deleted file mode 100644 index 918d130d977..00000000000 --- a/crates/rspack/tests/tree-shaking/array-side-effects/snapshot/snap.diff +++ /dev/null @@ -1,10 +0,0 @@ ---- expected -+++ actual -@@ -17,6 +17,7 @@ - "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js"); - /* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./src/a */"./src/a.js"); - - diff --git a/crates/rspack/tests/tree-shaking/bb/a.js b/crates/rspack/tests/tree-shaking/bb/a.js index 58fd4577a01..475a4b2c64a 100644 --- a/crates/rspack/tests/tree-shaking/bb/a.js +++ b/crates/rspack/tests/tree-shaking/bb/a.js @@ -1,10 +1,8 @@ // import { d, c } from "./b.js"; -// export * from "./c.js"; -// export * from './b.js' +export * from "./c.js"; +export * from './b.js' // export const a = 3; // // d; // export { c }; // -export const ccc = 3; -export const b = 3; 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 9b4d42a2fd9..3c60d9a4616 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -6,23 +6,26 @@ 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__); +// import { d, c } from "./b.js"; + + // export const a = 3; + // + // d; + // export { c }; + // +}, +"./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; } }); -// import { d, c } from "./b.js"; -// export * from "./c.js"; -// export * from './b.js' -// export const a = 3; -// -// d; -// export { c }; -// - const ccc = 3; - const b = 3; + const ccc = 30; }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); +/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); _a_js__WEBPACK_IMPORTED_MODULE_0_.ccc; }, diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index a573baf36e8..82377467991 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -6,24 +6,13 @@ +@@ -6,23 +6,13 @@ "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -13,11 +13,7 @@ - const a = 3; -_b_js__WEBPACK_IMPORTED_MODULE_0_.d; - -+ // export const a = 3; -+ // -+ // d; -+ // export { c }; - }, +-}, -"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); @@ -26,15 +22,11 @@ -}); - const d = 3; - const c = 100; --}, ++ // export const a = 3; ++ // ++ // d; ++ // export { c }; ++ // + }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; - __webpack_require__.r(__webpack_exports__); -@@ -35,7 +24,6 @@ - "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); --/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); - - _a_js__WEBPACK_IMPORTED_MODULE_0_.ccc; - }, diff --git a/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/new_treeshaking.snap index 7e25db3d68b..efb999f5d65 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 @@ -3,33 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```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__); - function aaa() {} -}, -"./a/bbb.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - function bbb() {} -}, -"./a/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _aaa__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./aaa */"./a/aaa.js"); -__webpack_require__.es(_aaa__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _bbb__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bbb */"./a/bbb.js"); -__webpack_require__.es(_bbb__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - - -}, "./answer.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; } }); -/* harmony import */var _a_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a/index */"./a/index.js"); const answer = 42; }, @@ -39,7 +18,6 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'myanswer': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_.myanswer; } }); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 a6430de07d2..5d68e0d65d5 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,36 +1,10 @@ --- expected +++ actual -@@ -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__); -+ function aaa() {} -+}, -+"./a/bbb.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+ function bbb() {} -+}, -+"./a/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+/* harmony import */var _aaa__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./aaa */"./a/aaa.js"); -+__webpack_require__.es(_aaa__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -+/* harmony import */var _bbb__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bbb */"./a/bbb.js"); -+__webpack_require__.es(_bbb__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -+ -+ -+}, - "./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -18,7 +18,6 @@ __webpack_require__.d(__webpack_exports__, { - 'answer': function() { return answer; } + 'myanswer': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_.myanswer; } }); -+/* harmony import */var _a_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a/index */"./a/index.js"); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); - const answer = 42; }, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 46f2a271fc8..731c0bc7ae1 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 @@ -3,23 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const a = 'bar'; -}, -"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const a = 'foo'; - const b = 'foo'; -}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); +/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); 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 new file mode 100644 index 00000000000..d0a1b07ce96 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/snap.diff @@ -0,0 +1,28 @@ +--- expected ++++ actual +@@ -3,23 +3,12 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +- const a = 'bar'; +-}, +-"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +- const a = 'foo'; +- const b = 'foo'; +-}, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); ++/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +-/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); ++/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + + 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 51599a002db..1f2d7bf1928 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 @@ -3,18 +3,13 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - 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; } }); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); const a = 'foo'; 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 new file mode 100644 index 00000000000..7e6929abfd6 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/snap.diff @@ -0,0 +1,22 @@ +--- expected ++++ actual +@@ -3,18 +3,13 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +- 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; } + }); +-/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); ++/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + const a = 'foo'; + 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 bd579c58e56..4602ad4918e 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 @@ -3,11 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const a = 'bar'; -}, "./baz.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -23,7 +18,7 @@ __webpack_require__.d(__webpack_exports__, { 'a': function() { return _baz__WEBPACK_IMPORTED_MODULE_0_.a; } }); /* harmony import */var _baz__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./baz */"./baz.js"); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); 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 new file mode 100644 index 00000000000..b415d8c3ef2 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/snap.diff @@ -0,0 +1,23 @@ +--- expected ++++ actual +@@ -3,11 +3,6 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +- const a = 'bar'; +-}, + "./baz.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +@@ -23,7 +18,7 @@ + 'a': function() { return _baz__WEBPACK_IMPORTED_MODULE_0_.a; } + }); + /* harmony import */var _baz__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./baz */"./baz.js"); +-/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); ++/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + + 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 1c21692936c..9df20f537de 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 @@ -6,8 +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__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); -__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { @@ -17,22 +15,6 @@ __webpack_require__.r(__webpack_exports__); _answer__WEBPACK_IMPORTED_MODULE_0_.filter; }, -"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'filter': function() { return _test_js__WEBPACK_IMPORTED_MODULE_0_; } -}); -/* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./test.js */"./test.js"); - const a = 3; - - -}, -"./test.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const result = ""; -}, },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } 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 2fcb66d19f9..659e4b07807 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,12 +1,37 @@ --- expected +++ actual -@@ -31,9 +31,6 @@ - "./test.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -6,8 +6,6 @@ + "./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); +-__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + + }, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -16,25 +14,6 @@ + /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); + + _answer__WEBPACK_IMPORTED_MODULE_0_.filter; +-}, +-"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'filter': function() { return _test_js__WEBPACK_IMPORTED_MODULE_0_; } +-}); +-/* harmony import */var _test_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./test.js */"./test.js"); +- const a = 3; +- +- +-}, +-"./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 = ""; +- const result = ""; }, + },function(__webpack_require__) { 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 0810f183395..ffb27acc28b 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 @@ -9,7 +9,6 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'formatNumber': function() { return _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0_["default"]; } }); -/* harmony import */var _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./plugin/formatNumber */"./src/plugin/formatNumber.js"); }, 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 932aea79560..955409d013f 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 @@ -1,6 +1,14 @@ --- expected +++ actual -@@ -23,9 +23,6 @@ +@@ -9,7 +9,6 @@ + __webpack_require__.d(__webpack_exports__, { + 'formatNumber': function() { return _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0_["default"]; } + }); +-/* harmony import */var _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./plugin/formatNumber */"./src/plugin/formatNumber.js"); + + + }, +@@ -23,9 +22,6 @@ "./src/plugin/formatNumber.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); 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 482cef67e5e..1ced53d3c04 100644 --- a/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/new_treeshaking.snap @@ -3,61 +3,9 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Layout.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _something__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./something */"./something/index.js"); -__webpack_require__.es(_something__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* 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__); - - -}, -"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - function cccc() {} -}, -"./colors/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const red = 'red'; -}, -"./colors/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const blue = 'blue'; -}, -"./colors/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./result */"./colors/result.js"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - -}, -"./colors/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./colors/a.js"); -__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./colors/b.js"); -__webpack_require__.es(_b__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./colors/c.js"); -__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__); - const result = 'ssss'; -}, "./export.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); -__webpack_require__.es(_Layout__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { @@ -67,25 +15,6 @@ __webpack_require__.r(__webpack_exports__); _export__WEBPACK_IMPORTED_MODULE_0_.Colors; _export__WEBPACK_IMPORTED_MODULE_0_.Something; -}, -"./something/Something.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - class Something { -} -}, -"./something/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'Colors': function() { return _colors_index__WEBPACK_IMPORTED_MODULE_0_; } -}); -/* harmony import */var _colors_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../colors/index */"./colors/index.js"); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./something/Something.js"); -__webpack_require__.es(_Something__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - - - }, },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export-star-chain/snapshot/snap.diff index d1c07230056..6c1903f2dda 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,53 +1,95 @@ --- expected +++ actual -@@ -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__); -+/* 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__); - - - }, -+"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+ function cccc() {} -+}, - "./colors/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -3,63 +3,9 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./Layout.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _something__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./something */"./something/index.js"); +-__webpack_require__.es(_something__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +- +- +-}, +-"./colors/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); -__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__); +- 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__); +- const blue = 'blue'; +-}, +-"./colors/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./result */"./colors/result.js"); +-__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +- +-}, +-"./colors/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./colors/a.js"); +-__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +-/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./colors/b.js"); +-__webpack_require__.es(_b__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +-/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./colors/c.js"); +-__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'; - }, +- 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__); +-/* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); +-__webpack_require__.es(_Layout__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + + }, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -69,28 +15,6 @@ + + _export__WEBPACK_IMPORTED_MODULE_0_.Colors; + _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 { - } +- class Something { +-} +-}, +-"./something/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'Colors': function() { return _colors_index__WEBPACK_IMPORTED_MODULE_0_; } +-}); +-/* harmony import */var _colors_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../colors/index */"./colors/index.js"); +-/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./something/Something.js"); +-__webpack_require__.es(_Something__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- +- +- }, + + },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/export_star/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/export_star/snapshot/new_treeshaking.snap index 99613de3738..0fbb3404f35 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 @@ -3,25 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.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_; } -}); -/* 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"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - function b() {} - - -}, "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); +/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); const a = 3; const foo = 3; @@ -35,17 +22,6 @@ __webpack_require__.r(__webpack_exports__); _foo__WEBPACK_IMPORTED_MODULE_0_.bar.a; (0, _foo__WEBPACK_IMPORTED_MODULE_0_.c)(); -}, -"./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); -__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - const c = 103330; - - }, },function(__webpack_require__) { 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 45d4a1ce593..98ab1bed4db 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,54 @@ --- expected +++ actual -@@ -19,9 +19,6 @@ +@@ -3,28 +3,12 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./bar.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_; } +-}); +-/* 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"); +-__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- function b() {} +- +- +-}, "./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"); +-/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); ++/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __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__); +-/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); ++/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + const a = 3; + const foo = 3; +@@ -38,20 +22,6 @@ + + _foo__WEBPACK_IMPORTED_MODULE_0_.bar.a; + (0, _foo__WEBPACK_IMPORTED_MODULE_0_.c)(); +-}, +-"./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"); +-/* 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"); +-__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- const c = 103330; +- +- + }, + + },function(__webpack_require__) { 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 6c118c52652..3a5412b3b67 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 @@ -3,51 +3,18 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); -__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - function b() {} - - -}, -"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* 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"); -__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - const a = 3; - - -}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); +/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./result */"./result.js"); +/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __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__); -/* 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"); -__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - const c = 103330; - - }, },function(__webpack_require__) { diff --git a/crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff new file mode 100644 index 00000000000..41fb6eeb428 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff @@ -0,0 +1,55 @@ +--- expected ++++ actual +@@ -3,49 +3,16 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); +-__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +-/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); +-__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- function b() {} +- +- +-}, +-"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* 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"); +-__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- const a = 3; +- +- +-}, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); ++/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +-/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); ++/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +-/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./result */"./result.js"); ++/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __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__); +-/* 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"); +-__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- const c = 103330; + + + }, 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 312f1ee2784..5cd7f1fcf1a 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 @@ -9,25 +9,13 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'b': function() { return b; } }); -/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo.js */"./foo.js"); +/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_foo_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result.js */"./result.js"); +/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); function b() {} -}, -"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* 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"); -__webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - const a = 3; - const b = 3; - - }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; @@ -35,18 +23,6 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar.js */"./bar.js"); (0, _bar_js__WEBPACK_IMPORTED_MODULE_0_.b)(); -}, -"./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* 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"); -__webpack_require__.es(_bar_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - const c = 103330; - const b = 103330; - - }, },function(__webpack_require__) { 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 new file mode 100644 index 00000000000..428bfaa515f --- /dev/null +++ b/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/snap.diff @@ -0,0 +1,47 @@ +--- expected ++++ actual +@@ -9,23 +9,11 @@ + __webpack_require__.d(__webpack_exports__, { + 'b': function() { return b; } + }); +-/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo.js */"./foo.js"); ++/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_foo_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +-/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result.js */"./result.js"); ++/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + function b() {} +- +- +-}, +-"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* 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"); +-__webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- const a = 3; +- const b = 3; + + + }, +@@ -35,18 +23,6 @@ + /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar.js */"./bar.js"); + + (0, _bar_js__WEBPACK_IMPORTED_MODULE_0_.b)(); +-}, +-"./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* 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"); +-__webpack_require__.es(_bar_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +- const c = 103330; +- const b = 103330; +- +- + }, + + },function(__webpack_require__) { 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 96e8895fe2f..623d8dcb582 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 @@ -6,66 +6,8 @@ source: crates/rspack_testing/src/run_fixture.rs "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _source__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./source */"./source/index.js"); -/* harmony import */var _source__WEBPACK_IMPORTED_MODULE_0__default = /*#__PURE__*/__webpack_require__.n(_source__WEBPACK_IMPORTED_MODULE_0_); console.log('something'); -}, -"./source/index.js": function (module, exports, __webpack_require__) { -var _class_call_check = __webpack_require__(/* @swc/helpers/_/_class_call_check */"../../../../../node_modules/@swc/helpers/esm/_class_call_check.js"); -var _create_class = __webpack_require__(/* @swc/helpers/_/_create_class */"../../../../../node_modules/@swc/helpers/esm/_create_class.js"); -var test = function test() { - var res = new Response(); - return res; -}; -var Response = function() { - "use strict"; - function Response(mode) { - _class_call_check._(this, Response); - // eslint-disable-next-line no-undefined - if (mode.data === undefined) mode.data = {}; - this.data = mode.data; - this.isMatchIgnored = false; - } - _create_class._(Response, [ - { - key: "ignoreMatch", - value: function ignoreMatch() { - this.isMatchIgnored = true; - } - } - ]); - return Response; -}(); -var result = test(); -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__); - function _class_call_check(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); -} - -}, -"../../../../../node_modules/@swc/helpers/esm/_create_class.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -function _defineProperties(target, props) { - for(var i = 0; i < props.length; i++){ - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } -} - function _create_class(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; -} - }, },function(__webpack_require__) { 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 deleted file mode 100644 index c76e4471032..00000000000 --- a/crates/rspack/tests/tree-shaking/handle-side-effects-commonjs-imported-unused/snapshot/snap.diff +++ /dev/null @@ -1,70 +0,0 @@ ---- expected -+++ actual -@@ -6,9 +6,67 @@ - "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+/* harmony import */var _source__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./source */"./source/index.js"); -+/* harmony import */var _source__WEBPACK_IMPORTED_MODULE_0__default = /*#__PURE__*/__webpack_require__.n(_source__WEBPACK_IMPORTED_MODULE_0_); - - console.log('something'); - }, -+"./source/index.js": function (module, exports, __webpack_require__) { -+var _class_call_check = __webpack_require__(/* @swc/helpers/_/_class_call_check */"../../../../../node_modules/@swc/helpers/esm/_class_call_check.js"); -+var _create_class = __webpack_require__(/* @swc/helpers/_/_create_class */"../../../../../node_modules/@swc/helpers/esm/_create_class.js"); -+var test = function test() { -+ var res = new Response(); -+ return res; -+}; -+var Response = function() { -+ "use strict"; -+ function Response(mode) { -+ _class_call_check._(this, Response); -+ // eslint-disable-next-line no-undefined -+ if (mode.data === undefined) mode.data = {}; -+ this.data = mode.data; -+ this.isMatchIgnored = false; -+ } -+ _create_class._(Response, [ -+ { -+ key: "ignoreMatch", -+ value: function ignoreMatch() { -+ this.isMatchIgnored = true; -+ } -+ } -+ ]); -+ return Response; -+}(); -+var result = test(); -+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__); -+ function _class_call_check(instance, Constructor) { -+ if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); -+} -+ -+}, -+"../../../../../node_modules/@swc/helpers/esm/_create_class.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+function _defineProperties(target, props) { -+ for(var i = 0; i < props.length; i++){ -+ var descriptor = props[i]; -+ descriptor.enumerable = descriptor.enumerable || false; -+ descriptor.configurable = true; -+ if ("value" in descriptor) descriptor.writable = true; -+ Object.defineProperty(target, descriptor.key, descriptor); -+ } -+} -+ function _create_class(Constructor, protoProps, staticProps) { -+ if (protoProps) _defineProperties(Constructor.prototype, protoProps); -+ if (staticProps) _defineProperties(Constructor, staticProps); -+ return Constructor; -+} -+ -+}, - - },function(__webpack_require__) { - var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } diff --git a/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap index 57a6d36d687..32c7971cce6 100644 --- a/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap @@ -12,8 +12,6 @@ __webpack_require__.d(__webpack_exports__, { }); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_0_); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./app */"./app.js"); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_1_); const routes = { diff --git a/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/snap.diff new file mode 100644 index 00000000000..98a97ebbd5f --- /dev/null +++ b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/snap.diff @@ -0,0 +1,11 @@ +--- expected ++++ actual +@@ -12,8 +12,6 @@ + }); + /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); + /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_0_); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./app */"./app.js"); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_1_); + + + const routes = { 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 d456ee9b668..e494bfd1703 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 @@ -9,7 +9,6 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'app': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_; } }); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); }, 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 778e4801e50..c5c3ba6d256 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 @@ -1,6 +1,14 @@ --- expected +++ actual -@@ -23,9 +23,6 @@ +@@ -9,7 +9,6 @@ + __webpack_require__.d(__webpack_exports__, { + 'app': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_; } + }); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); + + + }, +@@ -23,9 +22,6 @@ "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); 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 f6b34955491..9e689bfb961 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 @@ -3,11 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const c = 'a'; -}, "./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -23,7 +18,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'a': function() { return a; } }); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); +/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); @@ -31,15 +26,6 @@ __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); const a = 3; }, -"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); -__webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - - const a = 'foo'; - const b = 'foo'; -}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__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 8ddaf3b9fb0..0bdd108e1c4 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,30 +1,48 @@ --- expected +++ actual -@@ -6,14 +6,14 @@ - "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -3,17 +3,12 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { ++"./bar.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__, { -+ 'c': function() { return c; } -+}); + __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__); const a = 'bar'; const c = 'bar'; }, -@@ -34,9 +34,6 @@ - "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -23,25 +18,13 @@ + __webpack_require__.d(__webpack_exports__, { + 'a': function() { return a; } + }); +-/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); ++/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); + __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + + + const a = 3; +-}, +-"./foo.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 _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); - __webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - +-/* 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__); +- +- const a = 'foo'; +- const b = 'foo'; + }, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; 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 26be6ac5643..cb5608646ad 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 @@ -11,11 +11,6 @@ __webpack_require__.d(__webpack_exports__, { }); const a = 3; }, -"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const b = 30; -}, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -25,8 +20,8 @@ __webpack_require__.r(__webpack_exports__); 'use strict'; __webpack_require__.r(__webpack_exports__); /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c.js */"./c.js"); +/* 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-effects1/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/module-rule-side-effects1/snapshot/snap.diff index cf7b5b7d6e9..9fe31842991 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,22 +1,10 @@ --- expected +++ actual -@@ -11,6 +11,11 @@ - }); - const a = 3; - }, -+"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+ const b = 30; -+}, - "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -@@ -20,6 +25,7 @@ - 'use strict'; +@@ -21,6 +21,7 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); -+/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); /* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c.js */"./c.js"); ++/* 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 26be6ac5643..36737b8a3c9 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 @@ -16,17 +16,11 @@ __webpack_require__.d(__webpack_exports__, { __webpack_require__.r(__webpack_exports__); const b = 30; }, -"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const c = 300; -}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); /* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c.js */"./c.js"); +/* 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/snap.diff b/crates/rspack/tests/tree-shaking/module-rule-side-effects2/snapshot/snap.diff index 4a02621d726..55e32f1068d 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 -@@ -16,11 +16,17 @@ - __webpack_require__.r(__webpack_exports__); - const b = 30; - }, -+"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+ const c = 300; -+}, +@@ -19,8 +19,8 @@ "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); ++/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); - /* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); -+/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c.js */"./c.js"); +-/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); 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 7075199e11a..77519700c76 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 @@ -3,37 +3,9 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const a = { - a: '' -}; -}, -"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const b = { - b: "" -}; -}, -"./enum-old.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_.a; }, - 'b': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.b; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./a.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./b.js"); - - -}, "./enum.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _enum_old__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./enum-old */"./enum-old.js"); -__webpack_require__.es(_enum_old__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 bd51f2cbf90..faf2a25b2df 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,22 +1,46 @@ --- expected +++ actual -@@ -6,9 +6,6 @@ - "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -3,43 +3,9 @@ + --- + ```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 = { - a: '' - }; -@@ -16,9 +13,6 @@ - "./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +- const a = { +- a: '' +-}; +-}, +-"./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: "" - }; +- const b = { +- b: "" +-}; +-}, +-"./enum-old.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_.a; }, +- 'b': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.b; } +-}); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./a.js"); +-/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./b.js"); +- +- +-}, + "./enum.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _enum_old__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./enum-old */"./enum-old.js"); +-__webpack_require__.es(_enum_old__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + + }, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 414d1d8efb6..c6d4c72f355 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 @@ -3,19 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const a = 103330; - const b = 103330; -}, -"./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); -__webpack_require__.es(_answer__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - -}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -26,8 +13,6 @@ _lib__WEBPACK_IMPORTED_MODULE_0_.a; "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js"); -__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); }, 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 f2cd8fe2f01..ce140b712ca 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,34 @@ --- expected +++ actual -@@ -6,9 +6,6 @@ - "./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -3,22 +3,6 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; } -}); - const a = 103330; - const b = 103330; +- const a = 103330; +- const b = 103330; +-}, +-"./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); +-__webpack_require__.es(_answer__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +- +-}, + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +@@ -29,8 +13,6 @@ + "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js"); +-__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + }, + 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 e7be25eed34..3716ca284cc 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 @@ -22,7 +22,6 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'Lib': function() { return _answer__WEBPACK_IMPORTED_MODULE_0_; } }); -/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); }, 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 f2cd8fe2f01..3ae8796b831 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 @@ -10,3 +10,11 @@ const a = 103330; const b = 103330; }, +@@ -25,7 +22,6 @@ + __webpack_require__.d(__webpack_exports__, { + 'Lib': function() { return _answer__WEBPACK_IMPORTED_MODULE_0_; } + }); +-/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); + + + }, 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 09fab6f8765..626b094e329 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 @@ -34,8 +34,6 @@ __webpack_require__.d(__webpack_exports__, { 'a': function() { return _a_js__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); }, 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 96d627e8475..d49f47d997d 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 @@ -24,7 +24,7 @@ "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -@@ -22,9 +31,11 @@ +@@ -22,9 +31,9 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -32,8 +32,7 @@ + 'a': function() { return _a_js__WEBPACK_IMPORTED_MODULE_0_["default"]; }, + 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); - /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); -+/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); +-/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); }, 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 b3864dc2e01..4ae6be842f6 100644 --- a/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/react-redux-like/snapshot/new_treeshaking.snap @@ -3,24 +3,9 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'Provider': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, - 'useSelector': function() { return _selector_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } -}); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); -/* harmony import */var _selector_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./selector.js */"./selector.js"); - - - -}, "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js"); -__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); function batch() {} @@ -33,19 +18,6 @@ __webpack_require__.r(__webpack_exports__); _foo__WEBPACK_IMPORTED_MODULE_0_.Provider; _foo__WEBPACK_IMPORTED_MODULE_0_.useSelector; }, -"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -function Provider() {} -var __WEBPACK_DEFAULT_EXPORT__ = Provider; -}, -"./selector.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -function useSelector() { - return ""; -} -}, },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } 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 475420f67a4..dcd2732b443 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,21 +1,53 @@ --- expected +++ actual -@@ -36,18 +36,12 @@ - "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -3,24 +3,9 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'Provider': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, +- 'useSelector': function() { return _selector_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } +-}); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); +-/* harmony import */var _selector_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./selector.js */"./selector.js"); +- +- +- +-}, + "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./app */"./app.js"); +-__webpack_require__.es(_app__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + + function batch() {} + +@@ -32,25 +17,6 @@ + + _foo__WEBPACK_IMPORTED_MODULE_0_.Provider; + _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__); +-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 ""; - } +-function useSelector() { +- return ""; +-} + }, + + },function(__webpack_require__) { 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 9be3ebf3428..39289772fce 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 @@ -3,54 +3,9 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./package/autogen/a.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__WEBPACK_IMPORTED_MODULE_0_; } -}); -/* harmony import */var _aa__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./aa */"./package/autogen/aa.js"); - - function a() {} - function dddd() {} - -}, -"./package/autogen/aa.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - 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__); - function b() {} -}, -"./package/autogen/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - function c() {} -}, -"./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_; }, - 'b': function() { return _b__WEBPACK_IMPORTED_MODULE_1_; }, - 'c': function() { return _c__WEBPACK_IMPORTED_MODULE_2_; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./package/autogen/a.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./package/autogen/b.js"); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./package/autogen/c.js"); - - - -}, "./package/src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../autogen/index */"./package/autogen/index.js"); -__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); }, "./src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 83ea39fa783..89a21e1ef53 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,45 +1,47 @@ --- expected +++ actual -@@ -7,7 +7,6 @@ - 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { +@@ -3,44 +3,9 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./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; }, - 'aa': function() { return _aa__WEBPACK_IMPORTED_MODULE_0_; } - }); - /* harmony import */var _aa__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./aa */"./package/autogen/aa.js"); -@@ -19,19 +18,30 @@ - "./package/autogen/aa.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +- 'aa': function() { return _aa__WEBPACK_IMPORTED_MODULE_0_; } +-}); +-/* harmony import */var _aa__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./aa */"./package/autogen/aa.js"); +- +- function a() {} +- function dddd() {} +- +-}, +-"./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; } -}); - 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__); -+ function b() {} -+}, -+"./package/autogen/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+ function c() {} -+}, - "./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +- const aa = 3; +- const cc = 3; +-}, +-"./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_; } +-}); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./package/autogen/a.js"); +- +- +- +-}, + "./package/src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_; } -+ 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_; }, -+ 'b': function() { return _b__WEBPACK_IMPORTED_MODULE_1_; }, -+ 'c': function() { return _c__WEBPACK_IMPORTED_MODULE_2_; } - }); - /* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./package/autogen/a.js"); -+/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./package/autogen/b.js"); -+/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./package/autogen/c.js"); - - +-/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../autogen/index */"./package/autogen/index.js"); +-__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + }, + "./src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 ce0a1504009..a2ad74f8e90 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 @@ -3,42 +3,9 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./package/autogen/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - function a() {} - function dddd() {} -}, -"./package/autogen/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - function b() {} -}, -"./package/autogen/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - function c() {} -}, -"./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_; }, - 'b': function() { return _b__WEBPACK_IMPORTED_MODULE_1_; }, - 'c': function() { return _c__WEBPACK_IMPORTED_MODULE_2_; } -}); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./package/autogen/a.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./package/autogen/b.js"); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./package/autogen/c.js"); - - - -}, "./package/src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../autogen/index */"./package/autogen/index.js"); -__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); }, "./src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 8391c8da673..ad61b5daf55 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,37 +1,34 @@ --- expected +++ actual -@@ -6,19 +6,30 @@ - "./package/autogen/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -3,31 +3,9 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./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; } -}); - function a() {} - function dddd() {} - }, -+"./package/autogen/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+ function b() {} -+}, -+"./package/autogen/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+ function c() {} -+}, - "./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +- function a() {} +- function dddd() {} +-}, +-"./package/autogen/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_; } +-}); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./package/autogen/a.js"); +- +- +- +-}, + "./package/src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -- 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_; } -+ 'a': function() { return _a__WEBPACK_IMPORTED_MODULE_0_; }, -+ 'b': function() { return _b__WEBPACK_IMPORTED_MODULE_1_; }, -+ 'c': function() { return _c__WEBPACK_IMPORTED_MODULE_2_; } - }); - /* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./package/autogen/a.js"); -+/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./package/autogen/b.js"); -+/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./package/autogen/c.js"); - - +-/* harmony import */var _autogen_index__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../autogen/index */"./package/autogen/index.js"); +-__webpack_require__.es(_autogen_index__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + }, + "./src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 f3b5f1f1447..079cc01ccb8 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 @@ -10,8 +10,6 @@ __webpack_require__.d(__webpack_exports__, { 'something': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'b': function() { return _src_a__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); -/* 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"); }, 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 7c415aca8ca..cc05fad08af 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 @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -7,9 +7,11 @@ +@@ -7,9 +7,9 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -8,12 +8,11 @@ + 'something': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, + 'b': function() { return _src_a__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); - /* 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"); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); }, -@@ -24,13 +26,20 @@ +@@ -24,13 +24,20 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 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 dffc8e633d7..326f7516249 100644 --- a/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/new_treeshaking.snap @@ -3,20 +3,9 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```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__); - function test() { - console.log('something'); -} -}, "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); -__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./src/a */"./src/a.js"); -__webpack_require__.es(_src_a__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); // export { // result as test @@ -39,46 +28,6 @@ __webpack_require__.d(__webpack_exports__, { const result = 20000; const something = function() {}; }, -"./src/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _d_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./d.js */"./src/d.js"); - - const a = ()=>{ - (0, _d_js__WEBPACK_IMPORTED_MODULE_0_.test)(); - _d_js__WEBPACK_IMPORTED_MODULE_0_.b; - console.log(""); -}; -}, -"./src/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - '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"); - - const b = 3; -}, -"./src/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'test': function() { return side_effects_module__WEBPACK_IMPORTED_MODULE_0_.test; } -}); -/* harmony import */var side_effects_module__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* side-effects-module */"../node_modules/side-effects-module/index.js"); - -}, -"./src/d.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'test': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.test; }, - 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.b; } -}); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./src/b.js"); - -}, },function(__webpack_require__) { var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } 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 6c92388ec30..9e28a634eb4 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,70 +1,11 @@ --- expected +++ actual -@@ -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__); -+ function test() { -+ console.log('something'); -+} -+}, +@@ -6,8 +6,6 @@ "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); - /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); - __webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -+/* harmony import */var _src_a__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./src/a */"./src/a.js"); -+__webpack_require__.es(_src_a__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); +-__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); // export { // result as test -@@ -30,6 +39,46 @@ - const result = 20000; - const something = function() {}; - }, -+"./src/a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+/* harmony import */var _d_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./d.js */"./src/d.js"); -+ -+ const a = ()=>{ -+ (0, _d_js__WEBPACK_IMPORTED_MODULE_0_.test)(); -+ _d_js__WEBPACK_IMPORTED_MODULE_0_.b; -+ console.log(""); -+}; -+}, -+"./src/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ '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"); -+ -+ const b = 3; -+}, -+"./src/c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'test': function() { return side_effects_module__WEBPACK_IMPORTED_MODULE_0_.test; } -+}); -+/* harmony import */var side_effects_module__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* side-effects-module */"../node_modules/side-effects-module/index.js"); -+ -+}, -+"./src/d.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+__webpack_require__.d(__webpack_exports__, { -+ 'test': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.test; }, -+ 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.b; } -+}); -+/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./src/b.js"); -+ -+}, - - },function(__webpack_require__) { - var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) } 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 8c1ff80c839..dfa9ee450d0 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 @@ -10,8 +10,6 @@ __webpack_require__.d(__webpack_exports__, { 'something': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'b': function() { return _src_a__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); -/* 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"); // export { // result as test 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 1dffbccc59c..07bf9b9f182 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 @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -7,9 +7,11 @@ +@@ -7,9 +7,9 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -8,12 +8,11 @@ + 'something': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, + 'b': function() { return _src_a__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); - /* 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"); +-/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); // export { // result as test -@@ -26,13 +28,20 @@ +@@ -26,13 +26,20 @@ '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 771258395ce..0b02c69b9bf 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 @@ -3,12 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const a = 3; - const b = 3; -}, "./answer.js": function (__unused_webpack_module, exports, __webpack_require__) { const res = __webpack_require__(/* ./lib.js */"./lib.js"); exports.test = function() { @@ -25,8 +19,6 @@ _answer__WEBPACK_IMPORTED_MODULE_0_.test; "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); -__webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); }, 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 72cc586767a..819f7f7eb2b 100644 --- a/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/transitive-bailout/snapshot/snap.diff @@ -1,13 +1,28 @@ --- expected +++ actual -@@ -6,10 +6,6 @@ - "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); +@@ -3,16 +3,6 @@ + --- + ```js title=main.js + (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +-"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; }, - 'b': function() { return b; } -}); - const a = 3; - const b = 3; +- const a = 3; +- const b = 3; +-}, + "./answer.js": function (__unused_webpack_module, exports, __webpack_require__) { + const res = __webpack_require__(/* ./lib.js */"./lib.js"); + exports.test = function() { +@@ -29,8 +19,6 @@ + "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); +-__webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + }, + 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 422c045ba38..a753df8b2db 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 @@ -3,18 +3,12 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); - const a = 3; -}, "./app.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 _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); /* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./side-effects.js */"./side-effects.js"); /* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_1__default = /*#__PURE__*/__webpack_require__.n(_side_effects_js__WEBPACK_IMPORTED_MODULE_1_); 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 deleted file mode 100644 index 6bee0952b6e..00000000000 --- a/crates/rspack/tests/tree-shaking/transitive_side_effects_when_analyze/snapshot/snap.diff +++ /dev/null @@ -1,21 +0,0 @@ ---- expected -+++ actual -@@ -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__); -+ const a = 3; -+}, - "./app.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 _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); - /* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./side-effects.js */"./side-effects.js"); - /* harmony import */var _side_effects_js__WEBPACK_IMPORTED_MODULE_1__default = /*#__PURE__*/__webpack_require__.n(_side_effects_js__WEBPACK_IMPORTED_MODULE_1_); - 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 21f8bed113c..8fcf34ce184 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 @@ -44,7 +44,6 @@ __webpack_require__.d(__webpack_exports__, { '_': function() { return tslib__WEBPACK_IMPORTED_MODULE_0_.__generator; }, '_ts_generator': function() { return tslib__WEBPACK_IMPORTED_MODULE_0_.__generator; } }); -/* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); }, "../../../../../node_modules/tslib/tslib.es6.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 0e1aa172d28..28d65fabc07 100644 --- a/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/ts-target-es5/snapshot/snap.diff @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -41,7 +41,8 @@ +@@ -41,17 +41,14 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -8,9 +8,9 @@ + '_': function() { return tslib__WEBPACK_IMPORTED_MODULE_0_.__generator; }, + '_ts_generator': function() { return tslib__WEBPACK_IMPORTED_MODULE_0_.__generator; } }); - /* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); +-/* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); -@@ -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__); @@ -20,7 +20,7 @@ /****************************************************************************** Copyright (c) Microsoft Corporation. -@@ -482,9 +480,6 @@ +@@ -482,9 +479,6 @@ "./index.ts": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); 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 51d5ba52f34..c9baf210b57 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 @@ -20,6 +20,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__); /* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./inner */"./inner.js"); /* harmony import */var _module__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./module */"./module.js"); +/* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./inner */"./inner.js"); it("export should be unused when only unused functions use it", ()=>{ 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 21e5a17af8b..adbe03b50f5 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 @@ -1,6 +1,14 @@ --- expected +++ actual -@@ -36,6 +36,7 @@ +@@ -20,6 +20,7 @@ + __webpack_require__.r(__webpack_exports__); + /* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./inner */"./inner.js"); + /* harmony import */var _module__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./module */"./module.js"); ++/* harmony import */var _inner__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./inner */"./inner.js"); + + + it("export should be unused when only unused functions use it", ()=>{ +@@ -36,6 +37,7 @@ __webpack_require__.d(__webpack_exports__, { 'A': function() { return A; }, 'B': function() { return B; }, @@ -8,7 +16,7 @@ 'exportAUsed': function() { return exportAUsed; }, 'exportBUsed': function() { return exportBUsed; }, 'exportCUsed': function() { return exportCUsed; } -@@ -49,8 +50,8 @@ +@@ -49,8 +51,8 @@ function C(s) { return s + "C"; } @@ -19,7 +27,7 @@ const exportCUsed = false; }, "./module.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -@@ -84,7 +85,7 @@ +@@ -84,7 +86,7 @@ } function withC(v) { const value = x(v); diff --git a/crates/rspack_core/src/module_graph_module.rs b/crates/rspack_core/src/module_graph_module.rs index bbc7998bc27..ba89d5a976c 100644 --- a/crates/rspack_core/src/module_graph_module.rs +++ b/crates/rspack_core/src/module_graph_module.rs @@ -123,19 +123,19 @@ impl ModuleGraphModule { // } pub fn depended_modules<'a>(&self, module_graph: &'a ModuleGraph) -> Vec<&'a ModuleIdentifier> { - dbg!(&self.module_identifier); + // dbg!(&self.module_identifier); self .outgoing_connections_unordered(module_graph) .unwrap() .filter_map(|con: &ModuleGraphConnection| { // TODO: runtime opt let active_state = con.get_active_state(module_graph, None); - dbg!(&con, &active_state,); - dbg!(&module_graph - .dependency_by_id(&con.dependency_id) - .and_then(|dep| dep - .as_module_dependency() - .map(|item| item.dependency_debug_name()))); + // dbg!(&con, &active_state,); + // dbg!(&module_graph + // .dependency_by_id(&con.dependency_id) + // .and_then(|dep| dep + // .as_module_dependency() + // .map(|item| item.dependency_debug_name()))); match active_state { crate::ConnectionState::Bool(false) => None, _ => Some(con.dependency_id), diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs index 30546bcc7c3..91966b65a25 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs @@ -1,3 +1,5 @@ +use std::ops::ControlFlow; + use rspack_core::tree_shaking::symbol::{self, IndirectTopLevelSymbol}; use rspack_core::tree_shaking::visitor::SymbolRef; use rspack_core::{ @@ -52,166 +54,163 @@ impl HarmonyImportDependency { } } -impl DependencyTemplate for HarmonyImportDependency { - fn apply( - &self, - _source: &mut TemplateReplaceSource, - code_generatable_context: &mut TemplateContext, - ) { - let compilation = &code_generatable_context.compilation; - let module = &code_generatable_context.module; - - let ref_mgm = compilation +pub fn harmony_import_dependency_apply( + module_dependency: &T, + code_generatable_context: &mut TemplateContext, + specifiers: &Vec, +) { + let compilation = &code_generatable_context.compilation; + let module = &code_generatable_context.module; + let ref_mgm = compilation + .module_graph + .module_graph_module_by_dependency_id(module_dependency.id()) + .expect("should have ref module"); + let is_target_active = if compilation.options.is_new_tree_shaking() { + let connection = compilation .module_graph - .module_graph_module_by_dependency_id(&self.id) - .expect("should have ref module"); - let is_target_active = if compilation.options.is_new_tree_shaking() { - let connection = compilation.module_graph.connection_by_dependency(&self.id); - if let Some(con) = connection { - // TODO: runtime opt - con.is_target_active(&compilation.module_graph, None) - } else { - true - } + .connection_by_dependency(module_dependency.id()); + if let Some(con) = connection { + // TODO: runtime opt + con.is_target_active(&compilation.module_graph, None) } else { - compilation - .include_module_ids - .contains(&ref_mgm.module_identifier) - }; - if !is_target_active { - return; + true } + } else { + compilation + .include_module_ids + .contains(&ref_mgm.module_identifier) + }; + if !is_target_active { + return; + } + if !module_dependency.is_export_all() { + let specifiers = specifiers + .iter() + .filter(|specifier| { + let is_import = matches!( + module_dependency.dependency_type(), + DependencyType::EsmImport + ); + if is_import && !ref_mgm.module_type.is_js_like() { + return true; + } - if !self.export_all { - let specifiers = self - .specifiers - .iter() - .filter(|specifier| { - let is_import = matches!(self.dependency_type, DependencyType::EsmImport); - if is_import && !ref_mgm.module_type.is_js_like() { - return true; - } - - match specifier { - Specifier::Namespace(_) => true, - Specifier::Default(local) => { - if is_import { - compilation - .used_symbol_ref - .contains(&SymbolRef::Indirect(IndirectTopLevelSymbol { - src: ref_mgm.module_identifier, - ty: symbol::IndirectType::ImportDefault(local.clone()), - importer: module.identifier(), - dep_id: self.id, - })) - } else { - unreachable!("`export v from ''` is a unrecoverable syntax error") - } - } - Specifier::Named(local, imported) => { - let symbol = if matches!(self.dependency_type, DependencyType::EsmImport) { - SymbolRef::Indirect(IndirectTopLevelSymbol { + match specifier { + Specifier::Namespace(_) => true, + Specifier::Default(local) => { + if is_import { + compilation + .used_symbol_ref + .contains(&SymbolRef::Indirect(IndirectTopLevelSymbol { src: ref_mgm.module_identifier, - ty: symbol::IndirectType::Import(local.clone(), imported.clone()), + ty: symbol::IndirectType::ImportDefault(local.clone()), importer: module.identifier(), - dep_id: self.id, - }) - } else { - SymbolRef::Indirect(IndirectTopLevelSymbol { - src: module.identifier(), - ty: symbol::IndirectType::ReExport(local.clone(), imported.clone()), - importer: module.identifier(), - dep_id: self.id, - }) - }; - - compilation.used_symbol_ref.contains(&symbol) + dep_id: *module_dependency.id(), + })) + } else { + unreachable!("`export v from ''` is a unrecoverable syntax error") } } - }) - .collect::>(); - - if specifiers.is_empty() - && compilation - .side_effects_free_modules - .contains(&ref_mgm.module_identifier) - { - return; - } - } + Specifier::Named(local, imported) => { + let symbol = if matches!( + module_dependency.dependency_type(), + DependencyType::EsmImport + ) { + SymbolRef::Indirect(IndirectTopLevelSymbol { + src: ref_mgm.module_identifier, + ty: symbol::IndirectType::Import(local.clone(), imported.clone()), + importer: module.identifier(), + dep_id: *module_dependency.id(), + }) + } else { + SymbolRef::Indirect(IndirectTopLevelSymbol { + src: module.identifier(), + ty: symbol::IndirectType::ReExport(local.clone(), imported.clone()), + importer: module.identifier(), + dep_id: *module_dependency.id(), + }) + }; - let content: (String, String) = - import_statement(code_generatable_context, &self.id, &self.request, false); - - let TemplateContext { - init_fragments, - compilation, - module, - runtime_requirements, - .. - } = code_generatable_context; + compilation.used_symbol_ref.contains(&symbol) + } + } + }) + .collect::>(); - let ref_module = compilation - .module_graph - .module_identifier_by_dependency_id(&self.id) - .expect("should have dependency referenced module"); - let import_var = compilation - .module_graph - .get_import_var(&module.identifier(), &self.request); - if compilation.module_graph.is_async(ref_module) { - init_fragments.push(Box::new(NormalInitFragment::new( - content.0, - InitFragmentStage::StageHarmonyImports, - None, - ))); - init_fragments.push(Box::new(NormalInitFragment::new( + if specifiers.is_empty() + && compilation + .side_effects_free_modules + .contains(&ref_mgm.module_identifier) + { + return; + } + } + let content: (String, String) = import_statement( + code_generatable_context, + module_dependency.id(), + module_dependency.request(), + false, + ); + let TemplateContext { + init_fragments, + compilation, + module, + runtime_requirements, + .. + } = code_generatable_context; + let ref_module = compilation + .module_graph + .module_identifier_by_dependency_id(module_dependency.id()) + .expect("should have dependency referenced module"); + let import_var = compilation + .module_graph + .get_import_var(&module.identifier(), module_dependency.request()); + if compilation.module_graph.is_async(ref_module) { + init_fragments.push(Box::new(NormalInitFragment::new( + content.0, + InitFragmentStage::StageHarmonyImports, + None, + ))); + init_fragments.push(Box::new(NormalInitFragment::new( format!( "var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([{import_var}]);\n([{import_var}] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);" ), InitFragmentStage::StageHarmonyImports, None, ))); - init_fragments.push(Box::new(NormalInitFragment::new( - content.1, - InitFragmentStage::StageAsyncHarmonyImports, - None, - ))); - } else { - init_fragments.push(Box::new(NormalInitFragment::new( - format!("{}{}", content.0, content.1), - InitFragmentStage::StageHarmonyImports, - None, - ))); - } - if self.export_all { - // let connection = compilation.module_graph.connection_by_dependency(&self.id); - // if let Some(con) = connection { - // // TODO: runtime opt - // let active = con.is_target_active(&compilation.module_graph, None); - // if !active { - // return; - // } - // } - runtime_requirements.insert(RuntimeGlobals::EXPORT_STAR); - let exports_argument = compilation - .module_graph - .module_graph_module_by_identifier(&module.identifier()) - .expect("should have mgm") - .get_exports_argument(); - init_fragments.push(Box::new(NormalInitFragment::new( - format!( - "{}.{}({import_var}, {exports_argument});\n", - RuntimeGlobals::REQUIRE, - RuntimeGlobals::EXPORT_STAR, - ), - if compilation.module_graph.is_async(ref_module) { - InitFragmentStage::StageAsyncHarmonyImports - } else { - InitFragmentStage::StageHarmonyImports - }, - None, - ))); - } + init_fragments.push(Box::new(NormalInitFragment::new( + content.1, + InitFragmentStage::StageAsyncHarmonyImports, + None, + ))); + } else { + init_fragments.push(Box::new(NormalInitFragment::new( + format!("{}{}", content.0, content.1), + InitFragmentStage::StageHarmonyImports, + None, + ))); + } + + if module_dependency.is_export_all() { + runtime_requirements.insert(RuntimeGlobals::EXPORT_STAR); + let exports_argument = compilation + .module_graph + .module_graph_module_by_identifier(&module.identifier()) + .expect("should have mgm") + .get_exports_argument(); + init_fragments.push(Box::new(NormalInitFragment::new( + format!( + "{}.{}({import_var}, {exports_argument});\n", + RuntimeGlobals::REQUIRE, + RuntimeGlobals::EXPORT_STAR, + ), + if compilation.module_graph.is_async(ref_module) { + InitFragmentStage::StageAsyncHarmonyImports + } else { + InitFragmentStage::StageHarmonyImports + }, + None, + ))); } } @@ -297,3 +296,13 @@ impl ModuleDependency for HarmonyImportDependency { "HarmonyImportDependency" } } + +impl DependencyTemplate for HarmonyImportDependency { + fn apply( + &self, + _source: &mut TemplateReplaceSource, + code_generatable_context: &mut TemplateContext, + ) { + harmony_import_dependency_apply(self, code_generatable_context, &self.specifiers); + } +} 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 d26b8dc480f..51bda7bcc8d 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 @@ -10,7 +10,9 @@ use rspack_core::{ use rustc_hash::FxHashSet as HashSet; use swc_core::ecma::atoms::JsWord; -use super::{create_resource_identifier_for_esm_dependency, Specifier}; +use super::{ + create_resource_identifier_for_esm_dependency, harmony_import_dependency_apply, Specifier, +}; #[derive(Debug, Clone)] pub struct HarmonyImportSpecifierDependency { @@ -130,6 +132,27 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { .module_graph_module_by_dependency_id(&self.id) .expect("should have ref module"); + let compilation = &code_generatable_context.compilation; + let ref_mgm = compilation + .module_graph + .module_graph_module_by_dependency_id(&self.id) + .expect("should have ref module"); + let is_target_active = if compilation.options.is_new_tree_shaking() { + let connection = compilation.module_graph.connection_by_dependency(&self.id); + if let Some(con) = connection { + // TODO: runtime opt + con.is_target_active(&compilation.module_graph, None) + } else { + true + } + } else { + compilation + .include_module_ids + .contains(&ref_mgm.module_identifier) + }; + if !is_target_active { + return; + } let used = self.check_used(reference_mgm, compilation); if !used { @@ -148,6 +171,12 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { .module_graph .get_import_var(&code_generatable_context.module.identifier(), &self.request); + // TODO: scope hoist + harmony_import_dependency_apply( + self, + code_generatable_context, + &vec![self.specifier.clone()], + ); let export_expr = export_from_import( code_generatable_context, true, From 45cc1d6a2cdd62feccf4412a4e87ca37e39643b1 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 18:28:58 +0800 Subject: [PATCH 10/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20snapshot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../snapshot/new_treeshaking.snap | 15 +++- .../snapshot/snap.diff | 28 ------- .../snapshot/new_treeshaking.snap | 21 ----- .../snapshot/snap.diff | 43 +++++------ .../snapshot/new_treeshaking.snap | 7 +- .../snapshot/snap.diff | 22 ------ .../snapshot/new_treeshaking.snap | 7 +- .../snapshot/snap.diff | 23 ------ .../export_star/snapshot/new_treeshaking.snap | 28 ++++++- .../export_star/snapshot/snap.diff | 52 +++---------- .../snapshot/new_treeshaking.snap | 39 +++++++++- .../export_star2/snapshot/snap.diff | 55 ------------- .../snapshot/new_treeshaking.snap | 28 ++++++- .../snapshot/snap.diff | 47 ----------- .../snapshot/new_treeshaking.snap | 3 +- .../snapshot/snap.diff | 9 ++- .../snapshot/new_treeshaking.snap | 16 +++- .../snapshot/snap.diff | 58 +++++--------- .../snapshot/new_treeshaking.snap | 1 - .../snapshot/snap.diff | 10 +++ .../snapshot/new_treeshaking.snap | 6 -- .../named_export_alias/snapshot/snap.diff | 22 ------ .../snapshot/new_treeshaking.snap | 2 - .../snapshot/snap.diff | 5 +- .../snapshot/new_treeshaking.snap | 28 +------ .../snapshot/snap.diff | 77 +++++++++++-------- .../snapshot/new_treeshaking.snap | 1 - .../snapshot/snap.diff | 10 --- .../snapshot/new_treeshaking.snap | 6 -- .../snapshot/snap.diff | 29 +++++-- .../snapshot/new_treeshaking.snap | 6 +- .../snapshot/snap.diff | 26 ++++++- .../snapshot/new_treeshaking.snap | 17 +--- .../snapshot/snap.diff | 43 +++++------ crates/rspack_core/src/dependency/mod.rs | 4 +- crates/rspack_core/src/module_graph_module.rs | 2 +- .../esm/harmony_import_dependency.rs | 8 +- 37 files changed, 321 insertions(+), 483 deletions(-) delete mode 100644 crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/snap.diff create mode 100644 crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/named_export_alias/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/snap.diff 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 731c0bc7ae1..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 @@ -3,12 +3,23 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); + const a = 'bar'; +}, +"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); + const a = 'foo'; + const b = 'foo'; +}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* 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__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); 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 d0a1b07ce96..00000000000 --- a/crates/rspack/tests/tree-shaking/conflicted_name_by_re_export_all_should_be_hidden/snapshot/snap.diff +++ /dev/null @@ -1,28 +0,0 @@ ---- expected -+++ actual -@@ -3,23 +3,12 @@ - --- - ```js title=main.js - (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { --"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); -- const a = 'bar'; --}, --"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); -- const a = 'foo'; -- const b = 'foo'; --}, - "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); --/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); -+/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); --/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); -+/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - - 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 a312beb8439..d45024e504b 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 @@ -21,10 +21,6 @@ var __WEBPACK_DEFAULT_EXPORT__ = Index; "./src/containers/containers.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _platform_container__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./platform-container */"./src/containers/platform-container/index.js"); -__webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _page_container__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./page-container */"./src/containers/page-container/index.js"); -__webpack_require__.es(_page_container__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); }, @@ -34,25 +30,8 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'containers': function() { return _containers__WEBPACK_IMPORTED_MODULE_0_; } }); -/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); -}, -"./src/containers/page-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../containers */"./src/containers/containers.js"); - -_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; } -}); - const usePlatform = 3; - const PlatformProvider = 1000; }, "./src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; diff --git a/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/snap.diff index d2d7a788ca2..0cc2f177151 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 @@ -1,32 +1,31 @@ --- expected +++ actual -@@ -23,6 +23,8 @@ +@@ -21,8 +21,6 @@ + "./src/containers/containers.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; __webpack_require__.r(__webpack_exports__); - /* harmony import */var _platform_container__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./platform-container */"./src/containers/platform-container/index.js"); - __webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -+/* harmony import */var _page_container__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./page-container */"./src/containers/page-container/index.js"); -+__webpack_require__.es(_page_container__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +-/* harmony import */var _platform_container__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./platform-container */"./src/containers/platform-container/index.js"); +-__webpack_require__.es(_platform_container__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); }, -@@ -36,12 +38,18 @@ +@@ -32,19 +30,8 @@ + __webpack_require__.d(__webpack_exports__, { + 'containers': function() { return _containers__WEBPACK_IMPORTED_MODULE_0_; } + }); +-/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); - }, -+"./src/containers/page-container/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+'use strict'; -+__webpack_require__.r(__webpack_exports__); -+/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ../containers */"./src/containers/containers.js"); -+ -+_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__, { +-}, +-"./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; } -+ 'usePlatform': function() { return usePlatform; } - }); - const usePlatform = 3; - const PlatformProvider = 1000; +-}); +- const usePlatform = 3; +- const PlatformProvider = 1000; + }, + "./src/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; 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 1f2d7bf1928..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 @@ -3,13 +3,18 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); + 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; } }); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); const a = 'foo'; 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 7e6929abfd6..00000000000 --- a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_1/snapshot/snap.diff +++ /dev/null @@ -1,22 +0,0 @@ ---- expected -+++ actual -@@ -3,18 +3,13 @@ - --- - ```js title=main.js - (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { --"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); -- 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; } - }); --/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); -+/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - const a = 'foo'; - 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 4602ad4918e..bd579c58e56 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 @@ -3,6 +3,11 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); + const a = 'bar'; +}, "./baz.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -18,7 +23,7 @@ __webpack_require__.d(__webpack_exports__, { 'a': function() { return _baz__WEBPACK_IMPORTED_MODULE_0_.a; } }); /* harmony import */var _baz__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./baz */"./baz.js"); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); 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 deleted file mode 100644 index b415d8c3ef2..00000000000 --- a/crates/rspack/tests/tree-shaking/explicit_named_export_higher_priority_2/snapshot/snap.diff +++ /dev/null @@ -1,23 +0,0 @@ ---- expected -+++ actual -@@ -3,11 +3,6 @@ - --- - ```js title=main.js - (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { --"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); -- const a = 'bar'; --}, - "./baz.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -@@ -23,7 +18,7 @@ - 'a': function() { return _baz__WEBPACK_IMPORTED_MODULE_0_.a; } - }); - /* harmony import */var _baz__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./baz */"./baz.js"); --/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); -+/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - - 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 0fbb3404f35..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 @@ -3,12 +3,25 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"./bar.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_; } +}); +/* 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"); +__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + function b() {} + + +}, "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* 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__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); __webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); const a = 3; const foo = 3; @@ -22,6 +35,17 @@ __webpack_require__.r(__webpack_exports__); _foo__WEBPACK_IMPORTED_MODULE_0_.bar.a; (0, _foo__WEBPACK_IMPORTED_MODULE_0_.c)(); +}, +"./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); +__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); +__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + const c = 103330; + + }, },function(__webpack_require__) { 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 98ab1bed4db..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,54 +1,22 @@ --- expected +++ actual -@@ -3,28 +3,12 @@ - --- - ```js title=main.js - (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { --"./bar.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_; } --}); --/* 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"); --__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -- function b() {} -- -- --}, +@@ -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__, { - 'a': function() { return a; } -}); --/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar */"./bar.js"); -+/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); + /* 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"); -+/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - const a = 3; - const foo = 3; -@@ -38,20 +22,6 @@ - - _foo__WEBPACK_IMPORTED_MODULE_0_.bar.a; - (0, _foo__WEBPACK_IMPORTED_MODULE_0_.c)(); --}, --"./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__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"); --__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -- const c = 103330; -- -- - }, - - },function(__webpack_require__) { + /* 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 3a5412b3b67..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 @@ -3,18 +3,51 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); +__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); +__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + function b() {} + + +}, +"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +/* 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"); +__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + const a = 3; + + +}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* 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__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./result */"./result.js"); __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__); +/* 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"); +__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + const c = 103330; + + }, },function(__webpack_require__) { 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 41fb6eeb428..00000000000 --- a/crates/rspack/tests/tree-shaking/export_star2/snapshot/snap.diff +++ /dev/null @@ -1,55 +0,0 @@ ---- expected -+++ actual -@@ -3,49 +3,16 @@ - --- - ```js title=main.js - (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { --"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); --/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); --__webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); --/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result */"./result.js"); --__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -- function b() {} -- -- --}, --"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); --/* 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"); --__webpack_require__.es(_result__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -- const a = 3; -- -- --}, - "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); --/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); -+/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); --/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); -+/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './bar''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); --/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./result */"./result.js"); -+/* harmony import */var _result__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __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__); --/* 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"); --__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -- const c = 103330; - - - }, 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 5cd7f1fcf1a..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 @@ -9,13 +9,25 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'b': function() { return b; } }); -/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* 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 _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result.js */"./result.js"); __webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); function b() {} +}, +"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +/* 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"); +__webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + const a = 3; + const b = 3; + + }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; @@ -23,6 +35,18 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar.js */"./bar.js"); (0, _bar_js__WEBPACK_IMPORTED_MODULE_0_.b)(); +}, +"./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +/* 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"); +__webpack_require__.es(_bar_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + const c = 103330; + const b = 103330; + + }, },function(__webpack_require__) { 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 428bfaa515f..00000000000 --- a/crates/rspack/tests/tree-shaking/export_star_conflict_export_no_error/snapshot/snap.diff +++ /dev/null @@ -1,47 +0,0 @@ ---- expected -+++ actual -@@ -9,23 +9,11 @@ - __webpack_require__.d(__webpack_exports__, { - 'b': function() { return b; } - }); --/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo.js */"./foo.js"); -+/* harmony import */var _foo_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_foo_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); --/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./result.js */"./result.js"); -+/* harmony import */var _result_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './result.js''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - function b() {} -- -- --}, --"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); --/* 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"); --__webpack_require__.es(_result_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -- const a = 3; -- const b = 3; - - - }, -@@ -35,18 +23,6 @@ - /* harmony import */var _bar_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./bar.js */"./bar.js"); - - (0, _bar_js__WEBPACK_IMPORTED_MODULE_0_.b)(); --}, --"./result.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); --/* 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"); --__webpack_require__.es(_bar_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -- const c = 103330; -- const b = 103330; -- -- - }, - - },function(__webpack_require__) { 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 2adaf1e2869..237247ec4cb 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 @@ -21,8 +21,6 @@ __webpack_require__.d(__webpack_exports__, { 'Layout': function() { return _layout_export__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'Sider': function() { return _Something__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); -/* harmony import */var _layout_export__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./layout_export */"./layout_export.js"); -/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); @@ -39,6 +37,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.r(__webpack_exports__); /* 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"); +/* harmony import */var _Layout_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout.js */"./Layout.js"); _Layout_js__WEBPACK_IMPORTED_MODULE_0_["default"].sider = _Something_js__WEBPACK_IMPORTED_MODULE_1_["default"]; 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 13169ed56cd..f717e54edca 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 @@ -18,18 +18,18 @@ class Something { } }, -@@ -16,8 +18,10 @@ +@@ -16,9 +18,9 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { + 'Layout': function() { return _layout_export__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'Sider': function() { return _Something__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); -+/* harmony import */var _layout_export__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./layout_export */"./layout_export.js"); - /* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); +-/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); -@@ -30,6 +34,16 @@ + +@@ -30,6 +32,17 @@ (0, _export__WEBPACK_IMPORTED_MODULE_0_.Sider)(); }, @@ -38,6 +38,7 @@ +__webpack_require__.r(__webpack_exports__); +/* 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"); ++/* harmony import */var _Layout_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout.js */"./Layout.js"); + + +_Layout_js__WEBPACK_IMPORTED_MODULE_0_["default"].sider = _Something_js__WEBPACK_IMPORTED_MODULE_1_["default"]; 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 9e689bfb961..f6b34955491 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 @@ -3,6 +3,11 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { +"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); + const c = 'a'; +}, "./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -18,7 +23,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'a': function() { return a; } }); -/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); +/* 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"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); @@ -26,6 +31,15 @@ __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); const a = 3; }, +"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); +__webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + + const a = 'foo'; + const b = 'foo'; +}, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__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 0bdd108e1c4..8ddaf3b9fb0 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,48 +1,30 @@ --- expected +++ actual -@@ -3,17 +3,12 @@ - --- - ```js title=main.js - (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { --"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -+"./bar.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -6,14 +6,14 @@ + "./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__, { +- '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__, { ++ 'c': function() { return c; } ++}); const a = 'bar'; const c = 'bar'; }, -@@ -23,25 +18,13 @@ - __webpack_require__.d(__webpack_exports__, { - 'a': function() { return a; } - }); --/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./foo */"./foo.js"); -+/* harmony import */var _foo__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(Object(function webpackMissingModule() { var e = new Error('Cannot find module './foo''); e.code = 'MODULE_NOT_FOUND'; throw e; }())); - __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); - __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - - - const a = 3; --}, --"./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); +@@ -34,9 +34,6 @@ + "./foo.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 _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); --__webpack_require__.es(_a_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -- -- const a = 'foo'; -- const b = 'foo'; - }, - "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; + /* 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/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 aba7c01a3bf..844458392d6 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 @@ -35,7 +35,6 @@ __webpack_require__.d(__webpack_exports__, { }); /* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); /* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./c.js"); var L = _Layout__WEBPACK_IMPORTED_MODULE_0_["default"]; 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 new file mode 100644 index 00000000000..a54b8ca9112 --- /dev/null +++ b/crates/rspack/tests/tree-shaking/named-export-decl-with-src-eval/snapshot/snap.diff @@ -0,0 +1,10 @@ +--- expected ++++ actual +@@ -35,7 +35,6 @@ + }); + /* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); + /* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); +-/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./c.js"); + + + var L = _Layout__WEBPACK_IMPORTED_MODULE_0_["default"]; 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 4a5710ab73e..5bd4a8e79d8 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 @@ -3,11 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```js title=main.js (self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], { -"./Layout.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -function Layout() {} -}, "./Something.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -22,7 +17,6 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'default': function() { return a; } }); -/* 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_alias/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/snap.diff deleted file mode 100644 index a1a19200ba3..00000000000 --- a/crates/rspack/tests/tree-shaking/named_export_alias/snapshot/snap.diff +++ /dev/null @@ -1,22 +0,0 @@ ---- expected -+++ actual -@@ -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__); -+function Layout() {} -+}, - "./Something.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -@@ -17,6 +22,7 @@ - __webpack_require__.d(__webpack_exports__, { - 'default': function() { return a; } - }); -+/* 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/reexport_entry_elimination/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/reexport_entry_elimination/snapshot/new_treeshaking.snap index 6fc712822cc..c88588a7601 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 @@ -10,8 +10,6 @@ __webpack_require__.d(__webpack_exports__, { 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'c': function() { return _c_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); -/* 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"); }, 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 95848703fd8..040101b85af 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,18 +7,17 @@ +@@ -7,18 +7,15 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -8,8 +8,7 @@ + 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_["default"]; }, + 'c': function() { return _c_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); - /* 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"); +-/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); }, 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 e85621e7bc4..651c4b2a56a 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 @@ -15,15 +15,6 @@ function abc() { return _dep_a__WEBPACK_IMPORTED_MODULE_0_.x; } }, -"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?b */"./dep.js?b"); - -function abc() { - return _dep_b__WEBPACK_IMPORTED_MODULE_0_.x; -} -}, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -62,7 +53,6 @@ var __WEBPACK_DEFAULT_EXPORT__ = false; 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'x': function() { return x; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -92,7 +82,6 @@ var __WEBPACK_DEFAULT_EXPORT__ = false; 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { - 'x': function() { return x; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -108,17 +97,6 @@ __webpack_require__.d(__webpack_exports__, { const x = "x"; var __WEBPACK_DEFAULT_EXPORT__ = false; }, -"./e.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -/* harmony import */var _dep_e__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?e */"./dep.js?e"); - -class def { - method() { - return _dep_e__WEBPACK_IMPORTED_MODULE_0_.x; - } -} -}, "./f.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -134,12 +112,10 @@ new def().method(); "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./a.js"); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./b.js"); /* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./c.js"); -/* harmony import */var _d__WEBPACK_IMPORTED_MODULE_3_ = __webpack_require__(/* ./d */"./d.js"); -/* harmony import */var _e__WEBPACK_IMPORTED_MODULE_4_ = __webpack_require__(/* ./e */"./e.js"); /* harmony import */var _f__WEBPACK_IMPORTED_MODULE_5_ = __webpack_require__(/* ./f */"./f.js"); +/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./a.js"); +/* harmony import */var _d__WEBPACK_IMPORTED_MODULE_3_ = __webpack_require__(/* ./d */"./d.js"); /* harmony import */var _dep_a__WEBPACK_IMPORTED_MODULE_6_ = __webpack_require__(/* ./dep?a */"./dep.js?a"); /* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_7_ = __webpack_require__(/* ./dep?b */"./dep.js?b"); /* harmony import */var _dep_c__WEBPACK_IMPORTED_MODULE_8_ = __webpack_require__(/* ./dep?c */"./dep.js?c"); 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 d7a576dd834..53808cb9b40 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,15 +1,22 @@ --- expected +++ actual -@@ -21,7 +21,7 @@ - /* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?b */"./dep.js?b"); - - function abc() { -- return /* "./dep?b" unused */null; -+ return _dep_b__WEBPACK_IMPORTED_MODULE_0_.x; +@@ -15,15 +15,6 @@ + return _dep_a__WEBPACK_IMPORTED_MODULE_0_.x; } }, +-"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?b */"./dep.js?b"); +- +-function abc() { +- return /* "./dep?b" unused */null; +-} +-}, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -@@ -56,12 +56,13 @@ + 'use strict'; + __webpack_require__.r(__webpack_exports__); +@@ -56,7 +47,7 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -18,13 +25,7 @@ }, "./dep.js?b": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'x': function() { return x; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } - }); - const x = "x"; -@@ -75,7 +76,7 @@ +@@ -75,7 +66,7 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -33,7 +34,7 @@ }, "./dep.js?d": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; -@@ -85,12 +86,13 @@ +@@ -85,7 +76,7 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; @@ -42,27 +43,39 @@ }, "./dep.js?e": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; - __webpack_require__.r(__webpack_exports__); - __webpack_require__.d(__webpack_exports__, { -+ 'x': function() { return x; }, - 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } - }); - const x = "x"; -@@ -104,7 +106,7 @@ +@@ -104,19 +95,8 @@ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); const x = "x"; -var __WEBPACK_DEFAULT_EXPORT__ = true; +var __WEBPACK_DEFAULT_EXPORT__ = false; }, - "./e.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; -@@ -113,7 +115,7 @@ - - class def { - method() { +-"./e.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-/* harmony import */var _dep_e__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./dep?e */"./dep.js?e"); +- +-class def { +- method() { - return /* "./dep?e" unused */null; -+ return _dep_e__WEBPACK_IMPORTED_MODULE_0_.x; - } - } - }, +- } +-} +-}, + "./f.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +@@ -132,12 +112,10 @@ + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); ++/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./c.js"); ++/* harmony import */var _f__WEBPACK_IMPORTED_MODULE_5_ = __webpack_require__(/* ./f */"./f.js"); + /* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"./a.js"); +-/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"./b.js"); +-/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./c.js"); + /* harmony import */var _d__WEBPACK_IMPORTED_MODULE_3_ = __webpack_require__(/* ./d */"./d.js"); +-/* harmony import */var _e__WEBPACK_IMPORTED_MODULE_4_ = __webpack_require__(/* ./e */"./e.js"); +-/* harmony import */var _f__WEBPACK_IMPORTED_MODULE_5_ = __webpack_require__(/* ./f */"./f.js"); + /* harmony import */var _dep_a__WEBPACK_IMPORTED_MODULE_6_ = __webpack_require__(/* ./dep?a */"./dep.js?a"); + /* harmony import */var _dep_b__WEBPACK_IMPORTED_MODULE_7_ = __webpack_require__(/* ./dep?b */"./dep.js?b"); + /* harmony import */var _dep_c__WEBPACK_IMPORTED_MODULE_8_ = __webpack_require__(/* ./dep?c */"./dep.js?c"); 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 2f479dc3076..3e7c731cd70 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 @@ -6,7 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./chunk.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* 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 deleted file mode 100644 index 2004564657b..00000000000 --- a/crates/rspack/tests/tree-shaking/webpack-inner-graph-switch/snapshot/snap.diff +++ /dev/null @@ -1,10 +0,0 @@ ---- expected -+++ actual -@@ -6,6 +6,7 @@ - "./chunk.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -+/* 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-reexport-namespace-and-default/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-reexport-namespace-and-default/snapshot/new_treeshaking.snap index c3e5a48c507..52f81d4ac55 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 @@ -31,7 +31,6 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'mod': function() { return mod; } }); -/* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./package1/script */"./package1/script.js"); /* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./package2/script */"./package2/script.js"); @@ -44,7 +43,6 @@ __webpack_require__.d(__webpack_exports__, { 'exportDefaultUsed': function() { return exportDefaultUsed; } }); /* harmony import */var _script1__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script1 */"./package1/script1.js"); -__webpack_require__.es(_script1__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); var __WEBPACK_DEFAULT_EXPORT__ = _script1__WEBPACK_IMPORTED_MODULE_0_["default"]; @@ -56,8 +54,6 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); -/* harmony import */var _script2__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script2 */"./package1/script2.js"); -__webpack_require__.es(_script2__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); var __WEBPACK_DEFAULT_EXPORT__ = 1; }, @@ -68,7 +64,6 @@ __webpack_require__.d(__webpack_exports__, { 'exportDefaultUsed': function() { return exportDefaultUsed; } }); /* harmony import */var _script3__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script3 */"./package1/script3.js"); -__webpack_require__.es(_script3__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); function __WEBPACK_DEFAULT_EXPORT__(){ return _script3__WEBPACK_IMPORTED_MODULE_0_["default"]; @@ -92,7 +87,6 @@ __webpack_require__.d(__webpack_exports__, { 'exportDefaultUsed': function() { return exportDefaultUsed; } }); /* harmony import */var _script1__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script1 */"./package2/script1.js"); -__webpack_require__.es(_script1__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); var __WEBPACK_DEFAULT_EXPORT__ = _script1__WEBPACK_IMPORTED_MODULE_0_["default"]; 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 a7fc803a3f3..78a8cf05d69 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,8 +1,18 @@ --- expected +++ actual -@@ -46,13 +46,16 @@ +@@ -31,7 +31,6 @@ + __webpack_require__.d(__webpack_exports__, { + 'mod': function() { return mod; } + }); +-/* harmony import */var _package1_script__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./package1/script */"./package1/script.js"); + /* harmony import */var _package2_script__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./package2/script */"./package2/script.js"); + + +@@ -44,17 +43,17 @@ + 'exportDefaultUsed': function() { return exportDefaultUsed; } + }); /* harmony import */var _script1__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script1 */"./package1/script1.js"); - __webpack_require__.es(_script1__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +-__webpack_require__.es(_script1__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -var __WEBPACK_DEFAULT_EXPORT__ = /* "./script1" unused */null; +var __WEBPACK_DEFAULT_EXPORT__ = _script1__WEBPACK_IMPORTED_MODULE_0_["default"]; @@ -12,18 +22,19 @@ "./package1/script1.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); +-/* harmony import */var _script2__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script2 */"./package1/script2.js"); +-__webpack_require__.es(_script2__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +__webpack_require__.d(__webpack_exports__, { + 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } +}); - /* harmony import */var _script2__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script2 */"./package1/script2.js"); - __webpack_require__.es(_script2__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -@@ -64,13 +67,23 @@ + var __WEBPACK_DEFAULT_EXPORT__ = 1; + }, +@@ -64,13 +63,22 @@ __webpack_require__.d(__webpack_exports__, { 'exportDefaultUsed': function() { return exportDefaultUsed; } }); +/* harmony import */var _script3__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script3 */"./package1/script3.js"); -+__webpack_require__.es(_script3__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); function __WEBPACK_DEFAULT_EXPORT__(){ - return /* "./script3" unused */null; @@ -43,7 +54,11 @@ "./package2/script.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -@@ -83,7 +96,7 @@ +@@ -79,11 +87,10 @@ + 'exportDefaultUsed': function() { return exportDefaultUsed; } + }); + /* harmony import */var _script1__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./script1 */"./package2/script1.js"); +-__webpack_require__.es(_script1__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); 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 86dbf936ed2..576f1fd8715 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 @@ -24,7 +24,6 @@ __webpack_require__.d(__webpack_exports__, { 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, 'x': function() { return x; } }); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var x = "x"; var y = "y"; @@ -54,9 +53,6 @@ __webpack_require__.d(__webpack_exports__, { 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"../node_modules/pmodule/a.js"); -__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); @@ -83,8 +79,8 @@ __webpack_require__.d(__webpack_exports__, { "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); /* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); +/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); diff --git a/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-side-effects-all-used/snapshot/snap.diff index 12e3e7d7fa1..b5532af7410 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,6 +1,14 @@ --- expected +++ actual -@@ -50,6 +50,7 @@ +@@ -24,7 +24,6 @@ + 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, + 'x': function() { return x; } + }); +-/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + var x = "x"; + var y = "y"; +@@ -50,12 +49,10 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'x': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.x; }, @@ -8,3 +16,19 @@ 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); +-/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"../node_modules/pmodule/a.js"); +-__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +-/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + + +@@ -82,8 +79,8 @@ + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); +-/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); + /* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); ++/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); + + + diff --git a/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/new_treeshaking.snap index 4192d94eace..b12335dbfa0 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 @@ -3,17 +3,6 @@ source: crates/rspack_testing/src/run_fixture.rs --- ```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__); -/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); -var a = "a"; -var b = "b"; -var c = "c"; - - -(0, _tracker__WEBPACK_IMPORTED_MODULE_0_.track)("a.js"); -}, "../node_modules/pmodule/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); @@ -21,7 +10,6 @@ __webpack_require__.d(__webpack_exports__, { 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, 'x': function() { return x; } }); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var x = "x"; var y = "y"; @@ -51,9 +39,6 @@ __webpack_require__.d(__webpack_exports__, { 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); -/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"../node_modules/pmodule/a.js"); -__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); @@ -80,8 +65,8 @@ __webpack_require__.d(__webpack_exports__, { "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); /* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); +/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); diff --git a/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/webpack-side-effects-simple-unused/snapshot/snap.diff index 69f970ed91f..5c38c283cfa 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,24 +1,14 @@ --- expected +++ actual -@@ -3,6 +3,17 @@ - --- - ```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__); -+/* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); -+var a = "a"; -+var b = "b"; -+var c = "c"; -+ -+ -+(0, _tracker__WEBPACK_IMPORTED_MODULE_0_.track)("a.js"); -+}, - "../node_modules/pmodule/b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); -@@ -36,9 +47,12 @@ +@@ -10,7 +10,6 @@ + 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, + 'x': function() { return x; } + }); +-/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); + /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + var x = "x"; + var y = "y"; +@@ -36,10 +35,10 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'x': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.x; }, @@ -26,8 +16,17 @@ 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); -+/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"../node_modules/pmodule/a.js"); -+__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - /* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); +-/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); + +@@ -66,8 +65,8 @@ + "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; + __webpack_require__.r(__webpack_exports__); ++/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); + /* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); +-/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); + + + diff --git a/crates/rspack_core/src/dependency/mod.rs b/crates/rspack_core/src/dependency/mod.rs index 5208fbf0021..eea740777c5 100644 --- a/crates/rspack_core/src/dependency/mod.rs +++ b/crates/rspack_core/src/dependency/mod.rs @@ -391,8 +391,8 @@ pub trait ModuleDependency: Dependency { None } - fn is_export_all(&self) -> bool { - false + fn is_export_all(&self) -> Option { + None } } diff --git a/crates/rspack_core/src/module_graph_module.rs b/crates/rspack_core/src/module_graph_module.rs index ba89d5a976c..623d57ab83c 100644 --- a/crates/rspack_core/src/module_graph_module.rs +++ b/crates/rspack_core/src/module_graph_module.rs @@ -147,7 +147,7 @@ impl ModuleGraphModule { .expect("should have id") .as_module_dependency() { - return !is_async_dependency(dep) && !dep.weak() && !dep.is_export_all(); + return !is_async_dependency(dep) && !dep.weak(); } false }) 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 91966b65a25..2fdd0bb24d7 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 @@ -83,7 +83,7 @@ pub fn harmony_import_dependency_apply( if !is_target_active { return; } - if !module_dependency.is_export_all() { + if module_dependency.is_export_all() == Some(false) { let specifiers = specifiers .iter() .filter(|specifier| { @@ -191,7 +191,7 @@ pub fn harmony_import_dependency_apply( ))); } - if module_dependency.is_export_all() { + if module_dependency.is_export_all() == Some(true) { runtime_requirements.insert(RuntimeGlobals::EXPORT_STAR); let exports_argument = compilation .module_graph @@ -244,8 +244,8 @@ impl Dependency for HarmonyImportDependency { } impl ModuleDependency for HarmonyImportDependency { - fn is_export_all(&self) -> bool { - self.export_all + fn is_export_all(&self) -> Option { + Some(self.export_all) } fn request(&self) -> &str { From 9d15cac9698161bb5b67973374ad464858c42e81 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 19:33:23 +0800 Subject: [PATCH 11/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20trait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../harmony_export_expression_dependency.rs | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs index 7b3c38ce068..0aaca883556 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_export_expression_dependency.rs @@ -1,6 +1,6 @@ use rspack_core::{ - Dependency, DependencyId, DependencyTemplate, ModuleDependency, TemplateContext, - TemplateReplaceSource, + AsModuleDependency, Dependency, DependencyId, DependencyTemplate, ModuleDependency, + TemplateContext, TemplateReplaceSource, }; pub const DEFAULT_EXPORT: &str = "__WEBPACK_DEFAULT_EXPORT__"; @@ -40,28 +40,6 @@ impl HarmonyExportExpressionDependency { } } -impl ModuleDependency for HarmonyExportExpressionDependency { - fn dependency_debug_name(&self) -> &'static str { - "HarmonyExportExpressionDependency" - } - - fn request(&self) -> &str { - "" - } - - fn user_request(&self) -> &str { - todo!() - } - - fn span(&self) -> Option<&rspack_core::ErrorSpan> { - todo!() - } - - fn set_request(&mut self, request: String) { - todo!() - } -} - impl Dependency for HarmonyExportExpressionDependency { fn id(&self) -> &rspack_core::DependencyId { &self.id @@ -76,6 +54,16 @@ impl Dependency for HarmonyExportExpressionDependency { } } +impl AsModuleDependency for HarmonyExportExpressionDependency { + fn as_module_dependency(&self) -> Option<&dyn ModuleDependency> { + None + } + + fn as_module_dependency_mut(&mut self) -> Option<&mut dyn ModuleDependency> { + None + } +} + impl DependencyTemplate for HarmonyExportExpressionDependency { fn apply( &self, From 35091e5aaf3b3f69f72b0235173f145d3045111e Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 19:47:11 +0800 Subject: [PATCH 12/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20recover?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fixtures/simple-with-query/snapshot/output.snap | 1 - .../esm/harmony_import_specifier_dependency.rs | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap b/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap index 03249a42d9c..5df0503681c 100644 --- a/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap +++ b/crates/rspack/tests/fixtures/simple-with-query/snapshot/output.snap @@ -16,7 +16,6 @@ __webpack_require__.d(__webpack_exports__, { __webpack_require__.r(__webpack_exports__); /* harmony import */var _b_jsx__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.jsx */"./b.jsx"); /* harmony import */var _b_js_x__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js?x */"./b.js?x"); -/* harmony import */var _b_jsx__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.jsx */"./b.jsx"); _b_js_x__WEBPACK_IMPORTED_MODULE_1_.a; 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 51bda7bcc8d..6de70f59597 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 @@ -172,11 +172,13 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { .get_import_var(&code_generatable_context.module.identifier(), &self.request); // TODO: scope hoist - harmony_import_dependency_apply( - self, - code_generatable_context, - &vec![self.specifier.clone()], - ); + if compilation.options.is_new_tree_shaking() { + harmony_import_dependency_apply( + self, + code_generatable_context, + &vec![self.specifier.clone()], + ); + } let export_expr = export_from_import( code_generatable_context, true, From d8f1b5530109ad7d87d910c6c648137ccc4108cc Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 19:48:52 +0800 Subject: [PATCH 13/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20snap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/tree-shaking/bb/a.js | 12 +++---- crates/rspack/tests/tree-shaking/bb/c.js | 2 +- .../rspack/tests/tree-shaking/bb/package.json | 2 +- .../bb/snapshot/new_treeshaking.snap | 23 ++++++++++---- .../tests/tree-shaking/bb/snapshot/snap.diff | 31 +++++-------------- 5 files changed, 31 insertions(+), 39 deletions(-) diff --git a/crates/rspack/tests/tree-shaking/bb/a.js b/crates/rspack/tests/tree-shaking/bb/a.js index 475a4b2c64a..fee8526f563 100644 --- a/crates/rspack/tests/tree-shaking/bb/a.js +++ b/crates/rspack/tests/tree-shaking/bb/a.js @@ -1,8 +1,6 @@ -// import { d, c } from "./b.js"; +import { d, c } from "./b.js"; export * from "./c.js"; -export * from './b.js' -// export const a = 3; -// -// d; -// export { c }; -// +export const a = 3; + +d; +export { c }; diff --git a/crates/rspack/tests/tree-shaking/bb/c.js b/crates/rspack/tests/tree-shaking/bb/c.js index 21febfe8994..2f351adf71c 100644 --- a/crates/rspack/tests/tree-shaking/bb/c.js +++ b/crates/rspack/tests/tree-shaking/bb/c.js @@ -1 +1 @@ -export const ccc = 30; +export const ccc = 30; \ No newline at end of file diff --git a/crates/rspack/tests/tree-shaking/bb/package.json b/crates/rspack/tests/tree-shaking/bb/package.json index 2c63c085104..7a73a41bfdf 100644 --- a/crates/rspack/tests/tree-shaking/bb/package.json +++ b/crates/rspack/tests/tree-shaking/bb/package.json @@ -1,2 +1,2 @@ { -} +} \ No newline at end of file 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 3c60d9a4616..0fabafc2814 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -6,13 +6,24 @@ 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__); -// import { d, c } from "./b.js"; +__webpack_require__.d(__webpack_exports__, { + '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"); + - // export const a = 3; - // - // d; - // export { c }; - // + const a = 3; +_b_js__WEBPACK_IMPORTED_MODULE_0_.d; + +}, +"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +__webpack_require__.d(__webpack_exports__, { + 'd': function() { return d; } +}); + const d = 3; + const c = 100; }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index 82377467991..6d98c7daf08 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -1,32 +1,15 @@ --- expected +++ actual -@@ -6,23 +6,13 @@ +@@ -6,9 +6,10 @@ "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); --/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); ++__webpack_require__.d(__webpack_exports__, { ++ '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__); -- -+// import { d, c } from "./b.js"; -- const a = 3; --_b_js__WEBPACK_IMPORTED_MODULE_0_.d; -- --}, --"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); --__webpack_require__.d(__webpack_exports__, { -- 'd': function() { return d; } --}); -- const d = 3; -- const c = 100; -+ // export const a = 3; -+ // -+ // d; -+ // export { c }; -+ // - }, - "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; + + const a = 3; From deb65110981a84c3b97e86233aca6656d7b503bf Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 21:57:07 +0800 Subject: [PATCH 14/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20snapshot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/tree-shaking/bb/a.js | 8 ++--- .../bb/snapshot/new_treeshaking.snap | 24 ++++--------- .../tests/tree-shaking/bb/snapshot/snap.diff | 33 ++++++++++++----- .../snapshot/new_treeshaking.snap | 1 + .../cjs-tree-shaking-basic/snapshot/snap.diff | 10 ------ .../snapshot/new_treeshaking.snap | 1 + .../snapshot/snap.diff | 7 ++-- .../snapshot/new_treeshaking.snap | 1 + .../export-named-decl-as/snapshot/snap.diff | 10 +----- .../snapshot/new_treeshaking.snap | 2 ++ .../snapshot/snap.diff | 6 +++- .../snapshot/new_treeshaking.snap | 1 + .../snapshot/snap.diff | 10 +----- .../snapshot/new_treeshaking.snap | 2 ++ .../snapshot/snap.diff | 8 ++--- .../snapshot/new_treeshaking.snap | 2 ++ .../snapshot/snap.diff | 11 +++++- .../snapshot/new_treeshaking.snap | 1 + .../snapshot/snap.diff | 5 ++- .../snapshot/new_treeshaking.snap | 1 + .../nested-import-4/snapshot/snap.diff | 8 ----- .../snapshot/new_treeshaking.snap | 2 ++ .../prune-bailout-module/snapshot/snap.diff | 5 +-- .../snapshot/new_treeshaking.snap | 2 ++ .../snapshot/snap.diff | 5 +-- .../snapshot/new_treeshaking.snap | 2 ++ .../side-effects-analyzed/snapshot/snap.diff | 7 ++-- .../snapshot/new_treeshaking.snap | 2 ++ .../side-effects-prune/snapshot/snap.diff | 11 ------ .../snapshot/new_treeshaking.snap | 2 ++ .../side-effects-two/snapshot/snap.diff | 7 ++-- .../snapshot/new_treeshaking.snap | 1 + .../ts-target-es5/snapshot/snap.diff | 8 ++--- .../snapshot/new_treeshaking.snap | 4 +++ .../snapshot/snap.diff | 18 ++-------- .../snapshot/new_treeshaking.snap | 2 ++ .../snapshot/snap.diff | 22 +++--------- ...ny_export_imported_specifier_dependency.rs | 35 +++++++++++++++++-- .../esm/harmony_import_dependency.rs | 5 ++- .../harmony_import_specifier_dependency.rs | 4 ++- .../harmony_export_dependency_scanner.rs | 1 + .../harmony_import_dependency_scanner.rs | 3 ++ 42 files changed, 160 insertions(+), 140 deletions(-) delete mode 100644 crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/snap.diff delete mode 100644 crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/snap.diff diff --git a/crates/rspack/tests/tree-shaking/bb/a.js b/crates/rspack/tests/tree-shaking/bb/a.js index fee8526f563..69fdc651d9e 100644 --- a/crates/rspack/tests/tree-shaking/bb/a.js +++ b/crates/rspack/tests/tree-shaking/bb/a.js @@ -1,6 +1,6 @@ -import { d, c } from "./b.js"; +// import { d, c } from "./b.js"; export * from "./c.js"; -export const a = 3; +// export const a = 3; -d; -export { c }; +// d; +// export { c }; 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 0fabafc2814..adb53cf60da 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -6,24 +6,12 @@ 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 _b_js__WEBPACK_IMPORTED_MODULE_0_.c; } -}); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); - - - const a = 3; -_b_js__WEBPACK_IMPORTED_MODULE_0_.d; - -}, -"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { -'use strict'; -__webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'd': function() { return d; } -}); - const d = 3; - const c = 100; +/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); +__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +// import { d, c } from "./b.js"; + // export const a = 3; + // d; + // export { c }; }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index 6d98c7daf08..941698f8a85 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -1,15 +1,32 @@ --- expected +++ actual -@@ -6,9 +6,10 @@ +@@ -6,23 +6,12 @@ "./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 _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 _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./c.js */"./c.js"); -__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); - - - const a = 3; +- +- +- const a = 3; +-_b_js__WEBPACK_IMPORTED_MODULE_0_.d; +- +-}, +-"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +-'use strict'; +-__webpack_require__.r(__webpack_exports__); +-__webpack_require__.d(__webpack_exports__, { +- 'd': function() { return d; } +-}); +- const d = 3; +- const c = 100; ++/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); ++__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); ++// import { d, c } from "./b.js"; ++ // export const a = 3; ++ // d; ++ // export { c }; + }, + "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { + 'use strict'; 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 efb999f5d65..12f11d33c3e 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 @@ -18,6 +18,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'myanswer': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_.myanswer; } }); +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); }, "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 deleted file mode 100644 index 5d68e0d65d5..00000000000 --- a/crates/rspack/tests/tree-shaking/cjs-tree-shaking-basic/snapshot/snap.diff +++ /dev/null @@ -1,10 +0,0 @@ ---- expected -+++ actual -@@ -18,7 +18,6 @@ - __webpack_require__.d(__webpack_exports__, { - 'myanswer': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_.myanswer; } - }); --/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); - - }, - "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 d45024e504b..1c7809ea70f 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 @@ -30,6 +30,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'containers': function() { return _containers__WEBPACK_IMPORTED_MODULE_0_; } }); +/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); }, diff --git a/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/cyclic-reference-export-all/snapshot/snap.diff index 0cc2f177151..c51c472cb18 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,11 +9,8 @@ }, -@@ -32,19 +30,8 @@ - __webpack_require__.d(__webpack_exports__, { - 'containers': function() { return _containers__WEBPACK_IMPORTED_MODULE_0_; } - }); --/* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); +@@ -35,16 +33,6 @@ + /* harmony import */var _containers__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./containers */"./src/containers/containers.js"); -}, 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 ffb27acc28b..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 @@ -9,6 +9,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'formatNumber': function() { return _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0_["default"]; } }); +/* harmony import */var _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./plugin/formatNumber */"./src/plugin/formatNumber.js"); }, 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 955409d013f..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 @@ -1,14 +1,6 @@ --- expected +++ actual -@@ -9,7 +9,6 @@ - __webpack_require__.d(__webpack_exports__, { - 'formatNumber': function() { return _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0_["default"]; } - }); --/* harmony import */var _plugin_formatNumber__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./plugin/formatNumber */"./src/plugin/formatNumber.js"); - - - }, -@@ -23,9 +22,6 @@ +@@ -23,9 +23,6 @@ "./src/plugin/formatNumber.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); diff --git a/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap index 32c7971cce6..7b5f2134a03 100644 --- a/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/import-export-all-as-a-empty-module/snapshot/new_treeshaking.snap @@ -10,6 +10,8 @@ __webpack_require__.d(__webpack_exports__, { 'aaa': function() { return _app__WEBPACK_IMPORTED_MODULE_1_; }, 'routes': function() { return routes; } }); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./app */"./app.js"); +/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_1_); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_0_); 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 index 98a97ebbd5f..4349dd3f8a0 100644 --- 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 @@ -1,7 +1,11 @@ --- expected +++ actual -@@ -12,8 +12,6 @@ +@@ -10,10 +10,10 @@ + 'aaa': function() { return _app__WEBPACK_IMPORTED_MODULE_1_; }, + 'routes': function() { return routes; } }); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./app */"./app.js"); ++/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1__default = /*#__PURE__*/__webpack_require__.n(_app__WEBPACK_IMPORTED_MODULE_1_); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); /* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0__default = /*#__PURE__*/__webpack_require__.n(_answer__WEBPACK_IMPORTED_MODULE_0_); -/* harmony import */var _app__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./app */"./app.js"); 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 e494bfd1703..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 @@ -9,6 +9,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'app': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_; } }); +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); }, 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 c5c3ba6d256..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 @@ -1,14 +1,6 @@ --- expected +++ actual -@@ -9,7 +9,6 @@ - __webpack_require__.d(__webpack_exports__, { - 'app': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_; } - }); --/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); - - - }, -@@ -23,9 +22,6 @@ +@@ -23,9 +23,6 @@ "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); 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 237247ec4cb..97e31c6bdc2 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 @@ -21,6 +21,8 @@ __webpack_require__.d(__webpack_exports__, { 'Layout': function() { return _layout_export__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'Sider': function() { return _Something__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); +/* harmony import */var _layout_export__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./layout_export */"./layout_export.js"); +/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); diff --git a/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/import-var-assign-side-effects/snapshot/snap.diff index f717e54edca..131b600fff4 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 @@ -18,18 +18,18 @@ class Something { } }, -@@ -16,9 +18,9 @@ +@@ -16,8 +18,10 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { + 'Layout': function() { return _layout_export__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'Sider': function() { return _Something__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); --/* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); ++/* harmony import */var _layout_export__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./layout_export */"./layout_export.js"); + /* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); - -@@ -30,6 +32,17 @@ +@@ -30,6 +34,17 @@ (0, _export__WEBPACK_IMPORTED_MODULE_0_.Sider)(); }, 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 f6b34955491..c057f772376 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 @@ -26,6 +26,8 @@ __webpack_require__.d(__webpack_exports__, { /* 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"); +__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); +/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __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 8ddaf3b9fb0..8b862e0c4c5 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 @@ -18,7 +18,16 @@ const a = 'bar'; const c = 'bar'; }, -@@ -34,9 +34,6 @@ +@@ -27,6 +27,8 @@ + __webpack_require__.es(_foo__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); + /* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); + __webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); ++/* harmony import */var _bar__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./bar */"./bar.js"); ++__webpack_require__.es(_bar__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); + + + const a = 3; +@@ -34,9 +36,6 @@ "./foo.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); 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 844458392d6..39af57dac5b 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 @@ -33,6 +33,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'cccc': function() { return _c__WEBPACK_IMPORTED_MODULE_2_.cccc; } }); +/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./c.js"); /* 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 a54b8ca9112..2cee3bc15f1 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,7 +1,10 @@ --- expected +++ actual -@@ -35,7 +35,6 @@ +@@ -33,9 +33,9 @@ + __webpack_require__.d(__webpack_exports__, { + 'cccc': function() { return _c__WEBPACK_IMPORTED_MODULE_2_.cccc; } }); ++/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./c.js"); /* harmony import */var _Layout__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./Layout */"./Layout.js"); /* harmony import */var _Something__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./Something */"./Something.js"); -/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./c */"./c.js"); 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 3716ca284cc..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 @@ -22,6 +22,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'Lib': function() { return _answer__WEBPACK_IMPORTED_MODULE_0_; } }); +/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); }, 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 3ae8796b831..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 @@ -10,11 +10,3 @@ const a = 103330; const b = 103330; }, -@@ -25,7 +22,6 @@ - __webpack_require__.d(__webpack_exports__, { - 'Lib': function() { return _answer__WEBPACK_IMPORTED_MODULE_0_; } - }); --/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js"); - - - }, 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 626b094e329..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 @@ -34,6 +34,8 @@ __webpack_require__.d(__webpack_exports__, { 'a': function() { return _a_js__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); +/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); +/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); }, 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 d49f47d997d..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 @@ -24,7 +24,7 @@ "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -@@ -22,9 +31,9 @@ +@@ -22,9 +31,11 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -32,7 +32,8 @@ + 'a': function() { return _a_js__WEBPACK_IMPORTED_MODULE_0_["default"]; }, + 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); --/* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); + /* harmony import */var _a_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a.js */"./a.js"); ++/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js"); }, 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 c88588a7601..6fc712822cc 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 @@ -10,6 +10,8 @@ __webpack_require__.d(__webpack_exports__, { 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'c': function() { return _c_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); +/* 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"); }, 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 040101b85af..95848703fd8 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,18 +7,15 @@ +@@ -7,18 +7,17 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -8,7 +8,8 @@ + 'b': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_["default"]; }, + 'c': function() { return _c_js__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); --/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); + /* 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"); }, 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 079cc01ccb8..f3b5f1f1447 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 @@ -10,6 +10,8 @@ __webpack_require__.d(__webpack_exports__, { 'something': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'b': function() { return _src_a__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); +/* 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"); }, 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 cc05fad08af..7c415aca8ca 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 @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -7,9 +7,9 @@ +@@ -7,9 +7,11 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -8,11 +8,12 @@ + 'something': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, + 'b': function() { return _src_a__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); --/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); + /* 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"); }, -@@ -24,13 +24,20 @@ +@@ -24,13 +26,20 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 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 326f7516249..1faa6134b14 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,6 +6,8 @@ source: crates/rspack_testing/src/run_fixture.rs "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); +/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); +__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); // export { // result as test 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 deleted file mode 100644 index 9e28a634eb4..00000000000 --- a/crates/rspack/tests/tree-shaking/side-effects-prune/snapshot/snap.diff +++ /dev/null @@ -1,11 +0,0 @@ ---- expected -+++ actual -@@ -6,8 +6,6 @@ - "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); --/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); --__webpack_require__.es(_lib__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); - - // export { - // result as test 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 dfa9ee450d0..8c1ff80c839 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 @@ -10,6 +10,8 @@ __webpack_require__.d(__webpack_exports__, { 'something': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, 'b': function() { return _src_a__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); +/* 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"); // export { // result as test 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 07bf9b9f182..1dffbccc59c 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 @@ -1,6 +1,6 @@ --- expected +++ actual -@@ -7,9 +7,9 @@ +@@ -7,9 +7,11 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -8,11 +8,12 @@ + 'something': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_["default"]; }, + 'b': function() { return _src_a__WEBPACK_IMPORTED_MODULE_1_["default"]; } }); --/* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); + /* 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"); // export { // result as test -@@ -26,13 +26,20 @@ +@@ -26,13 +28,20 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 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 8fcf34ce184..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 @@ -44,6 +44,7 @@ __webpack_require__.d(__webpack_exports__, { '_': function() { return tslib__WEBPACK_IMPORTED_MODULE_0_.__generator; }, '_ts_generator': function() { return tslib__WEBPACK_IMPORTED_MODULE_0_.__generator; } }); +/* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); }, "../../../../../node_modules/tslib/tslib.es6.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 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 28d65fabc07..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,6 +1,6 @@ --- expected +++ actual -@@ -41,17 +41,14 @@ +@@ -41,7 +41,8 @@ 'use strict'; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { @@ -8,9 +8,9 @@ + '_': function() { return tslib__WEBPACK_IMPORTED_MODULE_0_.__generator; }, + '_ts_generator': function() { return tslib__WEBPACK_IMPORTED_MODULE_0_.__generator; } }); --/* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); + /* harmony import */var tslib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* tslib */"../../../../../node_modules/tslib/tslib.es6.js"); - }, +@@ -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__); @@ -20,7 +20,7 @@ /****************************************************************************** Copyright (c) Microsoft Corporation. -@@ -482,9 +479,6 @@ +@@ -482,9 +480,6 @@ "./index.ts": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); 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 576f1fd8715..d2f8a0e0300 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 @@ -24,6 +24,7 @@ __webpack_require__.d(__webpack_exports__, { 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, 'x': function() { return x; } }); +/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var x = "x"; var y = "y"; @@ -53,6 +54,9 @@ __webpack_require__.d(__webpack_exports__, { 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); +/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"../node_modules/pmodule/a.js"); +__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); +/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); 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 b5532af7410..3be0ae50528 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,14 +1,6 @@ --- expected +++ actual -@@ -24,7 +24,6 @@ - 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, - 'x': function() { return x; } - }); --/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); - /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); - var x = "x"; - var y = "y"; -@@ -50,12 +49,10 @@ +@@ -50,6 +50,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'x': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.x; }, @@ -16,13 +8,7 @@ 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); --/* harmony import */var _a__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./a */"../node_modules/pmodule/a.js"); --__webpack_require__.es(_a__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); --/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); - /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); - - -@@ -82,8 +79,8 @@ +@@ -82,8 +83,8 @@ "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); 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 b12335dbfa0..9087e70cd9a 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 @@ -10,6 +10,7 @@ __webpack_require__.d(__webpack_exports__, { 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, 'x': function() { return x; } }); +/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); var x = "x"; var y = "y"; @@ -39,6 +40,7 @@ __webpack_require__.d(__webpack_exports__, { 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); +/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); 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 5c38c283cfa..37e7ca1e2c2 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,14 +1,6 @@ --- expected +++ actual -@@ -10,7 +10,6 @@ - 'z': function() { return _c__WEBPACK_IMPORTED_MODULE_0_.z; }, - 'x': function() { return x; } - }); --/* harmony import */var _c__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c */"../node_modules/pmodule/c.js"); - /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); - var x = "x"; - var y = "y"; -@@ -36,10 +35,10 @@ +@@ -36,6 +36,7 @@ __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { 'x': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.x; }, @@ -16,17 +8,13 @@ 'z': function() { return _b__WEBPACK_IMPORTED_MODULE_1_.z; }, 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; } }); --/* harmony import */var _b__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b */"../node_modules/pmodule/b.js"); - /* harmony import */var _tracker__WEBPACK_IMPORTED_MODULE_2_ = __webpack_require__(/* ./tracker */"../node_modules/pmodule/tracker.js"); - - -@@ -66,8 +65,8 @@ +@@ -66,8 +67,8 @@ "./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -+/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); - /* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); --/* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); +-/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); + /* harmony import */var pmodule__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* pmodule */"../node_modules/pmodule/index.js"); ++/* harmony import */var pmodule_tracker__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* pmodule/tracker */"../node_modules/pmodule/tracker.js"); 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 8e796587789..923b2f2c9c1 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 @@ -9,7 +9,7 @@ use rspack_core::{ use rustc_hash::FxHashSet as HashSet; use swc_core::ecma::atoms::JsWord; -use super::create_resource_identifier_for_esm_dependency; +use super::{create_resource_identifier_for_esm_dependency, harmony_import_dependency_apply}; // Create _webpack_require__.d(__webpack_exports__, {}). // case1: `import { a } from 'a'; export { a }` @@ -26,10 +26,16 @@ pub struct HarmonyExportImportedSpecifierDependency { // pub active_exports: HashSet, // pub all_star_exports: Option>, pub other_star_exports: Option>, // look like it is unused + pub export_all: bool, } impl HarmonyExportImportedSpecifierDependency { - pub fn new(request: JsWord, ids: Vec<(JsWord, Option)>, name: Option) -> Self { + pub fn new( + request: JsWord, + ids: Vec<(JsWord, Option)>, + name: Option, + export_all: bool, + ) -> Self { let resource_identifier = create_resource_identifier_for_esm_dependency(&request); Self { id: DependencyId::new(), @@ -38,6 +44,7 @@ impl HarmonyExportImportedSpecifierDependency { ids, resource_identifier, other_star_exports: None, + export_all, } } @@ -378,6 +385,7 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { let import_var = compilation .module_graph .get_import_var(&module.identifier(), &self.request); + let is_new_tree_shaking = compilation.options.is_new_tree_shaking(); let used_exports = if compilation.options.builtins.tree_shaking.is_true() { Some( @@ -390,6 +398,21 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { None }; + dbg!(&is_new_tree_shaking); + if is_new_tree_shaking { + // TODO: runtime opt + let mode = self.get_mode( + self.name.clone(), + &self.ids.iter().map(|id| id.0.clone()).collect::>(), + &compilation.module_graph, + &self.id, + None, + ); + if !matches!(mode.ty, ExportModeType::Unused | ExportModeType::EmptyStar) { + harmony_import_dependency_apply(self, code_generatable_context, &vec![]); + } + } + let mut exports = vec![]; for id in &self.ids { if used_exports.is_none() || matches!(used_exports.as_ref(), Some(x) if x.contains(&id.0)) { @@ -459,6 +482,14 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { Some(&self.resource_identifier) } + fn is_export_all(&self) -> Option { + if self.export_all { + Some(true) + } else { + None + } + } + fn get_condition(&self) -> Option { let id = self.id; Some(DependencyCondition::Fn(Box::new( 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 2fdd0bb24d7..0de12ac7975 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 @@ -71,7 +71,10 @@ pub fn harmony_import_dependency_apply( .connection_by_dependency(module_dependency.id()); if let Some(con) = connection { // TODO: runtime opt - con.is_target_active(&compilation.module_graph, None) + let ret = con.is_target_active(&compilation.module_graph, None); + + dbg!(&con, &ret); + ret } else { true } 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 6de70f59597..ff209ace524 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 @@ -141,7 +141,9 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { let connection = compilation.module_graph.connection_by_dependency(&self.id); if let Some(con) = connection { // TODO: runtime opt - con.is_target_active(&compilation.module_graph, None) + let ret = con.is_target_active(&compilation.module_graph, None); + + ret } else { true } diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs index 4582bde8024..7f3a5371ece 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs @@ -106,6 +106,7 @@ impl Visit for HarmonyExportDependencyScanner<'_> { reference.request.clone(), vec![(export.clone(), reference.names.clone())], Some(export), + false, ))); } else { self 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 2cfb189fe6f..07e4ea58181 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 @@ -106,6 +106,7 @@ impl Visit for HarmonyImportDependencyScanner<'_> { request.clone(), vec![(n.clone(), None)], Some(n.clone()), + false, ))); self.build_info.harmony_named_exports.insert(n.clone()); } @@ -120,6 +121,7 @@ impl Visit for HarmonyImportDependencyScanner<'_> { request.clone(), vec![(name.clone(), Some(orig.clone()))], Some(name.clone()), + false, ))); self.build_info.harmony_named_exports.insert(name); } @@ -140,6 +142,7 @@ impl Visit for HarmonyImportDependencyScanner<'_> { request.clone(), vec![], None, + true, ))); } self.dependencies.push(Box::new(dependency)); From 1a253fd5edd04b93029b430b879a4c56ebfd84c4 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 22:00:32 +0800 Subject: [PATCH 15/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bb --- crates/rspack/tests/tree-shaking/bb/a.js | 8 ++--- .../bb/snapshot/new_treeshaking.snap | 26 ++++++++++---- .../tests/tree-shaking/bb/snapshot/snap.diff | 36 ++++++------------- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/crates/rspack/tests/tree-shaking/bb/a.js b/crates/rspack/tests/tree-shaking/bb/a.js index 69fdc651d9e..fee8526f563 100644 --- a/crates/rspack/tests/tree-shaking/bb/a.js +++ b/crates/rspack/tests/tree-shaking/bb/a.js @@ -1,6 +1,6 @@ -// import { d, c } from "./b.js"; +import { d, c } from "./b.js"; export * from "./c.js"; -// export const a = 3; +export const a = 3; -// d; -// export { c }; +d; +export { c }; 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 adb53cf60da..1a73b1bc292 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap @@ -6,12 +6,26 @@ 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__); -/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); -__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -// import { d, c } from "./b.js"; - // export const a = 3; - // d; - // export { c }; +__webpack_require__.d(__webpack_exports__, { + 'c': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.c; } +}); +/* 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__); +/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); + + + const a = 3; +_b_js__WEBPACK_IMPORTED_MODULE_0_.d; + +}, +"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +'use strict'; +__webpack_require__.r(__webpack_exports__); +__webpack_require__.d(__webpack_exports__, { + 'd': function() { return d; } +}); + const d = 3; + const c = 100; }, "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; diff --git a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff index 941698f8a85..724c55f1d9f 100644 --- a/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff +++ b/crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff @@ -1,32 +1,16 @@ --- expected +++ actual -@@ -6,23 +6,12 @@ +@@ -6,9 +6,12 @@ "./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); --/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./c.js */"./c.js"); --__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__); -- -- -- const a = 3; --_b_js__WEBPACK_IMPORTED_MODULE_0_.d; -- --}, --"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { --'use strict'; --__webpack_require__.r(__webpack_exports__); --__webpack_require__.d(__webpack_exports__, { -- 'd': function() { return d; } --}); -- const d = 3; -- const c = 100; -+/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js"); -+__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__); -+// import { d, c } from "./b.js"; -+ // export const a = 3; -+ // d; -+ // export { c }; - }, - "./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; ++__webpack_require__.d(__webpack_exports__, { ++ 'c': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.c; } ++}); + /* 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__); ++/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js"); + + + const a = 3; From 31e2f5b69c1f458fafbb37b7f055410498f71c45 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Wed, 20 Sep 2023 11:06:57 +0800 Subject: [PATCH 16/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20ck=20point?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tree-shaking/import-star-as-and-export/app.js | 4 ++-- .../tree-shaking/import-star-as-and-export/index.js | 2 +- .../snapshot/new_treeshaking.snap | 6 +++--- .../import-star-as-and-export/snapshot/snap.diff | 10 +++++----- crates/rspack_core/src/compiler/compilation.rs | 6 +++--- .../harmony_export_imported_specifier_dependency.rs | 1 + .../src/dependency/esm/harmony_import_dependency.rs | 11 +++++++++-- .../esm/harmony_import_specifier_dependency.rs | 1 + .../src/plugin/flag_dependency_usage_plugin.rs | 11 ++++++++++- .../dependency/harmony_export_dependency_scanner.rs | 13 +++++++++++-- .../dependency/harmony_import_dependency_scanner.rs | 1 + 11 files changed, 47 insertions(+), 19 deletions(-) diff --git a/crates/rspack/tests/tree-shaking/import-star-as-and-export/app.js b/crates/rspack/tests/tree-shaking/import-star-as-and-export/app.js index 83585aba4d6..f3acedbc3ba 100644 --- a/crates/rspack/tests/tree-shaking/import-star-as-and-export/app.js +++ b/crates/rspack/tests/tree-shaking/import-star-as-and-export/app.js @@ -1,3 +1,3 @@ -import * as _app from './lib'; +import * as app from './lib'; -export { _app as app } \ No newline at end of file +export {app} diff --git a/crates/rspack/tests/tree-shaking/import-star-as-and-export/index.js b/crates/rspack/tests/tree-shaking/import-star-as-and-export/index.js index 4a57343d40e..f0b64f88a2f 100644 --- a/crates/rspack/tests/tree-shaking/import-star-as-and-export/index.js +++ b/crates/rspack/tests/tree-shaking/import-star-as-and-export/index.js @@ -1,4 +1,4 @@ import { app } from './app' -app \ No newline at end of file +app 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 d456ee9b668..09e992ee9ad 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 @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); -__webpack_require__.d(__webpack_exports__, { - 'app': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_; } -}); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); @@ -23,6 +20,9 @@ _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 778e4801e50..732e998adb6 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 @@ -1,12 +1,12 @@ --- expected +++ actual -@@ -23,9 +23,6 @@ - "./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -6,9 +6,6 @@ + "./app.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; } +- 'app': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_; } -}); - const a = 20000; - }, + /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); + diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index b55f9cf7eb7..ed1fb4c66bd 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -32,7 +32,7 @@ use super::{ use crate::{ build_chunk_graph::build_chunk_graph, cache::{use_code_splitting_cache, Cache, CodeSplittingCache}, - is_source_equal, + debug_exports_info, is_source_equal, tree_shaking::{optimizer, visitor::SymbolRef, BailoutFlag, OptimizeDependencyResult}, AddQueue, AddTask, AddTaskResult, AdditionalChunkRuntimeRequirementsArgs, BoxDependency, BoxModule, BuildQueue, BuildTask, BuildTaskResult, CacheCount, CacheOptions, Chunk, ChunkByUkey, @@ -1159,13 +1159,13 @@ impl Compilation { logger.time_end(start); if self.options.is_new_tree_shaking() { - for module in self.module_graph.module_graph_modules().values() {} + // for module in self.module_graph.module_graph_modules().values() {} // self // .module_graph // .module_graph_modules() // .values() // .foreach(|item| {}); - // debug_exports_info(&self.module_graph); + debug_exports_info(&self.module_graph); } let start = logger.time("create chunks"); 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 923b2f2c9c1..dfd975932d7 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 @@ -531,6 +531,7 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { &self.id, runtime, ); + dbg!(&mode, &self.ids); match mode.ty { ExportModeType::Missing | ExportModeType::Unused 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 0de12ac7975..117f9a2a443 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 @@ -72,8 +72,15 @@ pub fn harmony_import_dependency_apply( if let Some(con) = connection { // TODO: runtime opt let ret = con.is_target_active(&compilation.module_graph, None); - - dbg!(&con, &ret); + // dbg!( + // &con, + // &ret, + // &compilation + // .module_graph + // .dependency_by_id(&con.dependency_id) + // .and_then(|item| item.as_module_dependency()) + // .map(|item| item.dependency_debug_name()) + // ); ret } else { true 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 ff209ace524..98bcb721882 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 @@ -251,6 +251,7 @@ impl ModuleDependency for HarmonyImportSpecifierDependency { _runtime: Option<&RuntimeSpec>, ) -> Vec { // namespace import + dbg!(&self.ids); if self.ids.is_empty() { return self.get_referenced_exports_in_destructuring(None); } 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 bf5b8d14fe2..deafaadda1c 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 @@ -115,11 +115,20 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { .module_graph .dependency_by_id(&dep_id) .expect("should have dep"); + let referenced_exports = if let Some(md) = dep.as_module_dependency() { md.get_referenced_exports(&self.compilation.module_graph, runtime.as_ref()) } else { continue; }; + dbg!( + &connection, + dep + .as_module_dependency() + .map(|item| item.dependency_debug_name()), + &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)) @@ -194,6 +203,7 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { } for (module_id, referenced_exports) in map { + dbg!(&module_id, &referenced_exports); let normalized_refs = match referenced_exports { ProcessModuleReferencedExports::Map(map) => map.into_values().collect::>(), ProcessModuleReferencedExports::ExtendRef(extend_ref) => extend_ref, @@ -311,7 +321,6 @@ 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 { diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs index 7f3a5371ece..2246e892525 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs @@ -17,7 +17,8 @@ use swc_core::{ use super::harmony_import_dependency_scanner::ImportMap; use crate::dependency::{ AnonymousFunctionRangeInfo, HarmonyExportExpressionDependency, HarmonyExportHeaderDependency, - HarmonyExportImportedSpecifierDependency, HarmonyExportSpecifierDependency, DEFAULT_EXPORT, + HarmonyExportImportedSpecifierDependency, HarmonyExportSpecifierDependency, Specifier, + DEFAULT_EXPORT, }; pub struct HarmonyExportDependencyScanner<'a> { @@ -100,11 +101,19 @@ impl Visit for HarmonyExportDependencyScanner<'_> { _ => unreachable!(), }; if let Some(reference) = self.import_map.get(&orig.to_id()) { + let ids = match reference.specifier { + Specifier::Namespace(_) => { + vec![] + } + _ => { + vec![(export.clone(), reference.names.clone())] + } + }; self .dependencies .push(Box::new(HarmonyExportImportedSpecifierDependency::new( reference.request.clone(), - vec![(export.clone(), reference.names.clone())], + ids, Some(export), false, ))); 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 07e4ea58181..cb11d065f25 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 @@ -41,6 +41,7 @@ impl ImporterReferenceInfo { pub type ImportMap = HashMap; +#[derive(Debug)] pub struct ImporterInfo { pub span: Span, pub specifiers: Vec, From 7bc6a869fcb5a7bf10d6d5d1f83ac76579359282 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Wed, 20 Sep 2023 12:25:46 +0800 Subject: [PATCH 17/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20snapshot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../snapshot/new_treeshaking.snap | 3 +++ .../snapshot/snap.diff | 12 ------------ .../snapshot/new_treeshaking.snap | 4 ++++ .../nested-import-4/snapshot/snap.diff | 10 +++++----- ...ony_export_imported_specifier_dependency.rs | 18 +++++++++++++++--- .../harmony_export_dependency_scanner.rs | 8 ++++---- .../harmony_import_dependency_scanner.rs | 9 +++++++-- 7 files changed, 38 insertions(+), 26 deletions(-) delete mode 100644 crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/snap.diff 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 09e992ee9ad..f6e653b7e11 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 @@ -6,6 +6,9 @@ source: crates/rspack_testing/src/run_fixture.rs "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { 'use strict'; __webpack_require__.r(__webpack_exports__); +__webpack_require__.d(__webpack_exports__, { + 'app': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_; } +}); /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); 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 deleted file mode 100644 index 732e998adb6..00000000000 --- a/crates/rspack/tests/tree-shaking/import-star-as-and-export/snapshot/snap.diff +++ /dev/null @@ -1,12 +0,0 @@ ---- expected -+++ actual -@@ -6,9 +6,6 @@ - "./app.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { - 'use strict'; - __webpack_require__.r(__webpack_exports__); --__webpack_require__.d(__webpack_exports__, { -- 'app': function() { return _lib__WEBPACK_IMPORTED_MODULE_0_; } --}); - /* harmony import */var _lib__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib */"./lib.js"); - - 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 e7be25eed34..0f88efb840a 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,6 +6,10 @@ 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 f2cd8fe2f01..091fa6afd83 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 -@@ -6,9 +6,6 @@ - "./answer.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) { +@@ -7,7 +7,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; }, ++ 'b': function() { return b; } + }); const a = 103330; const b = 103330; - }, 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 dfd975932d7..a8fd459defd 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 @@ -20,6 +20,8 @@ pub struct HarmonyExportImportedSpecifierDependency { pub id: DependencyId, pub request: JsWord, pub ids: Vec<(JsWord, Option)>, + /// used for get_mode + pub mode_ids: Vec<(JsWord, Option)>, name: Option, resource_identifier: String, // Because it is shared by multiply HarmonyExportImportedSpecifierDependency, so put it to `BuildInfo` @@ -33,12 +35,14 @@ impl HarmonyExportImportedSpecifierDependency { pub fn new( request: JsWord, ids: Vec<(JsWord, Option)>, + mode_ids: Vec<(JsWord, Option)>, name: Option, export_all: bool, ) -> Self { let resource_identifier = create_resource_identifier_for_esm_dependency(&request); Self { id: DependencyId::new(), + mode_ids, name, request, ids, @@ -403,7 +407,11 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { // TODO: runtime opt let mode = self.get_mode( self.name.clone(), - &self.ids.iter().map(|id| id.0.clone()).collect::>(), + &self + .mode_ids + .iter() + .map(|id| id.0.clone()) + .collect::>(), &compilation.module_graph, &self.id, None, @@ -503,7 +511,7 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { let mode = down_casted_dep.get_mode( down_casted_dep.name.clone(), &down_casted_dep - .ids + .mode_ids .iter() .map(|id| id.0.clone()) .collect::>(), @@ -526,7 +534,11 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { ) -> Vec { let mode = self.get_mode( self.name.clone(), - &self.ids.iter().map(|id| id.0.clone()).collect::>(), + &self + .mode_ids + .iter() + .map(|id| id.0.clone()) + .collect::>(), module_graph, &self.id, runtime, diff --git a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs index 2246e892525..b0c58dee323 100644 --- a/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs +++ b/crates/rspack_plugin_javascript/src/visitors/dependency/harmony_export_dependency_scanner.rs @@ -101,19 +101,19 @@ impl Visit for HarmonyExportDependencyScanner<'_> { _ => unreachable!(), }; if let Some(reference) = self.import_map.get(&orig.to_id()) { - let ids = match reference.specifier { + let ids = vec![(export.clone(), reference.names.clone())]; + let mode_ids = match reference.specifier { Specifier::Namespace(_) => { vec![] } - _ => { - vec![(export.clone(), reference.names.clone())] - } + _ => ids.clone(), }; self .dependencies .push(Box::new(HarmonyExportImportedSpecifierDependency::new( reference.request.clone(), ids, + mode_ids, Some(export), false, ))); 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 cb11d065f25..d9a4efaa78b 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 @@ -101,11 +101,13 @@ impl Visit for HarmonyImportDependencyScanner<'_> { .iter() .for_each(|specifier| match specifier { Specifier::Namespace(n) => { + let ids = vec![(n.clone(), None)]; self .dependencies .push(Box::new(HarmonyExportImportedSpecifierDependency::new( request.clone(), - vec![(n.clone(), None)], + ids.clone(), + ids, Some(n.clone()), false, ))); @@ -116,11 +118,13 @@ impl Visit for HarmonyImportDependencyScanner<'_> { } Specifier::Named(orig, exported) => { let name = exported.clone().unwrap_or(orig.clone()); + let ids = vec![(name.clone(), Some(orig.clone()))]; self .dependencies .push(Box::new(HarmonyExportImportedSpecifierDependency::new( request.clone(), - vec![(name.clone(), Some(orig.clone()))], + ids.clone(), + ids, Some(name.clone()), false, ))); @@ -142,6 +146,7 @@ impl Visit for HarmonyImportDependencyScanner<'_> { .push(Box::new(HarmonyExportImportedSpecifierDependency::new( request.clone(), vec![], + vec![], None, true, ))); From 36bfdcf0604a4adbff7a34942d730f8118305c36 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Wed, 20 Sep 2023 12:43:43 +0800 Subject: [PATCH 18/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20snap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/tree-shaking/import-star-as-and-export/app.js | 4 ++-- .../tests/tree-shaking/import-star-as-and-export/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/rspack/tests/tree-shaking/import-star-as-and-export/app.js b/crates/rspack/tests/tree-shaking/import-star-as-and-export/app.js index f3acedbc3ba..83585aba4d6 100644 --- a/crates/rspack/tests/tree-shaking/import-star-as-and-export/app.js +++ b/crates/rspack/tests/tree-shaking/import-star-as-and-export/app.js @@ -1,3 +1,3 @@ -import * as app from './lib'; +import * as _app from './lib'; -export {app} +export { _app as app } \ No newline at end of file diff --git a/crates/rspack/tests/tree-shaking/import-star-as-and-export/index.js b/crates/rspack/tests/tree-shaking/import-star-as-and-export/index.js index f0b64f88a2f..4a57343d40e 100644 --- a/crates/rspack/tests/tree-shaking/import-star-as-and-export/index.js +++ b/crates/rspack/tests/tree-shaking/import-star-as-and-export/index.js @@ -1,4 +1,4 @@ import { app } from './app' -app +app \ No newline at end of file From 461ca1c09cdc6e1d1136e6fedb85632f416a2b6f Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Wed, 20 Sep 2023 23:07:06 +0800 Subject: [PATCH 19/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20check.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/check.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 crates/rspack/tests/check.js diff --git a/crates/rspack/tests/check.js b/crates/rspack/tests/check.js new file mode 100644 index 00000000000..e6962c13f0f --- /dev/null +++ b/crates/rspack/tests/check.js @@ -0,0 +1,29 @@ +const path = require("path"); +const fs = require("fs"); + +const currentDir = path.resolve(__dirname, "./tree-shaking"); +const dirList = fs.readdirSync(currentDir); +const excludeList = ["node_modules"] + + +const filteredList = dirList.filter((dir) => { + if (dir.startsWith(".")) { + return false; + } + if (excludeList.includes(dir)) { + return false; + } + + return true; +}); + +console.log(`total: ${filteredList.length}`) + +const failedList = filteredList.filter(item => { + const abPath = path.join(currentDir, item, "snapshot", "snap.diff") + return fs.existsSync(abPath) +}) + +console.log(`failed: ${failedList.length}`) +console.log(`passed: ${filteredList.length - failedList.length}`) + From 06651a6b13d160631d6cb460465a778f668aab6b Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Wed, 20 Sep 2023 23:07:46 +0800 Subject: [PATCH 20/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20check.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/check.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rspack/tests/check.js b/crates/rspack/tests/check.js index e6962c13f0f..634f965a1bb 100644 --- a/crates/rspack/tests/check.js +++ b/crates/rspack/tests/check.js @@ -26,4 +26,4 @@ const failedList = filteredList.filter(item => { console.log(`failed: ${failedList.length}`) console.log(`passed: ${filteredList.length - failedList.length}`) - +console.log(failedList) From f900cfaf57dcd691f5d371aa6603d81d1fba605f Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Thu, 21 Sep 2023 00:18:02 +0800 Subject: [PATCH 21/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20lint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/fixtures.rs | 3 +- crates/rspack_core/src/chunk_graph/mod.rs | 2 +- .../rspack_core/src/compiler/compilation.rs | 20 ++-- crates/rspack_core/src/lib.rs | 6 ++ crates/rspack_core/src/module_graph/mod.rs | 15 ++- crates/rspack_core/src/module_graph_module.rs | 93 ++++++++++--------- ...ny_export_imported_specifier_dependency.rs | 4 +- .../harmony_export_specifier_dependency.rs | 2 +- .../esm/harmony_import_dependency.rs | 9 +- .../harmony_import_specifier_dependency.rs | 30 ++---- .../plugin/flag_dependency_usage_plugin.rs | 18 ++-- 11 files changed, 101 insertions(+), 101 deletions(-) diff --git a/crates/rspack/tests/fixtures.rs b/crates/rspack/tests/fixtures.rs index 10297c6b27a..71c691a94d9 100644 --- a/crates/rspack/tests/fixtures.rs +++ b/crates/rspack/tests/fixtures.rs @@ -22,9 +22,10 @@ fn samples(fixture_path: PathBuf) { #[fixture("tests/tree-shaking/*", exclude("node_modules"))] fn tree_shaking(fixture_path: PathBuf) { + std::env::set_var("IS_NEW_TREESHAKING", "1"); // For each test case // First test is old version tree shaking snapshot test - // test_fixture(&fixture_path, Box::new(|_, _| {}), None); + test_fixture(&fixture_path, Box::new(|_, _| {}), None); // second test is webpack based tree shaking test_fixture( &fixture_path, diff --git a/crates/rspack_core/src/chunk_graph/mod.rs b/crates/rspack_core/src/chunk_graph/mod.rs index 156c0f1b6ea..3d7f9c7fdeb 100644 --- a/crates/rspack_core/src/chunk_graph/mod.rs +++ b/crates/rspack_core/src/chunk_graph/mod.rs @@ -1,7 +1,7 @@ use rspack_identifier::IdentifierMap; use rustc_hash::FxHashMap as HashMap; -use crate::{ChunkGroupUkey, ChunkUkey, CompilerOptions}; +use crate::{ChunkGroupUkey, ChunkUkey}; pub mod chunk_graph_chunk; pub mod chunk_graph_module; diff --git a/crates/rspack_core/src/compiler/compilation.rs b/crates/rspack_core/src/compiler/compilation.rs index ed1fb4c66bd..151b1f3f8d9 100644 --- a/crates/rspack_core/src/compiler/compilation.rs +++ b/crates/rspack_core/src/compiler/compilation.rs @@ -32,7 +32,7 @@ use super::{ use crate::{ build_chunk_graph::build_chunk_graph, cache::{use_code_splitting_cache, Cache, CodeSplittingCache}, - debug_exports_info, is_source_equal, + is_source_equal, tree_shaking::{optimizer, visitor::SymbolRef, BailoutFlag, OptimizeDependencyResult}, AddQueue, AddTask, AddTaskResult, AdditionalChunkRuntimeRequirementsArgs, BoxDependency, BoxModule, BuildQueue, BuildTask, BuildTaskResult, CacheCount, CacheOptions, Chunk, ChunkByUkey, @@ -1158,15 +1158,15 @@ impl Compilation { while plugin_driver.optimize_dependencies(self).await?.is_some() {} logger.time_end(start); - if self.options.is_new_tree_shaking() { - // for module in self.module_graph.module_graph_modules().values() {} - // self - // .module_graph - // .module_graph_modules() - // .values() - // .foreach(|item| {}); - debug_exports_info(&self.module_graph); - } + // if self.options.is_new_tree_shaking() { + // // for module in self.module_graph.module_graph_modules().values() {} + // // self + // // .module_graph + // // .module_graph_modules() + // // .values() + // // .foreach(|item| {}); + // debug_exports_info(&self.module_graph); + // } let start = logger.time("create chunks"); use_code_splitting_cache(self, |compilation| async { diff --git a/crates/rspack_core/src/lib.rs b/crates/rspack_core/src/lib.rs index 85cab0df48d..f0ff66a2b03 100644 --- a/crates/rspack_core/src/lib.rs +++ b/crates/rspack_core/src/lib.rs @@ -8,6 +8,7 @@ mod fake_namespace_object; pub use fake_namespace_object::*; mod module_profile; pub use module_profile::*; +use once_cell::sync::Lazy; use rspack_database::Database; pub mod external_module; pub use external_module::*; @@ -251,3 +252,8 @@ impl TryFrom<&str> for ModuleType { pub type ChunkByUkey = Database; pub type ChunkGroupByUkey = Database; pub(crate) type SharedPluginDriver = Arc; + +pub static IS_NEW_TREESHAKING: Lazy = Lazy::new(|| -> bool { + // std::env::set_var(key, value); + std::env::var("IS_NEW_TREESHAKING").is_ok() +}); diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index af2f748336b..fc4cdff01e0 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -7,6 +7,7 @@ use rspack_hash::RspackHashDigest; use rspack_identifier::IdentifierMap; use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; +use crate::IS_NEW_TREESHAKING; mod connection; pub use connection::*; @@ -117,9 +118,13 @@ impl ModuleGraph { ) -> Result<()> { 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()); + let condition = if *IS_NEW_TREESHAKING { + dependency + .as_module_dependency() + .and_then(|dep| dep.get_condition()) + } else { + None + }; self.add_dependency(dependency); self .dependency_id_to_module_identifier @@ -660,6 +665,10 @@ mod test { } impl ModuleDependency for $ident { + fn dependency_debug_name(&self) -> &'static str { + stringify!($ident) + } + fn request(&self) -> &str { &*self.1 } diff --git a/crates/rspack_core/src/module_graph_module.rs b/crates/rspack_core/src/module_graph_module.rs index 623d57ab83c..bda33485850 100644 --- a/crates/rspack_core/src/module_graph_module.rs +++ b/crates/rspack_core/src/module_graph_module.rs @@ -1,13 +1,13 @@ use rspack_error::{internal_error, Result}; use rustc_hash::FxHashSet as HashSet; -use crate::ExportsInfoId; use crate::{ is_async_dependency, module_graph::ConnectionId, BuildInfo, BuildMeta, BuildMetaDefaultObject, BuildMetaExportsType, ChunkGraph, ChunkGroupOptionsKindRef, DependencyId, ExportsArgument, ExportsType, FactoryMeta, ModuleArgument, ModuleGraph, ModuleGraphConnection, ModuleIdentifier, ModuleIssuer, ModuleProfile, ModuleSyntax, ModuleType, }; +use crate::{ExportsInfoId, IS_NEW_TREESHAKING}; #[derive(Debug)] pub struct ModuleGraphModule { @@ -123,51 +123,54 @@ impl ModuleGraphModule { // } pub fn depended_modules<'a>(&self, module_graph: &'a ModuleGraph) -> Vec<&'a ModuleIdentifier> { + if *IS_NEW_TREESHAKING { + self + .outgoing_connections_unordered(module_graph) + .expect("should have outgoing connections") + .filter_map(|con: &ModuleGraphConnection| { + // TODO: runtime opt + let active_state = con.get_active_state(module_graph, None); + // dbg!(&con, &active_state,); + // dbg!(&module_graph + // .dependency_by_id(&con.dependency_id) + // .and_then(|dep| dep + // .as_module_dependency() + // .map(|item| item.dependency_debug_name()))); + match active_state { + crate::ConnectionState::Bool(false) => None, + _ => Some(con.dependency_id), + } + }) + .filter(|id| { + if let Some(dep) = module_graph + .dependency_by_id(id) + .expect("should have id") + .as_module_dependency() + { + return !is_async_dependency(dep) && !dep.weak(); + } + false + }) + .filter_map(|id| module_graph.module_identifier_by_dependency_id(&id)) + .collect() + } else { + self + .dependencies + .iter() + .filter(|id| { + if let Some(dep) = module_graph + .dependency_by_id(id) + .expect("should have id") + .as_module_dependency() + { + return !is_async_dependency(dep) && !dep.weak(); + } + false + }) + .filter_map(|id| module_graph.module_identifier_by_dependency_id(id)) + .collect() + } // dbg!(&self.module_identifier); - self - .outgoing_connections_unordered(module_graph) - .unwrap() - .filter_map(|con: &ModuleGraphConnection| { - // TODO: runtime opt - let active_state = con.get_active_state(module_graph, None); - // dbg!(&con, &active_state,); - // dbg!(&module_graph - // .dependency_by_id(&con.dependency_id) - // .and_then(|dep| dep - // .as_module_dependency() - // .map(|item| item.dependency_debug_name()))); - match active_state { - crate::ConnectionState::Bool(false) => None, - _ => Some(con.dependency_id), - } - }) - .filter(|id| { - if let Some(dep) = module_graph - .dependency_by_id(id) - .expect("should have id") - .as_module_dependency() - { - return !is_async_dependency(dep) && !dep.weak(); - } - false - }) - .filter_map(|id| module_graph.module_identifier_by_dependency_id(&id)) - .collect() - // self - // .dependencies - // .iter() - // .filter(|id| { - // if let Some(dep) = module_graph - // .dependency_by_id(id) - // .expect("should have id") - // .as_module_dependency() - // { - // return !is_async_dependency(dep) && !dep.weak(); - // } - // false - // }) - // .filter_map(|id| module_graph.module_identifier_by_dependency_id(id)) - // .collect() } pub fn dynamic_depended_modules<'a>( 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 a8fd459defd..5ce11799b57 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 @@ -402,7 +402,6 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { None }; - dbg!(&is_new_tree_shaking); if is_new_tree_shaking { // TODO: runtime opt let mode = self.get_mode( @@ -417,7 +416,7 @@ impl DependencyTemplate for HarmonyExportImportedSpecifierDependency { None, ); if !matches!(mode.ty, ExportModeType::Unused | ExportModeType::EmptyStar) { - harmony_import_dependency_apply(self, code_generatable_context, &vec![]); + harmony_import_dependency_apply(self, code_generatable_context, &[]); } } @@ -543,7 +542,6 @@ impl ModuleDependency for HarmonyExportImportedSpecifierDependency { &self.id, runtime, ); - dbg!(&mode, &self.ids); match mode.ty { ExportModeType::Missing | ExportModeType::Unused 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 7d65f629e49..0bcdaf2db54 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, - ModuleDependency, TemplateContext, TemplateReplaceSource, UsedName, + TemplateContext, TemplateReplaceSource, UsedName, }; use swc_core::ecma::atoms::JsWord; 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 117f9a2a443..97cecb6f4e2 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/harmony_import_dependency.rs @@ -1,5 +1,3 @@ -use std::ops::ControlFlow; - use rspack_core::tree_shaking::symbol::{self, IndirectTopLevelSymbol}; use rspack_core::tree_shaking::visitor::SymbolRef; use rspack_core::{ @@ -57,7 +55,7 @@ impl HarmonyImportDependency { pub fn harmony_import_dependency_apply( module_dependency: &T, code_generatable_context: &mut TemplateContext, - specifiers: &Vec, + specifiers: &[Specifier], ) { let compilation = &code_generatable_context.compilation; let module = &code_generatable_context.module; @@ -71,7 +69,6 @@ pub fn harmony_import_dependency_apply( .connection_by_dependency(module_dependency.id()); if let Some(con) = connection { // TODO: runtime opt - let ret = con.is_target_active(&compilation.module_graph, None); // dbg!( // &con, // &ret, @@ -81,7 +78,7 @@ pub fn harmony_import_dependency_apply( // .and_then(|item| item.as_module_dependency()) // .map(|item| item.dependency_debug_name()) // ); - ret + con.is_target_active(&compilation.module_graph, None) } else { true } @@ -244,7 +241,7 @@ impl Dependency for HarmonyImportDependency { ) -> ConnectionState { if let Some(module) = module_graph .module_identifier_by_dependency_id(&self.id) - .and_then(|module_identifier| module_graph.module_by_identifier(&module_identifier)) + .and_then(|module_identifier| module_graph.module_by_identifier(module_identifier)) { module.get_side_effects_connection_state(module_graph, module_chain) } else { 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 98bcb721882..e627026ab5c 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 @@ -133,28 +133,19 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { .expect("should have ref module"); let compilation = &code_generatable_context.compilation; - let ref_mgm = compilation - .module_graph - .module_graph_module_by_dependency_id(&self.id) - .expect("should have ref module"); - let is_target_active = if compilation.options.is_new_tree_shaking() { + if compilation.options.is_new_tree_shaking() { let connection = compilation.module_graph.connection_by_dependency(&self.id); - if let Some(con) = connection { + let is_target_active = if let Some(con) = connection { // TODO: runtime opt - let ret = con.is_target_active(&compilation.module_graph, None); - - ret + con.is_target_active(&compilation.module_graph, None) } else { true + }; + + if !is_target_active { + return; } - } else { - compilation - .include_module_ids - .contains(&ref_mgm.module_identifier) }; - if !is_target_active { - return; - } let used = self.check_used(reference_mgm, compilation); if !used { @@ -175,11 +166,7 @@ impl DependencyTemplate for HarmonyImportSpecifierDependency { // TODO: scope hoist if compilation.options.is_new_tree_shaking() { - harmony_import_dependency_apply( - self, - code_generatable_context, - &vec![self.specifier.clone()], - ); + harmony_import_dependency_apply(self, code_generatable_context, &[self.specifier.clone()]); } let export_expr = export_from_import( code_generatable_context, @@ -251,7 +238,6 @@ impl ModuleDependency for HarmonyImportSpecifierDependency { _runtime: Option<&RuntimeSpec>, ) -> Vec { // namespace import - dbg!(&self.ids); if self.ids.is_empty() { return self.get_referenced_exports_in_destructuring(None); } 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 deafaadda1c..f17aee64926 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 @@ -121,14 +121,14 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { } else { continue; }; - dbg!( - &connection, - dep - .as_module_dependency() - .map(|item| item.dependency_debug_name()), - &referenced_exports, - &old_referenced_exports - ); + // dbg!( + // &connection, + // dep + // .as_module_dependency() + // .map(|item| item.dependency_debug_name()), + // &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)) @@ -203,7 +203,7 @@ impl<'a> FlagDependencyUsagePluginProxy<'a> { } for (module_id, referenced_exports) in map { - dbg!(&module_id, &referenced_exports); + // dbg!(&module_id, &referenced_exports); let normalized_refs = match referenced_exports { ProcessModuleReferencedExports::Map(map) => map.into_values().collect::>(), ProcessModuleReferencedExports::ExtendRef(extend_ref) => extend_ref, From 99afe64ba348535f9de19160e4c83250d2b5f594 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Thu, 21 Sep 2023 10:54:50 +0800 Subject: [PATCH 22/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2979e31c71..eaa715fbd29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -169,4 +169,4 @@ jobs: echo 'debug = false' >> Cargo.toml - name: Run test - run: cargo test --workspace -- --nocapture + run: IS_NEW_TREESHAKING=1 cargo test --workspace -- --nocapture From e55b2be51091b2b599e0c5f58fcf521ceb3501f5 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Thu, 21 Sep 2023 11:45:04 +0800 Subject: [PATCH 23/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20update=20env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack/tests/fixtures.rs | 4 +++- crates/rspack_core/src/lib.rs | 7 +++---- crates/rspack_core/src/module_graph/mod.rs | 2 +- crates/rspack_core/src/module_graph_module.rs | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/rspack/tests/fixtures.rs b/crates/rspack/tests/fixtures.rs index 71c691a94d9..e498a59bcdd 100644 --- a/crates/rspack/tests/fixtures.rs +++ b/crates/rspack/tests/fixtures.rs @@ -1,7 +1,8 @@ use std::path::PathBuf; +use std::sync::atomic::Ordering; use cargo_rst::git_diff; -use rspack_core::{BoxPlugin, CompilerOptions, TreeShaking, UsedExportsOption}; +use rspack_core::{BoxPlugin, CompilerOptions, TreeShaking, UsedExportsOption, IS_NEW_TREESHAKING}; use rspack_plugin_javascript::{FlagDependencyExportsPlugin, FlagDependencyUsagePlugin}; use rspack_testing::test_fixture; use testing_macros::fixture; @@ -27,6 +28,7 @@ fn tree_shaking(fixture_path: PathBuf) { // First test is old version tree shaking snapshot test test_fixture(&fixture_path, Box::new(|_, _| {}), None); // second test is webpack based tree shaking + IS_NEW_TREESHAKING.store(true, Ordering::SeqCst); test_fixture( &fixture_path, Box::new( diff --git a/crates/rspack_core/src/lib.rs b/crates/rspack_core/src/lib.rs index f0ff66a2b03..a785059b915 100644 --- a/crates/rspack_core/src/lib.rs +++ b/crates/rspack_core/src/lib.rs @@ -3,12 +3,14 @@ #![feature(box_patterns)] #![feature(anonymous_lifetime_in_impl_trait)] +use std::sync::atomic::AtomicBool; use std::{fmt, sync::Arc}; mod fake_namespace_object; pub use fake_namespace_object::*; mod module_profile; pub use module_profile::*; use once_cell::sync::Lazy; +use rkyv::with::Atomic; use rspack_database::Database; pub mod external_module; pub use external_module::*; @@ -253,7 +255,4 @@ pub type ChunkByUkey = Database; pub type ChunkGroupByUkey = Database; pub(crate) type SharedPluginDriver = Arc; -pub static IS_NEW_TREESHAKING: Lazy = Lazy::new(|| -> bool { - // std::env::set_var(key, value); - std::env::var("IS_NEW_TREESHAKING").is_ok() -}); +pub static IS_NEW_TREESHAKING: AtomicBool = AtomicBool::new(false); diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index fc4cdff01e0..181089e26dc 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -118,7 +118,7 @@ impl ModuleGraph { ) -> Result<()> { let is_module_dependency = dependency.as_module_dependency().is_some(); let dependency_id = *dependency.id(); - let condition = if *IS_NEW_TREESHAKING { + let condition = if IS_NEW_TREESHAKING.load(std::sync::atomic::Ordering::Relaxed) { dependency .as_module_dependency() .and_then(|dep| dep.get_condition()) diff --git a/crates/rspack_core/src/module_graph_module.rs b/crates/rspack_core/src/module_graph_module.rs index bda33485850..0c70b42bb90 100644 --- a/crates/rspack_core/src/module_graph_module.rs +++ b/crates/rspack_core/src/module_graph_module.rs @@ -123,7 +123,7 @@ impl ModuleGraphModule { // } pub fn depended_modules<'a>(&self, module_graph: &'a ModuleGraph) -> Vec<&'a ModuleIdentifier> { - if *IS_NEW_TREESHAKING { + if IS_NEW_TREESHAKING.load(std::sync::atomic::Ordering::Relaxed) { self .outgoing_connections_unordered(module_graph) .expect("should have outgoing connections") From 31e064306fbe2b39dbd96311dd9b9229d0718d96 Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Thu, 21 Sep 2023 11:55:26 +0800 Subject: [PATCH 24/24] =?UTF-8?q?chore:=20=F0=9F=A4=96=20lint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/rspack_core/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/rspack_core/src/lib.rs b/crates/rspack_core/src/lib.rs index a785059b915..e226e09f5c1 100644 --- a/crates/rspack_core/src/lib.rs +++ b/crates/rspack_core/src/lib.rs @@ -9,8 +9,6 @@ mod fake_namespace_object; pub use fake_namespace_object::*; mod module_profile; pub use module_profile::*; -use once_cell::sync::Lazy; -use rkyv::with::Atomic; use rspack_database::Database; pub mod external_module; pub use external_module::*;