mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(transformer): rename var in VarDeclarations common transform (#6242)
Pure refactor. Just rename a variable for clarity.
This commit is contained in:
parent
585ccdad8c
commit
1c31932f03
1 changed files with 11 additions and 11 deletions
|
|
@ -44,9 +44,9 @@ impl<'a, 'ctx> Traverse<'a> for VarDeclarations<'a, 'ctx> {
|
||||||
self.ctx.top_level_statements.insert_statement(stmt);
|
self.ctx.top_level_statements.insert_statement(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
let declarators = self.ctx.var_declarations.declarators.borrow();
|
let stack = self.ctx.var_declarations.stack.borrow();
|
||||||
debug_assert!(declarators.len() == 1);
|
debug_assert!(stack.len() == 1);
|
||||||
debug_assert!(declarators.last().is_none());
|
debug_assert!(stack.last().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_statements(
|
fn enter_statements(
|
||||||
|
|
@ -54,8 +54,8 @@ impl<'a, 'ctx> Traverse<'a> for VarDeclarations<'a, 'ctx> {
|
||||||
_stmts: &mut Vec<'a, Statement<'a>>,
|
_stmts: &mut Vec<'a, Statement<'a>>,
|
||||||
_ctx: &mut TraverseCtx<'a>,
|
_ctx: &mut TraverseCtx<'a>,
|
||||||
) {
|
) {
|
||||||
let mut declarators = self.ctx.var_declarations.declarators.borrow_mut();
|
let mut stack = self.ctx.var_declarations.stack.borrow_mut();
|
||||||
declarators.push(None);
|
stack.push(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
fn exit_statements(&mut self, stmts: &mut Vec<'a, Statement<'a>>, ctx: &mut TraverseCtx<'a>) {
|
||||||
|
|
@ -72,8 +72,8 @@ impl<'a, 'ctx> Traverse<'a> for VarDeclarations<'a, 'ctx> {
|
||||||
|
|
||||||
impl<'a, 'ctx> VarDeclarations<'a, 'ctx> {
|
impl<'a, 'ctx> VarDeclarations<'a, 'ctx> {
|
||||||
fn get_var_statement(&mut self, ctx: &mut TraverseCtx<'a>) -> Option<Statement<'a>> {
|
fn get_var_statement(&mut self, ctx: &mut TraverseCtx<'a>) -> Option<Statement<'a>> {
|
||||||
let mut declarators = self.ctx.var_declarations.declarators.borrow_mut();
|
let mut stack = self.ctx.var_declarations.stack.borrow_mut();
|
||||||
let declarators = declarators.pop()?;
|
let declarators = stack.pop()?;
|
||||||
debug_assert!(!declarators.is_empty());
|
debug_assert!(!declarators.is_empty());
|
||||||
|
|
||||||
let stmt = Statement::VariableDeclaration(ctx.ast.alloc_variable_declaration(
|
let stmt = Statement::VariableDeclaration(ctx.ast.alloc_variable_declaration(
|
||||||
|
|
@ -88,12 +88,12 @@ impl<'a, 'ctx> VarDeclarations<'a, 'ctx> {
|
||||||
|
|
||||||
/// Store for `VariableDeclarator`s to be added to enclosing statement block.
|
/// Store for `VariableDeclarator`s to be added to enclosing statement block.
|
||||||
pub struct VarDeclarationsStore<'a> {
|
pub struct VarDeclarationsStore<'a> {
|
||||||
declarators: RefCell<SparseStack<Vec<'a, VariableDeclarator<'a>>>>,
|
stack: RefCell<SparseStack<Vec<'a, VariableDeclarator<'a>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VarDeclarationsStore<'a> {
|
impl<'a> VarDeclarationsStore<'a> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { declarators: RefCell::new(SparseStack::new()) }
|
Self { stack: RefCell::new(SparseStack::new()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +128,7 @@ impl<'a> VarDeclarationsStore<'a> {
|
||||||
|
|
||||||
/// Add a `VariableDeclarator` to be inserted at top of current enclosing statement block.
|
/// Add a `VariableDeclarator` to be inserted at top of current enclosing statement block.
|
||||||
pub fn insert_declarator(&self, declarator: VariableDeclarator<'a>, ctx: &mut TraverseCtx<'a>) {
|
pub fn insert_declarator(&self, declarator: VariableDeclarator<'a>, ctx: &mut TraverseCtx<'a>) {
|
||||||
let mut declarators = self.declarators.borrow_mut();
|
let mut stack = self.stack.borrow_mut();
|
||||||
declarators.last_mut_or_init(|| ctx.ast.vec()).push(declarator);
|
stack.last_mut_or_init(|| ctx.ast.vec()).push(declarator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue