fix corner case in `evaluate` (#4078)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 26 Aug 2020 11:45:38 +0000 (12:45 +0100)
committerGitHub <noreply@github.com>
Wed, 26 Aug 2020 11:45:38 +0000 (19:45 +0800)
fixes #4077

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

index a1f3d50..cd790db 100644 (file)
@@ -3502,7 +3502,8 @@ merge(Compressor.prototype, {
             var left = this.left._eval(compressor, ignore_side_effects, cached, depth);
             if (left === this.left) return this;
             if (this.operator == (left ? "||" : "&&")) return left;
-            var right = this.right._eval(compressor, ignore_side_effects, cached, depth);
+            var rhs_ignore_side_effects = ignore_side_effects && !(left && typeof left == "object");
+            var right = this.right._eval(compressor, rhs_ignore_side_effects, cached, depth);
             if (right === this.right) return this;
             var result;
             switch (this.operator) {
index 9f97ba9..6d4d084 100644 (file)
@@ -2894,3 +2894,17 @@ issue_4067: {
     }
     expect_stdout: "NaN"
 }
+
+issue_4077: {
+    options = {
+        evaluate: true,
+        unsafe: true,
+    }
+    input: {
+        console.log((a = []) - (a[0]++, 1) || "PASS");
+    }
+    expect: {
+        console.log((a = []) - (a[0]++, 1) || "PASS");
+    }
+    expect_stdout: "PASS"
+}