fix corner case in `evaluate` (#3540)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 28 Oct 2019 11:56:42 +0000 (19:56 +0800)
committerGitHub <noreply@github.com>
Mon, 28 Oct 2019 11:56:42 +0000 (19:56 +0800)
fixes #3539

lib/compress.js
test/compress/numbers.js

index 442df59..7c5558b 100644 (file)
@@ -2901,6 +2901,7 @@ merge(Compressor.prototype, {
             }
             if (isNaN(result)) return compressor.find_parent(AST_With) ? this : result;
             if (compressor.option("unsafe_math")
+                && result
                 && typeof result == "number"
                 && (this.operator == "+" || this.operator == "-")) {
                 var digits = Math.max(0, decimals(left), decimals(right));
index 63a100b..79fccfb 100644 (file)
@@ -765,3 +765,19 @@ issue_3536: {
     }
     expect_stdout: "number 99 11 121"
 }
+
+issue_3539: {
+    options = {
+        evaluate: true,
+        unsafe_math: true,
+    }
+    input: {
+        var a = -0 + -"";
+        console.log(0/a, 1/a, -1/a);
+    }
+    expect: {
+        var a = -0;
+        console.log(0/a, 1/a, -1/a);
+    }
+    expect_stdout: "NaN -Infinity Infinity"
+}