disable do{...}while(false) optimisation (#1534)
authorAlex Lam S.L <alexlamsl@gmail.com>
Thu, 2 Mar 2017 16:54:41 +0000 (00:54 +0800)
committerGitHub <noreply@github.com>
Thu, 2 Mar 2017 16:54:41 +0000 (00:54 +0800)
- fails to handle `break` in body

fixes #1532

lib/compress.js
test/compress/loops.js

index 9923598..01fdeea 100644 (file)
@@ -2132,7 +2132,7 @@ merge(Compressor.prototype, {
                 }
             } else {
                 // self instanceof AST_Do
-                return self.body;
+                return self;
             }
         }
         if (self instanceof AST_While) {
index ca05461..e26dc79 100644 (file)
@@ -213,6 +213,30 @@ evaluate: {
             a();
         for(;;)
             c();
-        d();
+        // rule disabled due to issue_1532
+        do d(); while (false);
+    }
+}
+
+issue_1532: {
+    options = {
+        evaluate: true,
+        loops: true,
+    }
+    input: {
+        function f(x, y) {
+            do {
+                if (x) break;
+                foo();
+            } while (false);
+        }
+    }
+    expect: {
+        function f(x, y) {
+            do {
+                if (x) break;
+                foo();
+            } while (false);
+        }
     }
 }