diff --git a/crates/oxc_minifier/src/peephole/minimize_if_statement.rs b/crates/oxc_minifier/src/peephole/minimize_if_statement.rs index de6967c3569ba..0341d88b5c576 100644 --- a/crates/oxc_minifier/src/peephole/minimize_if_statement.rs +++ b/crates/oxc_minifier/src/peephole/minimize_if_statement.rs @@ -1,7 +1,7 @@ use oxc_allocator::TakeIn; use oxc_ast::ast::*; -use oxc_semantic::ScopeId; +use oxc_semantic::ScopeFlags; use oxc_span::GetSpan; use crate::ctx::Ctx; @@ -124,11 +124,10 @@ impl<'a> PeepholeOptimizations { /// Wrap to avoid ambiguous else. /// `if (foo) if (bar) baz else quaz` -> `if (foo) { if (bar) baz else quaz }` - #[expect(clippy::cast_possible_truncation)] fn wrap_to_avoid_ambiguous_else(if_stmt: &mut IfStatement<'a>, ctx: &mut Ctx<'a, '_>) { if let Statement::IfStatement(if2) = &mut if_stmt.consequent { if if2.consequent.is_jump_statement() && if2.alternate.is_some() { - let scope_id = ScopeId::new(ctx.scoping.scoping().scopes_len() as u32); + let scope_id = ctx.create_child_scope_of_current(ScopeFlags::empty()); if_stmt.consequent = Statement::BlockStatement(ctx.ast.alloc( ctx.ast.block_statement_with_scope_id( if_stmt.consequent.span(), diff --git a/crates/oxc_minifier/src/peephole/minimize_statements.rs b/crates/oxc_minifier/src/peephole/minimize_statements.rs index 9f0b40a691ac1..c490bddf08f5b 100644 --- a/crates/oxc_minifier/src/peephole/minimize_statements.rs +++ b/crates/oxc_minifier/src/peephole/minimize_statements.rs @@ -7,7 +7,7 @@ use oxc_ecmascript::{ constant_evaluation::{DetermineValueType, IsLiteralValue, ValueType}, side_effects::MayHaveSideEffects, }; -use oxc_semantic::ScopeId; +use oxc_semantic::ScopeFlags; use oxc_span::{ContentEq, GetSpan}; use oxc_traverse::Ancestor; @@ -572,7 +572,6 @@ impl<'a> PeepholeOptimizations { result.push(Statement::SwitchStatement(switch_stmt)); } - #[expect(clippy::cast_possible_truncation)] fn handle_if_statement( i: usize, stmts: &mut Vec<'a, Statement<'a>>, @@ -691,7 +690,7 @@ impl<'a> PeepholeOptimizations { let consequent = if body.len() == 1 { body.remove(0) } else { - let scope_id = ScopeId::new(ctx.scoping().scopes_len() as u32); + let scope_id = ctx.create_child_scope_of_current(ScopeFlags::empty()); let block_stmt = ctx.ast.block_statement_with_scope_id(span, body, scope_id); Statement::BlockStatement(ctx.ast.alloc(block_stmt))