Skip to content

Commit 109f452

Browse files
committed
refactor(semantic): eliminate manual current_node_ix manipulation in try statements (#14858)
fixes the `TODO`​ comments left in the code
1 parent f3b75c3 commit 109f452

File tree

5 files changed

+8
-17
lines changed

5 files changed

+8
-17
lines changed

crates/oxc_semantic/src/builder.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,12 +1573,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
15731573
self.visit_catch_clause(handler);
15741574

15751575
/* cfg */
1576-
control_flow!(self, |cfg| {
1577-
let catch_block_end_ix = cfg.current_node_ix;
1578-
// TODO: we shouldn't directly change the current node index.
1579-
cfg.current_node_ix = after_try_block_graph_ix;
1580-
Some(catch_block_end_ix)
1581-
})
1576+
control_flow!(self, |cfg| Some(cfg.current_node_ix))
15821577
/* cfg */
15831578
} else {
15841579
None
@@ -1605,12 +1600,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
16051600
self.visit_block_statement(finalizer);
16061601

16071602
/* cfg */
1608-
control_flow!(self, |cfg| {
1609-
let finally_block_end_ix = cfg.current_node_ix;
1610-
// TODO: we shouldn't directly change the current node index.
1611-
cfg.current_node_ix = after_try_block_graph_ix;
1612-
Some(finally_block_end_ix)
1613-
})
1603+
control_flow!(self, |cfg| Some(cfg.current_node_ix))
16141604
/* cfg */
16151605
} else {
16161606
None
@@ -1623,7 +1613,6 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
16231613

16241614
/* cfg */
16251615
control_flow!(self, |cfg| {
1626-
let after_try_statement_block_ix = cfg.new_basic_block_normal();
16271616
cfg.add_edge(
16281617
before_try_statement_graph_ix,
16291618
before_try_block_graph_ix,
@@ -1632,6 +1621,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
16321621
if let Some(catch_block_end_ix) = catch_block_end_ix
16331622
&& finally_block_end_ix.is_none()
16341623
{
1624+
let after_try_statement_block_ix = cfg.new_basic_block_normal();
16351625
cfg.add_edge(
16361626
after_try_block_graph_ix,
16371627
after_try_statement_block_ix,
@@ -1641,6 +1631,7 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
16411631
cfg.add_edge(catch_block_end_ix, after_try_statement_block_ix, EdgeType::Normal);
16421632
}
16431633
if let Some(finally_block_end_ix) = finally_block_end_ix {
1634+
let after_try_statement_block_ix = cfg.new_basic_block_normal();
16441635
if catch_block_end_ix.is_some() {
16451636
cfg.add_edge(
16461637
finally_block_end_ix,

crates/oxc_semantic/tests/integration/snapshots/do_while_break.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ return" shape = box]
9898
9 -> 10 [ label="Normal", style="dotted"]
9999
9 -> 7 [ label="Backedge", style="dotted", color=grey]
100100
7 -> 10 [ label="Jump", color=green]
101-
11 -> 2 [ label="Error(Implicit)", color=red, style=dashed]
102101
3 -> 5 [ label="Normal"]
102+
11 -> 2 [ label="Error(Implicit)", color=red, style=dashed]
103103
10 -> 11 [ label="Join"]
104104
12 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
105105
1 -> 12 [ label="Normal"]

crates/oxc_semantic/tests/integration/snapshots/function_in_finally.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ExpressionStatement" shape = box]
6565
4 -> 6 [ label="NewFunction"]
6666
7 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
6767
4 -> 7 [ label="Normal"]
68-
8 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
6968
1 -> 3 [ label="Normal"]
69+
8 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
7070
7 -> 8 [ label="Join"]
7171
}

crates/oxc_semantic/tests/integration/snapshots/labeled_block_break.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ unreachable" shape = box]
8989
9 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
9090
8 -> 9 [ label="Normal"]
9191
6 -> 9 [ label="Jump", color=green]
92-
10 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
9392
1 -> 3 [ label="Normal"]
93+
10 -> 0 [ label="Error(Implicit)", color=red, style=dashed]
9494
3 -> 10 [ label="Normal"]
9595
9 -> 10 [ label="Normal"]
9696
}

crates/oxc_semantic/tests/integration/snapshots/labelled_try_break.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ unreachable" shape = box]
9595
4 -> 7 [ label="Normal"]
9696
8 -> 2 [ label="Error(Implicit)", style=dashed, color=red]
9797
7 -> 8 [ label="Unreachable", style="dotted"]
98-
9 -> 2 [ label="Error(Implicit)", style=dashed, color=red]
9998
3 -> 5 [ label="Normal"]
99+
9 -> 2 [ label="Error(Implicit)", style=dashed, color=red]
100100
8 -> 9 [ label="Unreachable", style="dotted"]
101101
10 -> 2 [ label="Error(Implicit)", color=red, style=dashed]
102102
9 -> 10 [ label="Normal", style="dotted"]

0 commit comments

Comments
 (0)