diff --git a/crates/oxc_semantic/src/pg.rs b/crates/oxc_semantic/src/pg.rs index 8da2e3dc1f534..5398643a498a3 100644 --- a/crates/oxc_semantic/src/pg.rs +++ b/crates/oxc_semantic/src/pg.rs @@ -29,19 +29,19 @@ where while let Some((graph_ix, state)) = q.pop() { let mut edges = 0; - if visited.contains(&graph_ix) { - continue; - } - visited.insert(graph_ix); + for edge in graph.edges_directed(graph_ix, Direction::Outgoing) { + if visited.contains(&edge.target()) { + continue; + } if let Some(result_of_edge_filtering) = edge_filter(edge.weight()) { final_states.push(result_of_edge_filtering); } else { - let opposite_dir_of_edge_graph_ix = edge.target(); - let (new_state, keep_walking_this_path) = - visitor(&opposite_dir_of_edge_graph_ix, state.clone()); + let target = edge.target(); + let (new_state, keep_walking_this_path) = visitor(&target, state.clone()); + visited.insert(target); if keep_walking_this_path { - q.push((opposite_dir_of_edge_graph_ix, new_state.clone())); + q.push((target, new_state.clone())); } else { final_states.push(new_state.clone()); }