diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index 928fa003691d7..781702baa3c06 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -1573,12 +1573,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { self.visit_catch_clause(handler); /* cfg */ - control_flow!(self, |cfg| { - let catch_block_end_ix = cfg.current_node_ix; - // TODO: we shouldn't directly change the current node index. - cfg.current_node_ix = after_try_block_graph_ix; - Some(catch_block_end_ix) - }) + control_flow!(self, |cfg| Some(cfg.current_node_ix)) /* cfg */ } else { None @@ -1605,12 +1600,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { self.visit_block_statement(finalizer); /* cfg */ - control_flow!(self, |cfg| { - let finally_block_end_ix = cfg.current_node_ix; - // TODO: we shouldn't directly change the current node index. - cfg.current_node_ix = after_try_block_graph_ix; - Some(finally_block_end_ix) - }) + control_flow!(self, |cfg| Some(cfg.current_node_ix)) /* cfg */ } else { None @@ -1623,7 +1613,6 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { /* cfg */ control_flow!(self, |cfg| { - let after_try_statement_block_ix = cfg.new_basic_block_normal(); cfg.add_edge( before_try_statement_graph_ix, before_try_block_graph_ix, @@ -1632,6 +1621,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { if let Some(catch_block_end_ix) = catch_block_end_ix && finally_block_end_ix.is_none() { + let after_try_statement_block_ix = cfg.new_basic_block_normal(); cfg.add_edge( after_try_block_graph_ix, after_try_statement_block_ix, @@ -1641,6 +1631,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { cfg.add_edge(catch_block_end_ix, after_try_statement_block_ix, EdgeType::Normal); } if let Some(finally_block_end_ix) = finally_block_end_ix { + let after_try_statement_block_ix = cfg.new_basic_block_normal(); if catch_block_end_ix.is_some() { cfg.add_edge( finally_block_end_ix, diff --git a/crates/oxc_semantic/tests/integration/snapshots/do_while_break.snap b/crates/oxc_semantic/tests/integration/snapshots/do_while_break.snap index f172c9cab01a8..045354588cc3a 100644 --- a/crates/oxc_semantic/tests/integration/snapshots/do_while_break.snap +++ b/crates/oxc_semantic/tests/integration/snapshots/do_while_break.snap @@ -98,8 +98,8 @@ return" shape = box] 9 -> 10 [ label="Normal", style="dotted"] 9 -> 7 [ label="Backedge", style="dotted", color=grey] 7 -> 10 [ label="Jump", color=green] - 11 -> 2 [ label="Error(Implicit)", color=red, style=dashed] 3 -> 5 [ label="Normal"] + 11 -> 2 [ label="Error(Implicit)", color=red, style=dashed] 10 -> 11 [ label="Join"] 12 -> 0 [ label="Error(Implicit)", color=red, style=dashed] 1 -> 12 [ label="Normal"] diff --git a/crates/oxc_semantic/tests/integration/snapshots/function_in_finally.snap b/crates/oxc_semantic/tests/integration/snapshots/function_in_finally.snap index e06d0ed54cd6b..166620c09a05a 100644 --- a/crates/oxc_semantic/tests/integration/snapshots/function_in_finally.snap +++ b/crates/oxc_semantic/tests/integration/snapshots/function_in_finally.snap @@ -65,7 +65,7 @@ ExpressionStatement" shape = box] 4 -> 6 [ label="NewFunction"] 7 -> 0 [ label="Error(Implicit)", color=red, style=dashed] 4 -> 7 [ label="Normal"] - 8 -> 0 [ label="Error(Implicit)", color=red, style=dashed] 1 -> 3 [ label="Normal"] + 8 -> 0 [ label="Error(Implicit)", color=red, style=dashed] 7 -> 8 [ label="Join"] } diff --git a/crates/oxc_semantic/tests/integration/snapshots/labeled_block_break.snap b/crates/oxc_semantic/tests/integration/snapshots/labeled_block_break.snap index 1ec5323500ad7..36e0b424a61fb 100644 --- a/crates/oxc_semantic/tests/integration/snapshots/labeled_block_break.snap +++ b/crates/oxc_semantic/tests/integration/snapshots/labeled_block_break.snap @@ -89,8 +89,8 @@ unreachable" shape = box] 9 -> 0 [ label="Error(Implicit)", color=red, style=dashed] 8 -> 9 [ label="Normal"] 6 -> 9 [ label="Jump", color=green] - 10 -> 0 [ label="Error(Implicit)", color=red, style=dashed] 1 -> 3 [ label="Normal"] + 10 -> 0 [ label="Error(Implicit)", color=red, style=dashed] 3 -> 10 [ label="Normal"] 9 -> 10 [ label="Normal"] } diff --git a/crates/oxc_semantic/tests/integration/snapshots/labelled_try_break.snap b/crates/oxc_semantic/tests/integration/snapshots/labelled_try_break.snap index 5699b7b273b55..357b9cdae9170 100644 --- a/crates/oxc_semantic/tests/integration/snapshots/labelled_try_break.snap +++ b/crates/oxc_semantic/tests/integration/snapshots/labelled_try_break.snap @@ -95,8 +95,8 @@ unreachable" shape = box] 4 -> 7 [ label="Normal"] 8 -> 2 [ label="Error(Implicit)", style=dashed, color=red] 7 -> 8 [ label="Unreachable", style="dotted"] - 9 -> 2 [ label="Error(Implicit)", style=dashed, color=red] 3 -> 5 [ label="Normal"] + 9 -> 2 [ label="Error(Implicit)", style=dashed, color=red] 8 -> 9 [ label="Unreachable", style="dotted"] 10 -> 2 [ label="Error(Implicit)", color=red, style=dashed] 9 -> 10 [ label="Normal", style="dotted"]