diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-08-04 20:05:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-04 20:05:10 +0800 |
commit | a4002ef46799438614ff0b902551fa7fedf2c884 (patch) | |
tree | 9ffe320699f772bc5952dc2e2fa6db5760f0491b /lib | |
parent | 9d758a216bfb030f87df9864a0c5577f986e5f04 (diff) | |
download | tracifyjs-a4002ef46799438614ff0b902551fa7fedf2c884.tar.gz tracifyjs-a4002ef46799438614ff0b902551fa7fedf2c884.zip |
fix corner case in `evaluate` (#4036)
fixes #4035
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/lib/compress.js b/lib/compress.js index fbc2bf7d..650a7634 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7436,56 +7436,58 @@ merge(Compressor.prototype, { } break; } - if (self.left instanceof AST_Number && !self.right.is_constant()) switch (self.operator) { - // 0 + n => n - case "+": - if (self.left.value == 0) { - if (self.right.is_boolean(compressor)) return make_node(AST_UnaryPrefix, self, { - operator: "+", - expression: self.right - }).optimize(compressor); - if (self.right.is_number(compressor) && !self.right.is_negative_zero()) return self.right; - } - break; - // 1 * n => n - case "*": - if (self.left.value == 1) { - return self.right.is_number(compressor) ? self.right : make_node(AST_UnaryPrefix, self, { - operator: "+", - expression: self.right - }).optimize(compressor); - } - break; - } - if (self.right instanceof AST_Number && !self.left.is_constant()) switch (self.operator) { - // n + 0 => n - case "+": - if (self.right.value == 0) { - if (self.left.is_boolean(compressor)) return make_node(AST_UnaryPrefix, self, { - operator: "+", - expression: self.left - }).optimize(compressor); - if (self.left.is_number(compressor) && !self.left.is_negative_zero()) return self.left; - } - break; - // n - 0 => n - case "-": - if (self.right.value == 0) { - return self.left.is_number(compressor) ? self.left : make_node(AST_UnaryPrefix, self, { - operator: "+", - expression: self.left - }).optimize(compressor); + if (!(parent instanceof AST_UnaryPrefix && parent.operator == "delete")) { + if (self.left instanceof AST_Number && !self.right.is_constant()) switch (self.operator) { + // 0 + n => n + case "+": + if (self.left.value == 0) { + if (self.right.is_boolean(compressor)) return make_node(AST_UnaryPrefix, self, { + operator: "+", + expression: self.right + }).optimize(compressor); + if (self.right.is_number(compressor) && !self.right.is_negative_zero()) return self.right; + } + break; + // 1 * n => n + case "*": + if (self.left.value == 1) { + return self.right.is_number(compressor) ? self.right : make_node(AST_UnaryPrefix, self, { + operator: "+", + expression: self.right + }).optimize(compressor); + } + break; } - break; - // n / 1 => n - case "/": - if (self.right.value == 1) { - return self.left.is_number(compressor) ? self.left : make_node(AST_UnaryPrefix, self, { - operator: "+", - expression: self.left - }).optimize(compressor); + if (self.right instanceof AST_Number && !self.left.is_constant()) switch (self.operator) { + // n + 0 => n + case "+": + if (self.right.value == 0) { + if (self.left.is_boolean(compressor)) return make_node(AST_UnaryPrefix, self, { + operator: "+", + expression: self.left + }).optimize(compressor); + if (self.left.is_number(compressor) && !self.left.is_negative_zero()) return self.left; + } + break; + // n - 0 => n + case "-": + if (self.right.value == 0) { + return self.left.is_number(compressor) ? self.left : make_node(AST_UnaryPrefix, self, { + operator: "+", + expression: self.left + }).optimize(compressor); + } + break; + // n / 1 => n + case "/": + if (self.right.value == 1) { + return self.left.is_number(compressor) ? self.left : make_node(AST_UnaryPrefix, self, { + operator: "+", + expression: self.left + }).optimize(compressor); + } + break; } - break; } } if (compressor.option("typeofs")) switch (self.operator) { |