feat(semantic): introduce symbol_declarations method (#19609)

This is used upstream

It just allows for nicer code rather than having to do:
```rs
       for symbol_id in ctx.scoping().symbol_ids() {
           let declaration = ctx.scoping().symbol_declaration(symbol_id);
           let decl_node = ctx.nodes().get_node(declaration);
           let redeclarations = ctx.scoping().symbol_redeclarations(symbol_id);
           let mut component_info = None;

           if redeclarations.is_empty() {
               let declaration = ctx.scoping().symbol_declaration(symbol_id);
               let decl_node = ctx.nodes().get_node(declaration);
               component_info = is_react_component_node(
                   decl_node,
                   ctx,
                   &mut version_cache,
                   ignore_transpiler_name,
                   check_context_objects,
               );
           } else {
               for redeclaration in redeclarations {
                   let decl_node = ctx.nodes().get_node(redeclaration.declaration);
                   component_info = is_react_component_node(
                       decl_node,
                       ctx,
                       &mut version_cache,
                       ignore_transpiler_name,
                       check_context_objects,
                   );
                   if component_info.is_some() {
                       break;
                   }
               }
           }
```
This commit is contained in:
camc314 committed 2026-02-25 12:03:10 +00:00
1 parent 694be7d211
commit 5937a32ff1
1 file changed
+13
+13
View File
@@ -405,6 +405,19 @@ impl Scoping {
*self.symbol_table.symbol_declarations(symbol_id)
}
/// Get all declaration node IDs for a symbol.
///
/// Most symbols have a single declaration, but TypeScript allows merged type/value
/// declarations (e.g. `interface Foo {}` + `const Foo = ...`).
/// This iterator yields all declaration nodes in those cases.
#[inline]
pub fn symbol_declarations(&self, symbol_id: SymbolId) -> impl Iterator<Item = NodeId> + '_ {
let redeclarations = self.symbol_redeclarations(symbol_id);
std::iter::once(self.symbol_declaration(symbol_id))
.filter(move |_| redeclarations.is_empty())
.chain(redeclarations.iter().map(|redeclaration| redeclaration.declaration))
}
/// Create a new symbol and append symbol metadata to the symbol table.
pub fn create_symbol(
&mut self,