Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(transformer): rename VarDeclarationsStore methods #6184

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
11 changes: 8 additions & 3 deletions crates/oxc_transformer/src/common/var_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<'a> VarDeclarationsStore<'a> {
impl<'a> VarDeclarationsStore<'a> {
/// Add a `VariableDeclarator` to be inserted at top of current enclosing statement block,
/// given `name` and `symbol_id`.
pub fn insert_declarator(
pub fn insert(
&self,
name: Atom<'a>,
symbol_id: SymbolId,
Expand All @@ -92,19 +92,24 @@ impl<'a> VarDeclarationsStore<'a> {
let ident = BindingIdentifier::new_with_symbol_id(SPAN, name, symbol_id);
let ident = ctx.ast.binding_pattern_kind_from_binding_identifier(ident);
let ident = ctx.ast.binding_pattern(ident, NONE, false);
self.insert_declarator_binding_pattern(ident, init, ctx);
self.insert_binding_pattern(ident, init, ctx);
}

/// Add a `VariableDeclarator` to be inserted at top of current enclosing statement block,
/// given a `BindingPattern`.
pub fn insert_declarator_binding_pattern(
pub fn insert_binding_pattern(
&self,
ident: BindingPattern<'a>,
init: Option<Expression<'a>>,
ctx: &mut TraverseCtx<'a>,
) {
let declarator =
ctx.ast.variable_declarator(SPAN, VariableDeclarationKind::Var, ident, init, false);
self.insert_declarator(declarator, ctx);
}

/// 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>) {
let mut declarators = self.declarators.borrow_mut();
declarators.last_mut_or_init(|| ctx.ast.vec()).push(declarator);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<'a, 'ctx> ExponentiationOperator<'a, 'ctx> {
let symbol_name = ctx.ast.atom(ctx.symbols().get_name(symbol_id));

// var _name;
self.ctx.var_declarations.insert_declarator(symbol_name.clone(), symbol_id, None, ctx);
self.ctx.var_declarations.insert(symbol_name.clone(), symbol_id, None, ctx);

let ident =
ctx.create_reference_id(SPAN, symbol_name, Some(symbol_id), ReferenceFlags::Read);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl<'a, 'ctx> Traverse<'a> for NullishCoalescingOperator<'a, 'ctx> {
// `(x) => x;` -> `((x) => x)();`
new_expr = ctx.ast.expression_call(SPAN, arrow_function, NONE, ctx.ast.vec(), false);
} else {
self.ctx.var_declarations.insert_declarator_binding_pattern(id, None, ctx);
self.ctx.var_declarations.insert_binding_pattern(id, None, ctx);
}

*expr = new_expr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl<'a, 'ctx> LogicalAssignmentOperators<'a, 'ctx> {
let symbol_name = ctx.ast.atom(ctx.symbols().get_name(symbol_id));

// var _name;
self.ctx.var_declarations.insert_declarator(symbol_name.clone(), symbol_id, None, ctx);
self.ctx.var_declarations.insert(symbol_name.clone(), symbol_id, None, ctx);

// _name = name
Some(ctx.create_reference_id(SPAN, symbol_name, Some(symbol_id), ReferenceFlags::Write))
Expand Down