Skip to content

Constant evaluation is dumb #787

@mik01aj

Description

@mik01aj

I tried this in your online demo with constant evaluation enabled:

console.log(2 + 2 * 2);
console.log('abcdefgh'[4]);
console.log({a:'b'}['a']);

The result is:

console.log(6),console.log("abcdefgh"[4]),console.log({a:"b"}.a)

Only the first (numeric) expression was optimized. I would expect all of them to be evaluated.

This should be a safe transformation if only someone didn't override Array or Object constructor. (Note that accessing non-plain object's properties is not safe as they might have a getter.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions