-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misleading result from getStaticValue() when called on mutable const-declared variables #10
Comments
What happens if the following happens? const mutable = {a: 1};
mutable.a = 2;
mutable; Will |
@liangyuanruo, in your example, |
* 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]>
Hi @ninevra! Since this repo is unmaintained, you might want to re-open this issue in the @eslint-community fork https://github.com/eslint-community/eslint-utils For more info about why we created this organization, you can read https://eslint.org/blog/2023/03/announcing-eslint-community-org |
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: