mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(transformer): VarDeclarations common transform: check if at top level with ctx.parent() (#6231)
Micro-optimization. The stack of ancestors is now a `NonEmptyStack`, so `ctx.parent()` is now cheaper than `ctx.ancestors_depth()`.
This commit is contained in:
parent
a949ecb052
commit
0400ff9ea5
1 changed files with 3 additions and 4 deletions
|
|
@ -19,7 +19,7 @@ use oxc_ast::{ast::*, NONE};
|
|||
use oxc_data_structures::stack::SparseStack;
|
||||
use oxc_span::SPAN;
|
||||
use oxc_syntax::symbol::SymbolId;
|
||||
use oxc_traverse::{Traverse, TraverseCtx};
|
||||
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
|
||||
|
||||
use crate::TransformCtx;
|
||||
|
||||
|
|
@ -59,9 +59,8 @@ impl<'a, 'ctx> Traverse<'a> for VarDeclarations<'a, 'ctx> {
|
|||
}
|
||||
|
||||
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||
if ctx.ancestors_depth() == 2 {
|
||||
// Top level. Handle in `exit_program` instead.
|
||||
// (depth 1 = None, depth 2 = Program)
|
||||
if matches!(ctx.parent(), Ancestor::ProgramBody(_)) {
|
||||
// Handle in `exit_program` instead
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue