diff --git a/crates/oxc_transformer/src/proposals/explicit_resource_management.rs b/crates/oxc_transformer/src/proposals/explicit_resource_management.rs index 34b587a729257..ed08e025ccd7c 100644 --- a/crates/oxc_transformer/src/proposals/explicit_resource_management.rs +++ b/crates/oxc_transformer/src/proposals/explicit_resource_management.rs @@ -418,8 +418,7 @@ impl<'a> Traverse<'a> for ExplicitResourceManagement<'a, '_> { }, ); - let block_scope_id = - ctx.scoping.insert_scope_below_statements(&inner_block, ScopeFlags::empty()); + let block_scope_id = ctx.insert_scope_below_statements(&inner_block, ScopeFlags::empty()); program_body.push(ctx.ast.statement_block_with_scope_id(SPAN, inner_block, block_scope_id)); std::mem::swap(&mut program.body, &mut program_body); diff --git a/crates/oxc_traverse/src/context/mod.rs b/crates/oxc_traverse/src/context/mod.rs index d977f29907139..8dbe1f9744f17 100644 --- a/crates/oxc_traverse/src/context/mod.rs +++ b/crates/oxc_traverse/src/context/mod.rs @@ -1,4 +1,4 @@ -use oxc_allocator::{Allocator, Box}; +use oxc_allocator::{Allocator, Box, Vec as ArenaVec}; use oxc_ast::{ AstBuilder, ast::{Expression, IdentifierReference, Statement}, @@ -279,6 +279,23 @@ impl<'a> TraverseCtx<'a> { self.scoping.insert_scope_below_expression(expr, flags) } + /// Insert a scope into scope tree below a `Vec` of statements. + /// + /// Statements must be in current scope. + /// New scope is created as child of current scope. + /// All child scopes of the statement are reassigned to be children of the new scope. + /// + /// `flags` provided are amended to inherit from parent scope's flags. + /// + /// This is a shortcut for `ctx.scoping.insert_scope_below_statements`. + pub fn insert_scope_below_statements( + &mut self, + stmts: &ArenaVec, + flags: ScopeFlags, + ) -> ScopeId { + self.scoping.insert_scope_below_statements(stmts, flags) + } + /// Remove scope for an expression from the scope chain. /// /// Delete the scope and set parent of its child scopes to its parent scope.