From e510c7b93cae92b8dd6941ab0030511c97e7bf79 Mon Sep 17 00:00:00 2001 From: Boshen Date: Thu, 19 Dec 2024 11:52:27 +0800 Subject: [PATCH] u --- Cargo.lock | 1 - crates/oxc_semantic/src/builder.rs | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b32c9a4b2a44..75f0e99d3aa05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1914,7 +1914,6 @@ name = "oxc_semantic" version = "0.42.0" dependencies = [ "assert-unchecked", - "indexmap", "insta", "itertools", "oxc_allocator", diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index f8feba9dbd82b..34ef916d5a738 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -481,12 +481,10 @@ impl<'a> SemanticBuilder<'a> { fn resolve_references_for_current_scope(&mut self) { let (current_refs, parent_refs) = self.unresolved_references.current_and_parent_mut(); - for (name, mut references) in current_refs.drain() { - // Try to resolve a reference. - // If unresolved, transfer it to parent scope's unresolved references. - let bindings = self.scope.get_bindings(self.current_scope_id); - if let Some((_, symbol_id)) = bindings.iter().find(|(n, _)| n.as_str() == name.as_str()) - { + let bindings = self.scope.get_bindings(self.current_scope_id); + + for (binding_name, symbol_id) in bindings { + if let Some((name, mut references)) = current_refs.remove_entry(binding_name.as_str()) { let symbol_id = *symbol_id; let symbol_flags = self.symbols.get_flags(symbol_id); references.retain(|&reference_id| { @@ -530,8 +528,16 @@ impl<'a> SemanticBuilder<'a> { if references.is_empty() { continue; } + + if let Some(parent_reference_ids) = parent_refs.get_mut(&name) { + parent_reference_ids.extend(references); + } else { + parent_refs.insert(name, references); + } } + } + for (name, references) in current_refs.drain() { if let Some(parent_reference_ids) = parent_refs.get_mut(&name) { parent_reference_ids.extend(references); } else {