Skip to content
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 #192

Open
ninevra opened this issue Jan 21, 2024 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ninevra
Copy link

ninevra commented Jan 21, 2024

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}}.

@voxpelli
Copy link
Member

voxpelli commented Mar 8, 2024

We should definitely add a test case to check whether this may still be the case.

Would you be up for making a PR?

@voxpelli voxpelli added bug Something isn't working help wanted Extra attention is needed labels Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants