fix `pure_getters` on `AST_Binary` (#2681)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 28 Dec 2017 09:01:01 +0000 (17:01 +0800)
committerGitHub <noreply@github.com>
Thu, 28 Dec 2017 09:01:01 +0000 (17:01 +0800)
fixes #2678

lib/compress.js
test/compress/pure_getters.js

index ac5cd23..4e3a8f8 100644 (file)
@@ -1693,15 +1693,8 @@ merge(Compressor.prototype, {
             return this.operator == "void";
         });
         def(AST_Binary, function(compressor) {
-            switch (this.operator) {
-              case "&&":
-                return this.left._dot_throw(compressor);
-              case "||":
-                return this.left._dot_throw(compressor)
-                    && this.right._dot_throw(compressor);
-              default:
-                return false;
-            }
+            return (this.operator == "&&" || this.operator == "||")
+                && (this.left._dot_throw(compressor) || this.right._dot_throw(compressor));
         })
         def(AST_Assign, function(compressor) {
             return this.operator == "="
index 4174bc1..7185e0c 100644 (file)
@@ -611,3 +611,35 @@ issue_2313_6: {
         x();
     }
 }
+
+issue_2678: {
+    options = {
+        pure_getters: "strict",
+        side_effects: true,
+    }
+    input: {
+        var a = 1, c = "FAIL";
+        (function f() {
+            (a-- && f()).p;
+            return {
+                get p() {
+                    c = "PASS";
+                }
+            };
+        })();
+        console.log(c);
+    }
+    expect: {
+        var a = 1, c = "FAIL";
+        (function f() {
+            (a-- && f()).p;
+            return {
+                get p() {
+                    c = "PASS";
+                }
+            };
+        })();
+        console.log(c);
+    }
+    expect_stdout: "PASS"
+}