Skip to content

Incorrect removal property from object accessed in nested conditions #3733

Closed
@WearyMonkey

Description

We have found a case where a property of a conditionally accessed object is incorrectly removed. This is a critical issue as it's impossible to lint for in a large code base and will fail at runtime.

tested versions:
20201126.0.0-nightly
20201102.0.0

source:

const X = {Y: 1};

function fn(a) {
    if (a) {
        return a ? X : {};
    }
}

console.log(fn(true).Y);
java -jar compiler.jar -O ADVANCED --js test.js

output:

var a;a={};console.log(a.a);

expected output:

var a;a={a:1};console.log(a.a);

Notes:
Remove either of the conditions and it works as expected
Move the X variable declaration into fn and it works as expected.
Inline the fn and it works as expected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions