From 212ce4608ec24ba36868818b1ca662517b6ecb64 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 20 Feb 2022 13:38:04 +0000 Subject: [PATCH] fix corner case in `evaluate` (#5363) fixes #5362 --- lib/compress.js | 7 +++++-- test/compress/evaluate.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index dd0edd5a63..6b083d082f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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 diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 18527fb09e..da45378429 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -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" +}