Skip to content

Commit

Permalink
fix corner case in evaluate (#5363)
Browse files Browse the repository at this point in the history
fixes #5362
  • Loading branch information
alexlamsl committed Feb 20, 2022
1 parent fbc5ecf commit 212ce46
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/compress.js
Expand Up @@ -10799,8 +10799,11 @@ Compressor.prototype.compress = function(node) {
}
switch (op) {
case "+":
if (compressor.option("evaluate") && exp.is_number(compressor, true)) return exp;
break;
if (!compressor.option("evaluate")) break;
if (!exp.is_number(compressor, true)) break;
var parent = compressor.parent();
if (parent instanceof AST_UnaryPrefix && parent.operator == "delete") break;
return exp;
case "-":
if (exp instanceof AST_Infinity) exp = exp.transform(compressor);
// avoids infinite recursion of numerals
Expand Down
36 changes: 36 additions & 0 deletions test/compress/evaluate.js
Expand Up @@ -3294,3 +3294,39 @@ issue_5356: {
}
expect_stdout: "NaN"
}

issue_5362_1: {
options = {
evaluate: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a = -console;
console.log(delete +a);
}
expect: {
var a = -console;
console.log((+a, true));
}
expect_stdout: "true"
}

issue_5362_2: {
options = {
evaluate: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
unsafe: true,
unused: true,
}
input: {
var a = -console;
console.log(delete +a);
}
expect: {
console.log(true);
}
expect_stdout: "true"
}

0 comments on commit 212ce46

Please sign in to comment.