mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
refactor(ast, parser, transformer, traverse)!: remove BindingIdentifier::new methods (#6786)
This commit is contained in:
parent
ecc9151f99
commit
aeaa27a618
9 changed files with 16 additions and 26 deletions
|
|
@ -320,18 +320,6 @@ impl<'a> fmt::Display for IdentifierReference<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> BindingIdentifier<'a> {
|
||||
#[allow(missing_docs)]
|
||||
pub fn new(span: Span, name: Atom<'a>) -> Self {
|
||||
Self { span, name, symbol_id: Cell::default() }
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
pub fn new_with_symbol_id(span: Span, name: Atom<'a>, symbol_id: SymbolId) -> Self {
|
||||
Self { span, name, symbol_id: Cell::new(Some(symbol_id)) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for BindingIdentifier<'a> {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
|
|
|||
|
|
@ -211,8 +211,8 @@ impl<'a> ParserImpl<'a> {
|
|||
let params = {
|
||||
let ident = match ident {
|
||||
Expression::Identifier(ident) => {
|
||||
let name = ident.name.clone();
|
||||
BindingIdentifier::new(ident.span, name)
|
||||
let ident = ident.unbox();
|
||||
self.ast.binding_identifier(ident.span, ident.name)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -202,12 +202,12 @@ impl<'a> ModuleImportsStore<'a> {
|
|||
ModuleExportName::IdentifierName(
|
||||
ctx.ast.identifier_name(SPAN, import.imported),
|
||||
),
|
||||
import.local.create_binding_identifier(),
|
||||
import.local.create_binding_identifier(ctx),
|
||||
ImportOrExportKind::Value,
|
||||
))
|
||||
}
|
||||
Import::Default(local) => ImportDeclarationSpecifier::ImportDefaultSpecifier(
|
||||
ctx.ast.alloc_import_default_specifier(SPAN, local.create_binding_identifier()),
|
||||
ctx.ast.alloc_import_default_specifier(SPAN, local.create_binding_identifier(ctx)),
|
||||
),
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ impl<'a> VarDeclarationsStore<'a> {
|
|||
init: Option<Expression<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
let ident = binding.create_binding_identifier();
|
||||
let ident = binding.create_binding_identifier(ctx);
|
||||
let ident = ctx.ast.binding_pattern_kind_from_binding_identifier(ident);
|
||||
let ident = ctx.ast.binding_pattern(ident, NONE, false);
|
||||
self.insert_binding_pattern(ident, init, ctx);
|
||||
|
|
|
|||
|
|
@ -410,8 +410,9 @@ impl<'a> ArrowFunctions<'a> {
|
|||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
let binding_pattern = ctx.ast.binding_pattern(
|
||||
ctx.ast
|
||||
.binding_pattern_kind_from_binding_identifier(this_var.create_binding_identifier()),
|
||||
ctx.ast.binding_pattern_kind_from_binding_identifier(
|
||||
this_var.create_binding_identifier(ctx),
|
||||
),
|
||||
NONE,
|
||||
false,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ impl<'a, 'ctx> ReactJsxSource<'a, 'ctx> {
|
|||
|
||||
let var_kind = VariableDeclarationKind::Var;
|
||||
let id = {
|
||||
let ident = filename_var.create_binding_identifier();
|
||||
let ident = filename_var.create_binding_identifier(ctx);
|
||||
let ident = ctx.ast.binding_pattern_kind_from_binding_identifier(ident);
|
||||
ctx.ast.binding_pattern(ident, NONE, false)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -156,7 +156,8 @@ impl<'a, 'ctx> Traverse<'a> for ReactRefresh<'a, 'ctx> {
|
|||
let mut new_statements = ctx.ast.vec_with_capacity(self.registrations.len() + 1);
|
||||
for (symbol_id, persistent_id) in self.registrations.drain(..) {
|
||||
let name = ctx.ast.atom(ctx.symbols().get_name(symbol_id));
|
||||
let binding_identifier = BindingIdentifier::new_with_symbol_id(SPAN, name, symbol_id);
|
||||
let binding_identifier =
|
||||
ctx.ast.binding_identifier_with_symbol_id(SPAN, name, symbol_id);
|
||||
variable_declarator_items.push(
|
||||
ctx.ast.variable_declarator(
|
||||
SPAN,
|
||||
|
|
@ -683,7 +684,7 @@ impl<'a, 'ctx> ReactRefresh<'a, 'ctx> {
|
|||
.unwrap_or_else(|| ctx.current_scope_id());
|
||||
|
||||
let binding = ctx.generate_uid("s", target_scope_id, SymbolFlags::FunctionScopedVariable);
|
||||
let binding_identifier = binding.create_binding_identifier();
|
||||
let binding_identifier = binding.create_binding_identifier(ctx);
|
||||
|
||||
// _s();
|
||||
let call_expression = ctx.ast.statement_expression(
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ impl<'a> TypeScriptEnum<'a> {
|
|||
);
|
||||
ctx.scopes_mut().add_binding(func_scope_id, enum_name.to_compact_str(), param_symbol_id);
|
||||
|
||||
let ident = BindingIdentifier::new_with_symbol_id(
|
||||
let ident = ctx.ast.binding_identifier_with_symbol_id(
|
||||
decl.id.span,
|
||||
decl.id.name.clone(),
|
||||
param_symbol_id,
|
||||
|
|
|
|||
|
|
@ -47,13 +47,13 @@ impl<'a> BoundIdentifier<'a> {
|
|||
}
|
||||
|
||||
/// Create `BindingIdentifier` for this binding
|
||||
pub fn create_binding_identifier(&self) -> BindingIdentifier<'a> {
|
||||
BindingIdentifier::new_with_symbol_id(SPAN, self.name.clone(), self.symbol_id)
|
||||
pub fn create_binding_identifier(&self, ctx: &mut TraverseCtx<'a>) -> BindingIdentifier<'a> {
|
||||
ctx.ast.binding_identifier_with_symbol_id(SPAN, self.name.clone(), self.symbol_id)
|
||||
}
|
||||
|
||||
/// Create `BindingPattern` for this binding
|
||||
pub fn create_binding_pattern(&self, ctx: &mut TraverseCtx<'a>) -> BindingPattern<'a> {
|
||||
let ident = self.create_binding_identifier();
|
||||
let ident = self.create_binding_identifier(ctx);
|
||||
let binding_pattern_kind = ctx.ast.binding_pattern_kind_from_binding_identifier(ident);
|
||||
ctx.ast.binding_pattern(binding_pattern_kind, NONE, false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue