From 19bfccd61c3f9d0ae57454392999e64a2bfc375b Mon Sep 17 00:00:00 2001 From: Jinbao1001 Date: Tue, 24 Sep 2024 21:07:21 +0800 Subject: [PATCH] fix: deps sort not stable --- crates/mako/src/module_graph.rs | 28 +------------------ .../plugins/tree_shaking/shake/skip_module.rs | 5 ---- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/crates/mako/src/module_graph.rs b/crates/mako/src/module_graph.rs index b714dbd55..b881bbac3 100644 --- a/crates/mako/src/module_graph.rs +++ b/crates/mako/src/module_graph.rs @@ -9,7 +9,7 @@ use petgraph::visit::IntoEdgeReferences; use petgraph::Direction; use tracing::{debug, warn}; -use crate::module::{Dependencies, Dependency, Module, ModuleId, ResolveType}; +use crate::module::{Dependencies, Dependency, Module, ModuleId}; #[derive(Debug)] pub struct ModuleGraph { @@ -304,32 +304,6 @@ impl ModuleGraph { targets } - pub fn remove_dependency_module_by_source_and_resolve_type( - &mut self, - module_id: &ModuleId, - source: &String, - resolve_type: ResolveType, - ) { - let mut edges = self.get_edges(module_id, Direction::Outgoing); - - while let Some((edge_index, _node_index)) = edges.next(&self.graph) { - let dependencies = self.graph.edge_weight_mut(edge_index).unwrap(); - let mut found = false; - dependencies.retain(|dep| { - if !found && source == &dep.source && dep.resolve_type.same_enum(&resolve_type) { - found = true; - false - } else { - true - } - }); - if dependencies.is_empty() { - self.graph.remove_edge(edge_index); - } - return; - } - } - pub fn rewrite_dependency(&mut self, module_id: &ModuleId, deps: Vec<(&ModuleId, Dependency)>) { let mut edges = self.get_edges(module_id, Direction::Outgoing); while let Some((edge_index, _node_index)) = edges.next(&self.graph) { diff --git a/crates/mako/src/plugins/tree_shaking/shake/skip_module.rs b/crates/mako/src/plugins/tree_shaking/shake/skip_module.rs index 1eed7835b..4b451c6cb 100644 --- a/crates/mako/src/plugins/tree_shaking/shake/skip_module.rs +++ b/crates/mako/src/plugins/tree_shaking/shake/skip_module.rs @@ -196,13 +196,10 @@ pub(super) fn skip_module_optimize( let mut to_insert = vec![]; let mut to_insert_deps = vec![]; let mut to_delete = false; - let mut resolve_type: Option = None; match &mut stmt { ModuleItem::ModuleDecl(module_decl) => match module_decl { ModuleDecl::Import(import_decl) => { - resolve_type = Some(ResolveType::Import(ImportType::empty())); - for replace in replaces { let mut matched_index = None; let mut matched_ident = None; @@ -254,8 +251,6 @@ pub(super) fn skip_module_optimize( ModuleDecl::ExportDecl(_) => {} ModuleDecl::ExportNamed(export_named) => { if export_named.src.is_some() { - resolve_type = Some(ResolveType::ExportNamed(NamedExportType::empty())); - for replace in replaces { let mut matched_index = None; let mut matched_ident = None;