improve fix for #4119 (#4121)

This commit is contained in:
Alex Lam S.L
2020-09-17 16:08:36 +01:00
committed by GitHub
parent 09d93cc6c8
commit 72844eb5a4
2 changed files with 55 additions and 6 deletions

View File

@@ -3362,7 +3362,6 @@ merge(Compressor.prototype, {
cached.forEach(function(node) { cached.forEach(function(node) {
delete node._eval; delete node._eval;
}); });
if (cached.unsafe) return this;
if (ignore_side_effects) return val; if (ignore_side_effects) return val;
if (!val || val instanceof RegExp) return val; if (!val || val instanceof RegExp) return val;
if (typeof val == "function" || typeof val == "object") return this; if (typeof val == "function" || typeof val == "object") return this;
@@ -3429,12 +3428,8 @@ merge(Compressor.prototype, {
}); });
} }
var value = node._eval(compressor, ignore_side_effects, cached, depth); var value = node._eval(compressor, ignore_side_effects, cached, depth);
if (value === node) return this; if (typeof value == "object") return this;
modified(lhs); modified(lhs);
if (Array.isArray(value)) value.toString = function() {
cached.unsafe = true;
return "[]";
};
return value; return value;
}); });
def(AST_Sequence, function(compressor, ignore_side_effects, cached, depth) { def(AST_Sequence, function(compressor, ignore_side_effects, cached, depth) {

View File

@@ -2960,3 +2960,57 @@ issue_4119_2: {
} }
expect_stdout: "PASS" expect_stdout: "PASS"
} }
issue_4119_3: {
options = {
conditionals: true,
evaluate: true,
reduce_vars: true,
toplevel: true,
unsafe: true,
}
input: {
var a, b;
b = a = {
p: 42,
};
delete a.p;
console.log(b.p ? "FAIL" : "PASS");
}
expect: {
var a, b;
b = a = {
p: 42,
};
delete a.p;
console.log(b.p ? "FAIL" : "PASS");
}
expect_stdout: "PASS"
}
issue_4119_4: {
options = {
booleans: true,
conditionals: true,
evaluate: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a, b;
b = a = {
p: 42,
};
delete a.p;
console.log(!b ? "FAIL" : "PASS");
}
expect: {
var a, b;
b = a = {
p: 42,
};
delete a.p;
console.log((b, 0, "PASS"));
}
expect_stdout: "PASS"
}