fix corner case in evaluate

fixes #4214
This commit is contained in:
alexlamsl 2020-10-13 23:34:54 +08:00
parent 0e234a25c5
commit 2479689681
2 changed files with 38 additions and 3 deletions

View File

@ -3803,6 +3803,8 @@ merge(Compressor.prototype, {
if (fn.evaluating) return this;
if (fn.name && fn.name.definition().recursive_refs > 0) return this;
if (this.is_expr_pure(compressor)) return this;
var args = eval_args(this.args);
if (!args && !ignore_side_effects) return this;
var stat = fn.first_statement();
if (!(stat instanceof AST_Return)) {
if (ignore_side_effects) {
@ -3810,7 +3812,9 @@ merge(Compressor.prototype, {
fn.walk(new TreeWalker(function(node) {
if (found) return true;
if (node instanceof AST_Return) {
if (node.value && node.value.evaluate(compressor, true) !== undefined) found = true;
if (node.value && node.value._eval(compressor, true, cached, depth) !== undefined) {
found = true;
}
return true;
}
if (node instanceof AST_Scope && node !== fn) return true;
@ -3819,8 +3823,6 @@ merge(Compressor.prototype, {
}
return this;
}
var args = eval_args(this.args);
if (!args && !ignore_side_effects) return this;
var val = stat.value;
if (!val) return;
var cached_args = [];

View File

@ -3014,3 +3014,36 @@ issue_4119_4: {
}
expect_stdout: "PASS"
}
issue_4214: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
function f(a) {
return function() {
try {
return a;
} finally {
var b = 0;
}
}(a++ && this());
}
var c = f();
console.log(c);
}
expect: {
var c = function(a) {
return function() {
try {
return a;
} finally {}
}(a++ && this());
}();
console.log(c);
}
expect_stdout: "NaN"
}