Skip to content

Misleading result from getStaticValue() when called on mutable const-declared variables #10

@ninevra

Description

@ninevra

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

Minimal working example

This can also result in erroneously identifying 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}}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions