[Pkg-javascript-commits] [uglifyjs] 20/228: tweak do-while loops - `do{...}while(false)` => `{...}` - clean up `AST_While` logic

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit ae4db00991c6155fde42bd00c30614d922a4219a
Author: alexlamsl <alexlamsl at gmail.com>
Date:   Sat Feb 18 19:05:54 2017 +0800

    tweak do-while loops
    - `do{...}while(false)` => `{...}`
    - clean up `AST_While` logic
    
    closes #1452
---
 lib/compress.js        | 16 ++++++----------
 test/compress/loops.js | 29 +++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 2ba2982..ee28ee1 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1813,8 +1813,14 @@ merge(Compressor.prototype, {
                     extract_declarations_from_unreachable_code(compressor, self.body, a);
                     return make_node(AST_BlockStatement, self, { body: a });
                 }
+            } else {
+                // self instanceof AST_Do
+                return self.body;
             }
         }
+        if (self instanceof AST_While) {
+            return make_node(AST_For, self, self).transform(compressor);
+        }
         return self;
     });
 
@@ -1863,16 +1869,6 @@ merge(Compressor.prototype, {
         }
     };
 
-    OPT(AST_While, function(self, compressor) {
-        if (!compressor.option("loops")) return self;
-        self = AST_DWLoop.prototype.optimize.call(self, compressor);
-        if (self instanceof AST_While) {
-            if_break_in_loop(self, compressor);
-            self = make_node(AST_For, self, self).transform(compressor);
-        }
-        return self;
-    });
-
     OPT(AST_For, function(self, compressor){
         var cond = self.condition;
         if (cond) {
diff --git a/test/compress/loops.js b/test/compress/loops.js
index 78f618a..ca05461 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -187,3 +187,32 @@ keep_collapse_const_in_own_block_scope_2: {
         console.log(c);
     }
 }
+
+evaluate: {
+    options = {
+        loops: true,
+        dead_code: true,
+        evaluate: true,
+    };
+    input: {
+        while (true) {
+            a();
+        }
+        while (false) {
+            b();
+        }
+        do {
+            c();
+        } while (true);
+        do {
+            d();
+        } while (false);
+    }
+    expect: {
+        for(;;)
+            a();
+        for(;;)
+            c();
+        d();
+    }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list