Skip to content

Commit 7e888d2

Browse files
committed
fix(cfg): append switch case condition to correct block (#14810)
When a switch case test contains a logical expression (|| or &&), visiting the expression creates multiple CFG blocks for short-circuit evaluation and changes current_node_ix. The condition instruction must be appended to the block BEFORE visiting the expression, not after. This matches the pattern used in visit_if_statement and ensures the condition instruction is placed in the case entry block, making it discoverable by code that identifies case test blocks. Before: ```rust self.visit_expression(expr); // moves current_node_ix cfg.append_condition_to(cfg.current_node_ix, ...); // wrong block After: let condition_block_ix = cfg.current_node_ix; // save before self.visit_expression(expr); cfg.append_condition_to(condition_block_ix, ...); // correct block
1 parent aec04f2 commit 7e888d2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/oxc_semantic/src/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,12 +1481,14 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
14811481
self.enter_node(kind);
14821482

14831483
if let Some(expr) = &case.test {
1484+
#[cfg(feature = "cfg")]
1485+
let condition_block_ix = control_flow!(self, |cfg| cfg.current_node_ix);
14841486
#[cfg(feature = "cfg")]
14851487
self.record_ast_nodes();
14861488
self.visit_expression(expr);
14871489
#[cfg(feature = "cfg")]
14881490
let test_node_id = self.retrieve_recorded_ast_node();
1489-
control_flow!(self, |cfg| cfg.append_condition_to(cfg.current_node_ix, test_node_id));
1491+
control_flow!(self, |cfg| cfg.append_condition_to(condition_block_ix, test_node_id));
14901492
}
14911493

14921494
/* cfg */

0 commit comments

Comments
 (0)