aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-04-07 15:39:59 +0800
committerGitHub <noreply@github.com>2017-04-07 15:39:59 +0800
commite3c9c22c757112327b83f598b124690baf13ac52 (patch)
treeef0f12fae9fedb217b2a0b7219f95bbc9fb6511e /lib/compress.js
parent0f4cd73dcc5d8a936ae3630a7992dbcb44274136 (diff)
downloadtracifyjs-e3c9c22c757112327b83f598b124690baf13ac52.tar.gz
tracifyjs-e3c9c22c757112327b83f598b124690baf13ac52.zip
fix corner cases with `delete` (#1796)
`delete Infinity` returns `false` where as `delete (1/0)` returns `true`
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js43
1 files changed, 32 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 = [ '+', '-', '/', '*', '%', '>>', '<<', '>>>', '|', '^', '&' ];