fix corner case in `evaluate` (#3938)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 30 May 2020 10:22:40 +0000 (11:22 +0100)
committerGitHub <noreply@github.com>
Sat, 30 May 2020 10:22:40 +0000 (18:22 +0800)
fixes #3937

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

index 443a649..0791632 100644 (file)
@@ -3493,7 +3493,7 @@ merge(Compressor.prototype, {
             var fixed = this.fixed_value();
             if (!fixed) return this;
             var value;
-            if (member(fixed, cached)) {
+            if (HOP(fixed, "_eval")) {
                 value = fixed._eval();
             } else {
                 this._eval = return_this;
index 97b3940..0cf1d89 100644 (file)
@@ -2669,3 +2669,24 @@ issue_3935: {
     }
     expect_stdout: "NaN"
 }
+
+issue_3937: {
+    options = {
+        conditionals: true,
+        evaluate: true,
+        reduce_vars: true,
+        toplevel: true,
+        unsafe: true,
+    }
+    input: {
+        var a = 123;
+        (a++ + (b = a))[b] ? 0 ? a : b : 0 ? a : b;
+        console.log(a, b);
+    }
+    expect: {
+        var a = 123;
+        (a++ + (b = a))[b], 0, b;
+        console.log(a, b);
+    }
+    expect_stdout: "124 124"
+}