diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 8e7d6a59ad4e0..5c8e1705395b4 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -645,6 +645,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { self.visit_statement(&stmt.body); /* cfg - condition basic block */ + let after_body_graph_ix = self.cfg.current_node_ix; let start_of_condition_graph_ix = self.cfg.new_basic_block(); /* cfg */ @@ -655,18 +656,14 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { let end_do_while_graph_ix = self.cfg.new_basic_block(); - // before do while to start of condition basic block - self.cfg.add_edge( - before_do_while_stmt_graph_ix, - start_of_condition_graph_ix, - EdgeType::Normal, - ); + // before do while to start of body basic block + self.cfg.add_edge(before_do_while_stmt_graph_ix, start_body_graph_ix, EdgeType::Normal); // body of do-while to start of condition - self.cfg.add_edge(start_body_graph_ix, start_of_condition_graph_ix, EdgeType::Backedge); + self.cfg.add_edge(after_body_graph_ix, start_of_condition_graph_ix, EdgeType::Normal); // end of condition to after do while self.cfg.add_edge(end_of_condition_graph_ix, end_do_while_graph_ix, EdgeType::Normal); // end of condition to after start of body - self.cfg.add_edge(end_of_condition_graph_ix, start_body_graph_ix, EdgeType::Normal); + self.cfg.add_edge(end_of_condition_graph_ix, start_body_graph_ix, EdgeType::Backedge); self.cfg.restore_state( &statement_state, diff --git a/crates/oxc_semantic/tests/integration/snapshots/integration__cfg__cfg_files@do_while_break.js-2.snap b/crates/oxc_semantic/tests/integration/snapshots/integration__cfg__cfg_files@do_while_break.js-2.snap index 6d356b9a651ae..8a92966fcd7f5 100644 --- a/crates/oxc_semantic/tests/integration/snapshots/integration__cfg__cfg_files@do_while_break.js-2.snap +++ b/crates/oxc_semantic/tests/integration/snapshots/integration__cfg__cfg_files@do_while_break.js-2.snap @@ -26,18 +26,18 @@ digraph { 2 -> 3 [ label = Normal ] 4 -> 5 [ label = Unreachable , style = "dotted" ] 4 -> 5 [ label = Normal ] - 3 -> 6 [ label = Normal ] - 4 -> 6 [ label = Backedge ] + 3 -> 4 [ label = Normal ] + 5 -> 6 [ label = Normal ] 6 -> 7 [ label = Normal ] - 6 -> 4 [ label = Normal ] + 6 -> 4 [ label = Backedge ] 7 -> 8 [ label = Unreachable , style = "dotted" ] 2 -> 9 [ label = Normal ] 10 -> 11 [ label = Unreachable , style = "dotted" ] 10 -> 11 [ label = Normal ] - 9 -> 12 [ label = Normal ] - 10 -> 12 [ label = Backedge ] + 9 -> 10 [ label = Normal ] + 11 -> 12 [ label = Normal ] 12 -> 13 [ label = Normal ] - 12 -> 10 [ label = Normal ] + 12 -> 10 [ label = Backedge ] 13 -> 14 [ label = Normal ] 0 -> 15 [ label = Normal ] }