Skip to content

Commit

Permalink
move edges from dependany
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 14, 2024
1 parent 179a3a4 commit ef50fbb
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions turbopack/crates/turbopack-ecmascript/src/tree_shake/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,20 +1494,25 @@ impl DepGraph {
continue;
}

let dependants = g
.edges_directed(declarator, Direction::Incoming)
.map(|e| (e.source(), *e.weight()))
.collect::<Vec<_>>();

// We depend on the export node to preserve the export
queue.push((declarator, node, dependencies));
queue.push((node, declarator, dependants));
}
}

for (original, dependant, dependencies) in queue {
for (node, declarator, dependants) in queue {
// Move all edges from node to dependant
for dependency in dependencies {
g.add_edge(dependant, dependency, Dependency::Strong);
}
for (dependant, weight) in dependants {
g.add_edge(dependant, node, weight);

// Move items from original to dependant
let items = g.node_weight(original).expect("Node should exist").clone();
g.node_weight_mut(dependant).unwrap().extend(items);
if let Some(edge) = g.edges_connecting(dependant, declarator).next() {
g.remove_edge(edge.id());
}
}
}
}
}
Expand Down

0 comments on commit ef50fbb

Please sign in to comment.