diff --git a/crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs b/crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs index dde449438..5b3e02a27 100644 --- a/crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs +++ b/crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs @@ -6,7 +6,7 @@ use swc_core::ecma::ast::{ Decl, ExportDecl, ExportSpecifier, Id, ImportDecl, ImportSpecifier, Module as SwcModule, Module, ModuleExportName, }; -use swc_core::ecma::transforms::compat::es2015::destructuring; +use swc_core::ecma::transforms::compat::es2015::{destructuring, for_of}; use swc_core::ecma::transforms::compat::es2018::object_rest_spread; use swc_core::ecma::visit::{VisitMut, VisitMutWith, VisitWith}; @@ -272,6 +272,7 @@ fn optimize_import_namespace(import_infos: &mut [ImportInfo], module: &mut Modul let mut shadow = module.clone(); shadow.visit_mut_with(&mut object_rest_spread(Default::default())); + shadow.visit_mut_with(&mut for_of(Default::default())); shadow.visit_mut_with(&mut destructuring(Default::default())); shadow.visit_with(&mut v); diff --git a/e2e/fixtures/tree-shaking.import_namespace/src/index.tsx b/e2e/fixtures/tree-shaking.import_namespace/src/index.tsx index cfba35f0a..ea670f77e 100644 --- a/e2e/fixtures/tree-shaking.import_namespace/src/index.tsx +++ b/e2e/fixtures/tree-shaking.import_namespace/src/index.tsx @@ -19,3 +19,10 @@ let {a, ...restObject} = object console.log(a,restObject) let copiedObject = {...object} console.log(copiedObject) + +// ref https://github.com/swc-project/swc/discussions/9647 +for (const [k1, v1] of Object.entries(object)){ + for (const [k2, v2] of Object.entries(object)){ + console.log(k1,k2,v1,v2); + } +}