-
-
Notifications
You must be signed in to change notification settings - Fork 930
Description
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
- fix(linter):
eslint/radixrule correctly check for unbound symbols #5446 removes a usage and adds tests which demonstrate it was incorrect. - fix(linter):
tree_shaking/no_side_effects_in_initializationhandle JSX correctly #5450 removed another one. - The only remaining usage of is in the
tree_shaking/no_side_effects_in_initializationlinter 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.
Metadata
Metadata
Assignees
Labels
Type
Fields
Give feedbackPriority