From 1f0673ce131ac6646d863320ab6ab8226f81e7b9 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Sat, 14 Dec 2024 01:04:36 +0000 Subject: [PATCH] refactor(semantic): `SymbolTable::set_name` return old name --- crates/oxc_semantic/src/symbol.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/oxc_semantic/src/symbol.rs b/crates/oxc_semantic/src/symbol.rs index 42fda763edf2ae..0e5274a1b87b87 100644 --- a/crates/oxc_semantic/src/symbol.rs +++ b/crates/oxc_semantic/src/symbol.rs @@ -1,3 +1,5 @@ +use std::mem; + #[cfg(feature = "serialize")] use serde::Serialize; #[cfg(feature = "serialize")] @@ -101,9 +103,11 @@ impl SymbolTable { } /// Rename a symbol. + /// + /// Returns the old name. #[inline] - pub fn set_name(&mut self, symbol_id: SymbolId, name: CompactStr) { - self.names[symbol_id] = name; + pub fn set_name(&mut self, symbol_id: SymbolId, name: CompactStr) -> CompactStr { + mem::replace(&mut self.names[symbol_id], name) } /// Get the [`SymbolFlags`] for a symbol, which describe how the symbol is declared.