Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion crates/oxc_traverse/src/context/mod.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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<Statement>,
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.
Expand Down
Loading