You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
constmutable={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}.
@liangyuanruo, in your example, getStaticValue() returns {value: {a: 1}} for each of the three mutableIdentifier nodes. getStaticValue() doesn't examine anything besides the given node and the declarations of any variables it references, so it doesn't see the mutation on line 2, regardless of what form that mutation takes.
* feat: support ESLint 8.x
* chore: use `@babel/register` instead of `esm` (mysticatea#16)
* chore: use esbuild-register instead of esm.
* chore: add esbuild to deps
* chore: use @babel/register instead of esbuild-register
Co-authored-by: Yosuke Ota <[email protected]>
When
getStaticValue()
is called with a scope and encounters an identifier referring to a variable declared withconst
, it computes that variable's static value based on itsconst
declaration initializer only. If the variable is initialized to a mutable value, it can later be modified, resulting in the return value fromgetStaticValue()
not matching the variable's true value at time of use.Example:
Calling
getStaticValue()
on the Identifier nodemutable
on line 3 returns{value: {a: 1}}
, butmutable
's actual value is{a: 1, b: 2}
.Minimal working example
This can also result in erroneously identifying identifiers as static. For example:
mutable
on line 3 is not static-valued, butgetStaticValue()
returns{value: {a: 1}}
.The text was updated successfully, but these errors were encountered: