refactor(semantic)!: remove SymbolTable::get_symbol_id_from_span API (#6955)

closes #6867
This commit is contained in:
Boshen 2024-10-27 14:31:36 +00:00
parent c4c0865cb3
commit 9a6a2f99c6
3 changed files with 14 additions and 17 deletions

View file

@ -152,8 +152,7 @@ impl Rule for Namespace {
return; return;
} }
let Some(symbol_id) = let Some(symbol_id) = ctx.scopes().get_root_binding(entry.local_name.name().as_str())
ctx.semantic().symbols().get_symbol_id_from_span(entry.local_name.span())
else { else {
return; return;
}; };

View file

@ -88,13 +88,21 @@ impl Rule for NoNamedAsDefaultMember {
continue; continue;
}; };
if !remote_module_record_ref.exported_bindings.is_empty() { if remote_module_record_ref.exported_bindings.is_empty() {
continue;
}
let Some(symbol_id) =
ctx.scopes().get_root_binding(import_entry.local_name.name().as_str())
else {
return;
};
has_members_map.insert( has_members_map.insert(
ctx.symbols().get_symbol_id_from_span(import_entry.local_name.span()).unwrap(), symbol_id,
(remote_module_record_ref, import_entry.module_request.name().clone()), (remote_module_record_ref, import_entry.module_request.name().clone()),
); );
} }
}
if has_members_map.is_empty() { if has_members_map.is_empty() {
return; return;

View file

@ -88,12 +88,6 @@ impl SymbolTable {
self.spans.iter_enumerated().map(|(symbol_id, _)| symbol_id) self.spans.iter_enumerated().map(|(symbol_id, _)| symbol_id)
} }
pub fn get_symbol_id_from_span(&self, span: Span) -> Option<SymbolId> {
self.spans
.iter_enumerated()
.find_map(|(symbol, &inner_span)| if inner_span == span { Some(symbol) } else { None })
}
/// Get the [`Span`] of the [`AstNode`] declaring a symbol. /// Get the [`Span`] of the [`AstNode`] declaring a symbol.
/// ///
/// [`AstNode`]: crate::node::AstNode /// [`AstNode`]: crate::node::AstNode
@ -152,10 +146,6 @@ impl SymbolTable {
self.scope_ids[symbol_id] self.scope_ids[symbol_id]
} }
pub fn get_scope_id_from_span(&self, span: Span) -> Option<ScopeId> {
self.get_symbol_id_from_span(span).map(|symbol_id| self.get_scope_id(symbol_id))
}
/// Get the ID of the AST node declaring a symbol. /// Get the ID of the AST node declaring a symbol.
/// ///
/// This node will be a [`VariableDeclaration`], [`Function`], or some other AST node /// This node will be a [`VariableDeclaration`], [`Function`], or some other AST node