Skip to content

semantic!: Remove SymbolTable::get_symbol_id_from_name and SymbolTable::get_scope_id_from_name #5456

@overlookmotel

Description

@overlookmotel

These methods are in my opinion a footgun because they don't do what you might think they do. Worse still, minimal test cases often won't reveal that.

We use get_symbol_id_from_name to get the SymbolId for a reference, but actually that's not what it's doing - it will give you the SymbolId of the first binding with this variable name anywhere in the AST.

They are not the same. e.g. in this case:

{
    let foo;
}
let bar = foo;

If we want to know if foo in let bar = foo; refers to a local variable, get_symbol_id_from_name("foo").is_some() says "yes it does". But that's wrong.

Instead we should use symbol_table.is_global_reference(ident.reference_id().unwrap()).

As well as being correct, this is also much more performant, as it doesn't iterate through every single symbol in the entire AST the way get_symbol_id_from_name does.

Current API usage

get_symbol_id_from_name

get_scope_id_from_name

This method is not used anywhere in Oxc.

Metadata

Metadata

Assignees

Labels

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions