Incorrect symbol resolution in tree_shaking/no_side_effects_in_initialization
?
#5455
Labels
tree_shaking/no_side_effects_in_initialization
?
#5455
I am fairly sure that symbol resolution in this rule is not correct for
ExportSpecifier
:oxc/crates/oxc_linter/src/rules/tree_shaking/no_side_effects_in_initialization/listener_map.rs
Lines 193 to 202 in 1d3e973
Background
I would like to remove the method
SymbolTable::get_symbol_id_from_name
, as in my opinion it's a footgun (#5456). We use it 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.#5446 removes a usage of
get_symbol_id_from_name
and adds tests which demonstrate it was incorrect.This rule
I'm pretty sure the usage of
get_symbol_id_from_name
in this rule is wrong too. Isn't the question we should be asking in this code "is thelocal
a bound identifier?", not "is theexported
a bound identifier?"In the case of
export {foo}
, they're the same, but in case ofexport {foo as bar}
, they're not.However, I must admit this rule rather bends my brain! Can someone more familiar with this code advise?
@Boshen git "blames" you for this code. Can you help? But maybe @DonIsaac or @camc314 also may have an idea what this rule is about?
The text was updated successfully, but these errors were encountered: