fix corner case in evaluate (#4272)

fixes #4271
This commit is contained in:
Alex Lam S.L
2020-11-10 16:06:13 +00:00
committed by GitHub
parent 41310e6404
commit fba27bfb71
2 changed files with 28 additions and 4 deletions

View File

@@ -3592,10 +3592,7 @@ merge(Compressor.prototype, {
key = key._eval(compressor, ignore_side_effects, cached, depth);
if (key === prop.key) return this;
}
if (prop.value instanceof AST_Function) {
if (typeof Object.prototype[key] == "function") return this;
continue;
}
if (prop.value instanceof AST_Function && typeof Object.prototype[key] == "function") return this;
val[key] = prop.value._eval(compressor, ignore_side_effects, cached, depth);
if (val[key] === prop.value) return this;
}

View File

@@ -3047,3 +3047,30 @@ issue_4214: {
}
expect_stdout: "NaN"
}
issue_4271: {
options = {
evaluate: true,
unsafe: true,
}
input: {
({
p: null,
q: (console.log("foo"), 42),
p: function() {}
})[console.log("bar"), "p"] && console.log("PASS");
}
expect: {
({
p: null,
q: (console.log("foo"), 42),
p: function() {}
})[console.log("bar"), "p"],
console.log("PASS");
}
expect_stdout: [
"foo",
"bar",
"PASS",
]
}