semantic!: Remove SymbolTable::get_symbol_id_from_name
and SymbolTable::get_scope_id_from_name
#5456
Labels
A-semantic
Area - Semantic
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 theSymbolId
for a reference, but actually that's not what it's doing - it will give you theSymbolId
of the first binding with this variable name anywhere in the AST.They are not the same. e.g. in this case:
If we want to know if
foo
inlet 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
eslint/radix
rule correctly check for unbound symbols #5446 removes a usage and adds tests which demonstrate it was incorrect.tree_shaking/no_side_effects_in_initialization
handle JSX correctly #5450 removed another one.tree_shaking/no_side_effects_in_initialization
linter rule, and I believe it's incorrect there too (Incorrect symbol resolution intree_shaking/no_side_effects_in_initialization
? #5455).get_scope_id_from_name
This method is not used anywhere in Oxc.
The text was updated successfully, but these errors were encountered: