diff --git a/turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs b/turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs index 0d16c36f05511..f3c62c54359f1 100644 --- a/turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs +++ b/turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs @@ -14,7 +14,7 @@ use turbopack_core::{ use super::{ chunk_item::EcmascriptModulePartChunkItem, get_part_id, part_of_module, split, split_module, - Key, PartId, SplitResult, + Key, SplitResult, }; use crate::{ chunk::{EcmascriptChunkPlaceable, EcmascriptExports}, @@ -219,16 +219,11 @@ impl Module for EcmascriptModulePartAsset { let mut assets = deps .iter() - .map(|part_id| { + .map(|&part_id| { Ok(Vc::upcast(SingleModuleReference::new( Vc::upcast(EcmascriptModulePartAsset::new( self.full_module, - match part_id { - PartId::Internal(part_id) => ModulePart::internal(*part_id), - PartId::Export(name) => ModulePart::export(name.clone()), - PartId::ModuleEvaluation => ModulePart::evaluation(), - PartId::Exports => ModulePart::exports(), - }, + ModulePart::internal(part_id), self.import_externals, )), Vc::cell("ecmascript module part".into()), diff --git a/turbopack/crates/turbopack-ecmascript/src/tree_shake/graph.rs b/turbopack/crates/turbopack-ecmascript/src/tree_shake/graph.rs index 3ebbcc3ef0dc6..fb45f60c27edf 100644 --- a/turbopack/crates/turbopack-ecmascript/src/tree_shake/graph.rs +++ b/turbopack/crates/turbopack-ecmascript/src/tree_shake/graph.rs @@ -207,7 +207,7 @@ pub(super) struct SplitModuleResult { pub entrypoints: FxHashMap, /// Dependency between parts. - pub part_deps: FxHashMap>, + pub part_deps: FxHashMap>, pub modules: Vec, pub star_reexports: Vec, @@ -248,7 +248,7 @@ impl DepGraph { ) -> SplitModuleResult { let groups = self.finalize(data); let mut exports = FxHashMap::default(); - let mut part_deps = FxHashMap::<_, Vec>::default(); + let mut part_deps = FxHashMap::<_, Vec<_>>::default(); let star_reexports: Vec<_> = data .values() @@ -270,7 +270,6 @@ impl DepGraph { } let mut declarator = FxHashMap::default(); - let mut exporter = FxHashMap::default(); for (ix, group) in groups.graph_ix.iter().enumerate() { for id in group { @@ -279,10 +278,6 @@ impl DepGraph { for var in item.var_decls.iter() { declarator.entry(var.clone()).or_insert_with(|| ix as u32); } - - if let Some(export) = &item.export { - exporter.insert(export.clone(), ix as u32); - } } } @@ -393,7 +388,7 @@ impl DepGraph { } // Import variables - for &var in &required_vars { + for var in required_vars { let Some(&dep) = declarator.get(var) else { continue; }; @@ -412,10 +407,7 @@ impl DepGraph { is_type_only: false, })]; - part_deps - .entry(ix as u32) - .or_default() - .push(PartId::Internal(dep)); + part_deps.entry(ix as u32).or_default().push(dep); chunk .body @@ -431,38 +423,6 @@ impl DepGraph { }))); } - // Depend on exports. - // - // We preserve the export if the content is preserved. - // It's for server actions, where we need to preserve the export if the content is used. - for &var in &required_vars { - let Some(&dep) = exporter.get(&var.0) else { - continue; - }; - - if dep == ix as u32 { - continue; - } - - part_deps - .entry(ix as u32) - .or_default() - .push(PartId::Export(var.0.as_str().into())); - - chunk - .body - .push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { - span: DUMMY_SP, - specifiers: vec![], - src: Box::new(TURBOPACK_PART_IMPORT_SOURCE.into()), - type_only: false, - with: Some(Box::new(create_turbopack_part_id_assert(PartId::Export( - var.0.as_str().into(), - )))), - phase: Default::default(), - }))); - } - for g in group { // Skip directives, as we copy them to each modules. if let ModuleItem::Stmt(Stmt::Expr(ExprStmt { diff --git a/turbopack/crates/turbopack-ecmascript/src/tree_shake/mod.rs b/turbopack/crates/turbopack-ecmascript/src/tree_shake/mod.rs index b9d490ed34b47..1782cab5a90ee 100644 --- a/turbopack/crates/turbopack-ecmascript/src/tree_shake/mod.rs +++ b/turbopack/crates/turbopack-ecmascript/src/tree_shake/mod.rs @@ -398,7 +398,7 @@ pub(crate) enum SplitResult { modules: Vec>, #[turbo_tasks(trace_ignore)] - deps: FxHashMap>, + deps: FxHashMap>, #[turbo_tasks(debug_ignore, trace_ignore)] star_reexports: Vec,