From 464cfeab81160c5d8751621c1426166ef7435c1e Mon Sep 17 00:00:00 2001 From: IWANABETHATGUY Date: Tue, 19 Sep 2023 14:32:47 +0800 Subject: [PATCH] =?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 311f3555af4c..0786f055778c 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 172ab0000b9e..000000000000 --- 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 9da746e7efa1..75d4152918d5 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