fix corner case in evaluate (#3569)
This commit is contained in:
@@ -2881,6 +2881,7 @@ merge(Compressor.prototype, {
|
|||||||
if (!non_converting_binary[this.operator]) depth++;
|
if (!non_converting_binary[this.operator]) depth++;
|
||||||
var left = this.left._eval(compressor, cached, depth);
|
var left = this.left._eval(compressor, cached, depth);
|
||||||
if (left === this.left) return this;
|
if (left === this.left) return this;
|
||||||
|
if (this.operator == (left ? "||" : "&&")) return left;
|
||||||
var right = this.right._eval(compressor, cached, depth);
|
var right = this.right._eval(compressor, cached, depth);
|
||||||
if (right === this.right) return this;
|
if (right === this.right) return this;
|
||||||
var result;
|
var result;
|
||||||
@@ -3049,7 +3050,10 @@ merge(Compressor.prototype, {
|
|||||||
cached.push(node);
|
cached.push(node);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return stat.value ? stat.value._eval(compressor, cached, depth) : undefined;
|
if (!stat.value) return undefined;
|
||||||
|
var val = stat.value._eval(compressor, cached, depth);
|
||||||
|
if (val === stat.value) return this;
|
||||||
|
return val;
|
||||||
} else if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
|
} else if (compressor.option("unsafe") && exp instanceof AST_PropAccess) {
|
||||||
var key = exp.property;
|
var key = exp.property;
|
||||||
if (key instanceof AST_Node) {
|
if (key instanceof AST_Node) {
|
||||||
|
|||||||
@@ -1876,3 +1876,27 @@ issue_3558: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "1 0"
|
expect_stdout: "1 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3568: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0;
|
||||||
|
function f(b) {
|
||||||
|
return b && b.p;
|
||||||
|
}
|
||||||
|
console.log(f(++a + f()));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 0;
|
||||||
|
function f(b) {
|
||||||
|
return b && b.p;
|
||||||
|
}
|
||||||
|
console.log(NaN);
|
||||||
|
}
|
||||||
|
expect_stdout: "NaN"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user