fix unsafe expansion of object literals (#2390)

This commit is contained in:
Alex Lam S.L
2017-10-22 15:00:36 +08:00
committed by GitHub
parent 516eaef50c
commit 5fd723f143
2 changed files with 24 additions and 6 deletions

View File

@@ -4499,7 +4499,7 @@ merge(Compressor.prototype, {
for (var i = values.length; --i >= 0;) {
if (values[i].key === self.property) {
var value = values[i].value;
if (value instanceof AST_Function ? !value.contains_this() : !value.has_side_effects(compressor)) {
if (value instanceof AST_Function ? value.contains_this() : value.has_side_effects(compressor)) break;
var obj = self.expression.clone();
obj.properties = obj.properties.slice();
obj.properties.splice(i, 1);
@@ -4507,7 +4507,6 @@ merge(Compressor.prototype, {
}
}
}
}
if (compressor.option("unsafe_proto")
&& self.expression instanceof AST_Dot
&& self.expression.property == "prototype") {

View File

@@ -841,3 +841,22 @@ lhs_prop_2: {
"abc"[2] = "g";
}
}
literal_duplicate_key_side_effects: {
options = {
unsafe: true,
}
input: {
console.log({
a: "FAIL",
a: console.log ? "PASS" : "FAIL"
}.a);
}
expect: {
console.log({
a: "FAIL",
a: console.log ? "PASS" : "FAIL"
}.a);
}
expect_stdout: "PASS"
}