diff options
-rw-r--r-- | lib/compress.js | 14 | ||||
-rw-r--r-- | test/compress/numbers.js | 16 |
2 files changed, 24 insertions, 6 deletions
diff --git a/lib/compress.js b/lib/compress.js index 7355ff53..1ae5e8eb 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7556,13 +7556,15 @@ merge(Compressor.prototype, { && self.left.is_number(compressor)) { if (self.left.left instanceof AST_Constant) { var lhs = make_binary(self.left, self.operator, self.left.left, self.right, self.left.left.start, self.right.end); - self = make_binary(self, self.left.operator, lhs, self.left.right); + self = make_binary(self, self.left.operator, try_evaluate(compressor, lhs), self.left.right); } else if (self.left.right instanceof AST_Constant) { - var rhs = make_binary(self.left, align(self.left.operator, self.operator), self.left.right, self.right, self.left.right.start, self.right.end); - if (self.left.operator != "-" - || !self.right.value - || rhs.evaluate(compressor) - || !self.left.left.is_negative_zero()) { + var op = align(self.left.operator, self.operator); + var rhs = try_evaluate(compressor, make_binary(self.left, op, self.left.right, self.right)); + if (rhs.is_constant() + && !(self.left.operator == "-" + && self.right.value != 0 + && +rhs.value == 0 + && self.left.left.is_negative_zero())) { self = make_binary(self, self.left.operator, self.left.left, rhs); } } diff --git a/test/compress/numbers.js b/test/compress/numbers.js index 9fca46f3..32987a6b 100644 --- a/test/compress/numbers.js +++ b/test/compress/numbers.js @@ -637,6 +637,22 @@ evaluate_7_unsafe_math: { ] } +evaluate_8_unsafe_math: { + options = { + evaluate: true, + unsafe_math: true, + } + input: { + var a = [ "42" ]; + console.log(a * (1 / 7)); + } + expect: { + var a = [ "42" ]; + console.log(+a / 7); + } + expect_stdout: "6" +} + NaN_redefined: { options = { evaluate: true, |