Skip to content

Commit

Permalink
fix: deps sort not stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinbao1001 committed Sep 24, 2024
1 parent bea938c commit 19bfccd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
28 changes: 1 addition & 27 deletions crates/mako/src/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)>) {

Check warning on line 307 in crates/mako/src/module_graph.rs

View check run for this annotation

Codecov / codecov/patch

crates/mako/src/module_graph.rs#L307

Added line #L307 was not covered by tests
let mut edges = self.get_edges(module_id, Direction::Outgoing);
while let Some((edge_index, _node_index)) = edges.next(&self.graph) {
Expand Down
5 changes: 0 additions & 5 deletions crates/mako/src/plugins/tree_shaking/shake/skip_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResolveType> = 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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 19bfccd

Please sign in to comment.