fix corner case in `evaluate` & `unsafe_math` (#3756)
authorAlex Lam S.L <alexlamsl@gmail.com>
Mon, 30 Mar 2020 11:13:14 +0000 (12:13 +0100)
committerGitHub <noreply@github.com>
Mon, 30 Mar 2020 11:13:14 +0000 (19:13 +0800)
fixes #3755

lib/compress.js
test/compress/evaluate.js

index 343994e..72690fe 100644 (file)
@@ -3243,6 +3243,7 @@ merge(Compressor.prototype, {
             }
             if (isNaN(result)) return compressor.find_parent(AST_With) ? this : result;
             if (compressor.option("unsafe_math")
+                && !ignore_side_effects
                 && result
                 && typeof result == "number"
                 && (this.operator == "+" || this.operator == "-")) {
index 6d3adac..e7f6f7e 100644 (file)
@@ -2174,3 +2174,19 @@ issue_3738: {
     }
     expect_stdout: "Infinity"
 }
+
+issue_3755: {
+    options = {
+        booleans: true,
+        evaluate: true,
+        unsafe: true,
+        unsafe_math: true,
+    }
+    input: {
+        console.log((/4/.exec(1 + (!0 - 5 / "23")) || 0).p);
+    }
+    expect: {
+        console.log((/4/.exec(!0 - 5 / "23" + 1), 0).p);
+    }
+    expect_stdout: "undefined"
+}