Skip to content

Commit aeaa27a

Browse files
committed
refactor(ast, parser, transformer, traverse)!: remove BindingIdentifier::new methods (#6786)
1 parent ecc9151 commit aeaa27a

File tree

9 files changed

+16
-26
lines changed

9 files changed

+16
-26
lines changed

crates/oxc_ast/src/ast_impl/js.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,6 @@ impl<'a> fmt::Display for IdentifierReference<'a> {
320320
}
321321
}
322322

323-
impl<'a> BindingIdentifier<'a> {
324-
#[allow(missing_docs)]
325-
pub fn new(span: Span, name: Atom<'a>) -> Self {
326-
Self { span, name, symbol_id: Cell::default() }
327-
}
328-
329-
#[allow(missing_docs)]
330-
pub fn new_with_symbol_id(span: Span, name: Atom<'a>, symbol_id: SymbolId) -> Self {
331-
Self { span, name, symbol_id: Cell::new(Some(symbol_id)) }
332-
}
333-
}
334-
335323
impl<'a> fmt::Display for BindingIdentifier<'a> {
336324
#[inline]
337325
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/oxc_parser/src/js/arrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ impl<'a> ParserImpl<'a> {
211211
let params = {
212212
let ident = match ident {
213213
Expression::Identifier(ident) => {
214-
let name = ident.name.clone();
215-
BindingIdentifier::new(ident.span, name)
214+
let ident = ident.unbox();
215+
self.ast.binding_identifier(ident.span, ident.name)
216216
}
217217
_ => unreachable!(),
218218
};

crates/oxc_transformer/src/common/module_imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ impl<'a> ModuleImportsStore<'a> {
202202
ModuleExportName::IdentifierName(
203203
ctx.ast.identifier_name(SPAN, import.imported),
204204
),
205-
import.local.create_binding_identifier(),
205+
import.local.create_binding_identifier(ctx),
206206
ImportOrExportKind::Value,
207207
))
208208
}
209209
Import::Default(local) => ImportDeclarationSpecifier::ImportDefaultSpecifier(
210-
ctx.ast.alloc_import_default_specifier(SPAN, local.create_binding_identifier()),
210+
ctx.ast.alloc_import_default_specifier(SPAN, local.create_binding_identifier(ctx)),
211211
),
212212
}));
213213

crates/oxc_transformer/src/common/var_declarations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a> VarDeclarationsStore<'a> {
7474
init: Option<Expression<'a>>,
7575
ctx: &mut TraverseCtx<'a>,
7676
) {
77-
let ident = binding.create_binding_identifier();
77+
let ident = binding.create_binding_identifier(ctx);
7878
let ident = ctx.ast.binding_pattern_kind_from_binding_identifier(ident);
7979
let ident = ctx.ast.binding_pattern(ident, NONE, false);
8080
self.insert_binding_pattern(ident, init, ctx);

crates/oxc_transformer/src/es2015/arrow_functions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,9 @@ impl<'a> ArrowFunctions<'a> {
410410
ctx: &mut TraverseCtx<'a>,
411411
) {
412412
let binding_pattern = ctx.ast.binding_pattern(
413-
ctx.ast
414-
.binding_pattern_kind_from_binding_identifier(this_var.create_binding_identifier()),
413+
ctx.ast.binding_pattern_kind_from_binding_identifier(
414+
this_var.create_binding_identifier(ctx),
415+
),
415416
NONE,
416417
false,
417418
);

crates/oxc_transformer/src/react/jsx_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'ctx> ReactJsxSource<'a, 'ctx> {
207207

208208
let var_kind = VariableDeclarationKind::Var;
209209
let id = {
210-
let ident = filename_var.create_binding_identifier();
210+
let ident = filename_var.create_binding_identifier(ctx);
211211
let ident = ctx.ast.binding_pattern_kind_from_binding_identifier(ident);
212212
ctx.ast.binding_pattern(ident, NONE, false)
213213
};

crates/oxc_transformer/src/react/refresh.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ impl<'a, 'ctx> Traverse<'a> for ReactRefresh<'a, 'ctx> {
156156
let mut new_statements = ctx.ast.vec_with_capacity(self.registrations.len() + 1);
157157
for (symbol_id, persistent_id) in self.registrations.drain(..) {
158158
let name = ctx.ast.atom(ctx.symbols().get_name(symbol_id));
159-
let binding_identifier = BindingIdentifier::new_with_symbol_id(SPAN, name, symbol_id);
159+
let binding_identifier =
160+
ctx.ast.binding_identifier_with_symbol_id(SPAN, name, symbol_id);
160161
variable_declarator_items.push(
161162
ctx.ast.variable_declarator(
162163
SPAN,
@@ -683,7 +684,7 @@ impl<'a, 'ctx> ReactRefresh<'a, 'ctx> {
683684
.unwrap_or_else(|| ctx.current_scope_id());
684685

685686
let binding = ctx.generate_uid("s", target_scope_id, SymbolFlags::FunctionScopedVariable);
686-
let binding_identifier = binding.create_binding_identifier();
687+
let binding_identifier = binding.create_binding_identifier(ctx);
687688

688689
// _s();
689690
let call_expression = ctx.ast.statement_expression(

crates/oxc_transformer/src/typescript/enum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a> TypeScriptEnum<'a> {
8686
);
8787
ctx.scopes_mut().add_binding(func_scope_id, enum_name.to_compact_str(), param_symbol_id);
8888

89-
let ident = BindingIdentifier::new_with_symbol_id(
89+
let ident = ctx.ast.binding_identifier_with_symbol_id(
9090
decl.id.span,
9191
decl.id.name.clone(),
9292
param_symbol_id,

crates/oxc_traverse/src/context/bound_identifier.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ impl<'a> BoundIdentifier<'a> {
4747
}
4848

4949
/// Create `BindingIdentifier` for this binding
50-
pub fn create_binding_identifier(&self) -> BindingIdentifier<'a> {
51-
BindingIdentifier::new_with_symbol_id(SPAN, self.name.clone(), self.symbol_id)
50+
pub fn create_binding_identifier(&self, ctx: &mut TraverseCtx<'a>) -> BindingIdentifier<'a> {
51+
ctx.ast.binding_identifier_with_symbol_id(SPAN, self.name.clone(), self.symbol_id)
5252
}
5353

5454
/// Create `BindingPattern` for this binding
5555
pub fn create_binding_pattern(&self, ctx: &mut TraverseCtx<'a>) -> BindingPattern<'a> {
56-
let ident = self.create_binding_identifier();
56+
let ident = self.create_binding_identifier(ctx);
5757
let binding_pattern_kind = ctx.ast.binding_pattern_kind_from_binding_identifier(ident);
5858
ctx.ast.binding_pattern(binding_pattern_kind, NONE, false)
5959
}

0 commit comments

Comments
 (0)