diff options
-rw-r--r-- | lib/compress.js | 43 | ||||
-rw-r--r-- | test/compress/evaluate.js | 23 |
2 files changed, 55 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js index c199d13f..b001d35c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3620,6 +3620,11 @@ merge(Compressor.prototype, { return ref; } } + var parent = compressor.parent(); + if (parent instanceof AST_UnaryPrefix + && parent.operator == "delete" + && (parent.expression instanceof AST_SymbolRef + || parent.expression.TYPE === self.TYPE)) return self; return make_node(AST_UnaryPrefix, self, { operator: "void", expression: make_node(AST_Number, self, { @@ -3629,8 +3634,16 @@ merge(Compressor.prototype, { }); OPT(AST_Infinity, function(self, compressor){ - var retain = compressor.option("keep_infinity") && !find_variable(compressor, "Infinity"); - return retain ? self : make_node(AST_Binary, self, { + var parent = compressor.parent(); + if (parent instanceof AST_UnaryPrefix + && parent.operator == "delete" + && (parent.expression instanceof AST_SymbolRef + || parent.expression.TYPE === self.TYPE)) + return self; + if (compressor.option("keep_infinity") + && !find_variable(compressor, "Infinity")) + return self; + return make_node(AST_Binary, self, { operator: "/", left: make_node(AST_Number, self, { value: 1 @@ -3642,15 +3655,23 @@ merge(Compressor.prototype, { }); OPT(AST_NaN, function(self, compressor){ - return find_variable(compressor, "NaN") ? make_node(AST_Binary, self, { - operator: "/", - left: make_node(AST_Number, self, { - value: 0 - }), - right: make_node(AST_Number, self, { - value: 0 - }) - }) : self; + var parent = compressor.parent(); + if (parent instanceof AST_UnaryPrefix + && parent.operator == "delete" + && !(parent.expression instanceof AST_SymbolRef + || parent.expression.TYPE === self.TYPE) + || find_variable(compressor, "NaN")) { + return make_node(AST_Binary, self, { + operator: "/", + left: make_node(AST_Number, self, { + value: 0 + }), + right: make_node(AST_Number, self, { + value: 0 + }) + }); + } + return self; }); var ASSIGN_OPS = [ '+', '-', '/', '*', '%', '>>', '<<', '>>>', '|', '^', '&' ]; diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index fa432c46..e660071d 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -857,3 +857,26 @@ issue_1760_2: { } expect_stdout: "Infinity" } + +delete_expr: { + options = { + evaluate: true, + } + input: { + console.log(delete undefined); + console.log(delete void 0); + console.log(delete Infinity); + console.log(delete (1 / 0)); + console.log(delete NaN); + console.log(delete (0 / 0)); + } + expect: { + console.log(delete undefined); + console.log(delete void 0); + console.log(delete Infinity); + console.log(delete (1 / 0)); + console.log(delete NaN); + console.log(delete (0 / 0)); + } + expect_stdout: true +} |