Skip to content
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
15 changes: 15 additions & 0 deletions crates/oxc_semantic/src/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,21 @@ impl Scoping {
});
}

/// Rename symbol.
///
/// The following must be true for successful operation:
/// * Binding exists in specified scope for `symbol_id`.
/// * No binding already exists in scope for `new_name`.
///
/// Panics in debug mode if either of the above are not satisfied.
pub fn rename_symbol(&mut self, symbol_id: SymbolId, scope_id: ScopeId, new_name: &str) {
// Rename symbol
// FIXME: remove `to_string`
let old_name = self.set_symbol_name(symbol_id, new_name).to_string();
// Rename binding
self.rename_binding(scope_id, symbol_id, &old_name, new_name);
}

pub fn delete_typescript_bindings(&mut self) {
self.cell.with_dependent_mut(|_allocator, cell| {
for bindings in &mut cell.bindings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ impl<'a> ArrowFunctionConverter<'a> {
/// Rename the `arguments` symbol to a new name.
fn rename_arguments_symbol(symbol_id: SymbolId, name: Atom<'a>, ctx: &mut TraverseCtx<'a>) {
let scope_id = ctx.scoping().symbol_scope_id(symbol_id);
ctx.rename_symbol(symbol_id, scope_id, name.as_str());
ctx.scoping_mut().rename_symbol(symbol_id, scope_id, name.as_str());
}

/// Transform the identifier reference for `arguments` if it's affected after transformation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl<'a> ClassProperties<'a, '_> {
// Save replacement name in `clashing_symbols`
*name = new_name;
// Rename symbol and binding
ctx.rename_symbol(symbol_id, constructor_scope_id, new_name.as_str());
ctx.scoping_mut().rename_symbol(symbol_id, constructor_scope_id, new_name.as_str());
}

// Rename identifiers for clashing symbols in constructor params and body
Expand Down
15 changes: 0 additions & 15 deletions crates/oxc_traverse/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,21 +640,6 @@ impl<'a> TraverseCtx<'a> {
pub fn delete_reference_for_identifier(&mut self, ident: &IdentifierReference) {
self.scoping.delete_reference_for_identifier(ident);
}

/// Rename symbol.
///
/// Preserves original order of bindings for scope.
///
/// The following must be true for successful operation:
/// * Binding exists in specified scope for `symbol_id`.
/// * No binding already exists in scope for `new_name`.
///
/// Panics in debug mode if either of the above are not satisfied.
///
/// This is a shortcut for `ctx.scoping.rename_symbol`.
pub fn rename_symbol(&mut self, symbol_id: SymbolId, scope_id: ScopeId, new_name: &str) {
self.scoping.rename_symbol(symbol_id, scope_id, new_name);
}
}

// Methods used internally within crate
Expand Down
15 changes: 0 additions & 15 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,21 +429,6 @@ impl<'a> TraverseScoping<'a> {
pub fn delete_reference_for_identifier(&mut self, ident: &IdentifierReference) {
self.delete_reference(ident.reference_id(), &ident.name);
}

/// Rename symbol.
///
/// The following must be true for successful operation:
/// * Binding exists in specified scope for `symbol_id`.
/// * No binding already exists in scope for `new_name`.
///
/// Panics in debug mode if either of the above are not satisfied.
pub fn rename_symbol(&mut self, symbol_id: SymbolId, scope_id: ScopeId, new_name: &str) {
// Rename symbol
// FIXME: remove `to_string`
let old_name = self.scoping.set_symbol_name(symbol_id, new_name).to_string();
// Rename binding
self.scoping.rename_binding(scope_id, symbol_id, &old_name, new_name);
}
}

// Methods used internally within crate
Expand Down
Loading