[Pkg-javascript-commits] [uglifyjs] 82/228: suppress semicolons after do/while (#1556)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:19 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 a9fc9ddc3371a2ba051bca849db3c4b73983f24d
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Mon Mar 6 17:31:35 2017 +0800

    suppress semicolons after do/while (#1556)
    
    - unless both `beautify` & `screw-ie8` are enabled
    - deprecate workaround for if-do-while-else
    
    fixes #186
---
 lib/output.js          |  13 +----
 test/compress/loops.js | 156 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 159 insertions(+), 10 deletions(-)

diff --git a/lib/output.js b/lib/output.js
index 10fed13..7e16644 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -784,7 +784,9 @@ function OutputStream(options) {
         output.with_parens(function(){
             self.condition.print(output);
         });
-        output.semicolon();
+        if (output.option("beautify") && output.option("screw_ie8")) {
+            output.semicolon();
+        }
     });
     DEFPRINT(AST_While, function(self, output){
         output.print("while");
@@ -917,15 +919,6 @@ function OutputStream(options) {
         // adds the block brackets if needed.
         if (!self.body)
             return output.force_semicolon();
-        if (self.body instanceof AST_Do) {
-            // Unconditionally use the if/do-while workaround for all browsers.
-            // https://github.com/mishoo/UglifyJS/issues/#issue/57 IE
-            // croaks with "syntax error" on code like this: if (foo)
-            // do ... while(cond); else ...  we need block brackets
-            // around do/while
-            make_block(self.body, output);
-            return;
-        }
         var b = self.body;
         while (true) {
             if (b instanceof AST_If) {
diff --git a/test/compress/loops.js b/test/compress/loops.js
index e26dc79..2d04e23 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -240,3 +240,159 @@ issue_1532: {
         }
     }
 }
+
+issue_186: {
+    beautify = {
+        beautify: false,
+        screw_ie8: true,
+    }
+    input: {
+        var x = 3;
+        if (foo())
+            do
+                do
+                    alert(x);
+                while (--x);
+            while (x);
+        else
+            bar();
+    }
+    expect_exact: 'var x=3;if(foo())do do alert(x);while(--x)while(x)else bar();'
+}
+
+issue_186_ie8: {
+    beautify = {
+        beautify: false,
+        screw_ie8: false,
+    }
+    input: {
+        var x = 3;
+        if (foo())
+            do
+                do
+                    alert(x);
+                while (--x);
+            while (x);
+        else
+            bar();
+    }
+    expect_exact: 'var x=3;if(foo())do do alert(x);while(--x)while(x)else bar();'
+}
+
+issue_186_beautify: {
+    beautify = {
+        beautify: true,
+        screw_ie8: true,
+    }
+    input: {
+        var x = 3;
+        if (foo())
+            do
+                do
+                    alert(x);
+                while (--x);
+            while (x);
+        else
+            bar();
+    }
+    expect_exact: 'var x = 3;\n\nif (foo()) do do alert(x); while (--x); while (x); else bar();'
+}
+
+issue_186_beautify_ie8: {
+    beautify = {
+        beautify: true,
+        screw_ie8: false,
+    }
+    input: {
+        var x = 3;
+        if (foo())
+            do
+                do
+                    alert(x);
+                while (--x);
+            while (x);
+        else
+            bar();
+    }
+    expect_exact: 'var x = 3;\n\nif (foo()) do do alert(x); while (--x) while (x) else bar();'
+}
+
+issue_186_bracketize: {
+    beautify = {
+        beautify: false,
+        bracketize: true,
+        screw_ie8: true,
+    }
+    input: {
+        var x = 3;
+        if (foo())
+            do
+                do
+                    alert(x);
+                while (--x);
+            while (x);
+        else
+            bar();
+    }
+    expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
+}
+
+issue_186_bracketize_ie8: {
+    beautify = {
+        beautify: false,
+        bracketize: true,
+        screw_ie8: false,
+    }
+    input: {
+        var x = 3;
+        if (foo())
+            do
+                do
+                    alert(x);
+                while (--x);
+            while (x);
+        else
+            bar();
+    }
+    expect_exact: 'var x=3;if(foo()){do{do{alert(x)}while(--x)}while(x)}else{bar()}'
+}
+
+issue_186_beautify_bracketize: {
+    beautify = {
+        beautify: true,
+        bracketize: true,
+        screw_ie8: true,
+    }
+    input: {
+        var x = 3;
+        if (foo())
+            do
+                do
+                    alert(x);
+                while (--x);
+            while (x);
+        else
+            bar();
+    }
+    expect_exact: 'var x = 3;\n\nif (foo()) {\n    do {\n        do {\n            alert(x);\n        } while (--x);\n    } while (x);\n} else {\n    bar();\n}'
+}
+
+issue_186_beautify_bracketize_ie8: {
+    beautify = {
+        beautify: true,
+        bracketize: true,
+        screw_ie8: false,
+    }
+    input: {
+        var x = 3;
+        if (foo())
+            do
+                do
+                    alert(x);
+                while (--x);
+            while (x);
+        else
+            bar();
+    }
+    expect_exact: 'var x = 3;\n\nif (foo()) {\n    do {\n        do {\n            alert(x);\n        } while (--x)\n    } while (x)\n} else {\n    bar();\n}'
+}

-- 
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