Skip to content

Commit

Permalink
refactor(semantic)!: remove SymbolTable::get_symbol_id_from_span API (
Browse files Browse the repository at this point in the history
#6955)

closes #6867
  • Loading branch information
Boshen committed Oct 27, 2024
1 parent c4c0865 commit 9a6a2f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
3 changes: 1 addition & 2 deletions crates/oxc_linter/src/rules/import/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
18 changes: 13 additions & 5 deletions crates/oxc_linter/src/rules/import/no_named_as_default_member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 0 additions & 10 deletions crates/oxc_semantic/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a6a2f9

Please sign in to comment.