-
-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Transferring this issue from mysticatea#10 as requested in mysticatea#10 (comment).
i don't currently use this library, and haven't verified that the issue still applies; i did skim the commit log, though, and didn't see anything related.
When getStaticValue()
is called with a scope and encounters an identifier referring to a variable declared with const
, it computes that variable's static value based on its const
declaration initializer only. If the variable is initialized to a mutable value, it can later be modified, resulting in the return value from getStaticValue()
not matching the variable's true value at time of use.
Example:
const mutable = {a: 1};
mutable.b = 2;
mutable;
Calling getStaticValue()
on the Identifier node mutable
on line 3 returns {value: {a: 1}}
, but mutable
's actual value is {a: 1, b: 2}
.
This can also result in erroneously classifying identifiers as static. For example:
const mutable = {a: 1};
mutable.b = foo();
mutable;
mutable
on line 3 is not static-valued, but getStaticValue()
returns {value: {a: 1}}
.