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(traverse): TraverseCtx::generate_binding take an Atom #6830

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
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/typescript/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a> TypeScriptEnum<'a> {
let enum_name = decl.id.name.clone();
let func_scope_id = decl.scope_id.get().unwrap();
let param_ident = ctx.generate_binding(
enum_name.to_compact_str(),
enum_name.clone(),
func_scope_id,
SymbolFlags::FunctionScopedVariable,
);
Expand Down
28 changes: 20 additions & 8 deletions crates/oxc_traverse/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,31 @@ impl<'a> TraverseCtx<'a> {
/// Creates a symbol with the provided name and flags and adds it to the specified scope.
pub fn generate_binding(
&mut self,
name: CompactStr,
name: Atom<'a>,
scope_id: ScopeId,
flags: SymbolFlags,
) -> BoundIdentifier<'a> {
let name_atom = self.ast.atom(&name);
let owned_name = name.to_compact_str();

// Add binding to scope
let symbol_id =
self.symbols_mut().create_symbol(SPAN, name.clone(), flags, scope_id, NodeId::DUMMY);
self.scopes_mut().add_binding(scope_id, name, symbol_id);
let symbol_id = self.symbols_mut().create_symbol(
SPAN,
owned_name.clone(),
flags,
scope_id,
NodeId::DUMMY,
);
self.scopes_mut().add_binding(scope_id, owned_name, symbol_id);

BoundIdentifier::new(name_atom, symbol_id)
BoundIdentifier::new(name, symbol_id)
}

/// Generate binding in current scope.
///
/// Creates a symbol with the provided name and flags and adds it to the current scope.
pub fn generate_in_current_scope(
&mut self,
name: CompactStr,
name: Atom<'a>,
flags: SymbolFlags,
) -> BoundIdentifier<'a> {
self.generate_binding(name, self.current_scope_id(), flags)
Expand Down Expand Up @@ -356,7 +361,14 @@ impl<'a> TraverseCtx<'a> {
) -> BoundIdentifier<'a> {
// Get name for UID
let name = self.generate_uid_name(name);
self.generate_binding(name, scope_id, flags)
let name_atom = self.ast.atom(&name);

// Add binding to scope
let symbol_id =
self.symbols_mut().create_symbol(SPAN, name.clone(), flags, scope_id, NodeId::DUMMY);
self.scopes_mut().add_binding(scope_id, name, symbol_id);

BoundIdentifier::new(name_atom, symbol_id)
}

/// Generate UID in current scope.
Expand Down
Loading