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;
}
let Some(symbol_id) =
ctx.semantic().symbols().get_symbol_id_from_span(entry.local_name.span())
let Some(symbol_id) = ctx.scopes().get_root_binding(entry.local_name.name().as_str())
else {
return;
};

View file

@ -88,12 +88,20 @@ impl Rule for NoNamedAsDefaultMember {
continue;
};
if !remote_module_record_ref.exported_bindings.is_empty() {
has_members_map.insert(
ctx.symbols().get_symbol_id_from_span(import_entry.local_name.span()).unwrap(),
(remote_module_record_ref, import_entry.module_request.name().clone()),
);
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(
symbol_id,
(remote_module_record_ref, import_entry.module_request.name().clone()),
);
}
if has_members_map.is_empty() {

View file

@ -88,12 +88,6 @@ impl SymbolTable {
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.
///
/// [`AstNode`]: crate::node::AstNode
@ -152,10 +146,6 @@ impl SymbolTable {
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.
///
/// This node will be a [`VariableDeclaration`], [`Function`], or some other AST node