[Pkg-javascript-commits] [uglifyjs] 136/228: fix corner case in `AST_For.init` (#1652)

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

    fix corner case in `AST_For.init` (#1652)
    
    Enforce `null` as value for empty initialisation blocks.
    
    fixes #1648
---
 lib/compress.js        |  1 +
 lib/output.js          |  2 +-
 test/compress/loops.js | 18 ++++++++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index cbcb7b8..3804a93 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2327,6 +2327,7 @@ merge(Compressor.prototype, {
     };
 
     OPT(AST_For, function(self, compressor){
+        if (is_empty(self.init)) self.init = null;
         if (!compressor.option("loops")) return self;
         if (self.condition) {
             var cond = self.condition.evaluate(compressor);
diff --git a/lib/output.js b/lib/output.js
index 767abd4..c0f1052 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -799,7 +799,7 @@ function OutputStream(options) {
         output.print("for");
         output.space();
         output.with_parens(function(){
-            if (self.init && !(self.init instanceof AST_EmptyStatement)) {
+            if (self.init) {
                 if (self.init instanceof AST_Definitions) {
                     self.init.print(output);
                 } else {
diff --git a/test/compress/loops.js b/test/compress/loops.js
index b55c616..c8d7784 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -440,3 +440,21 @@ issue_186_beautify_bracketize_ie8: {
         '}',
     ]
 }
+
+issue_1648: {
+    options = {
+        join_vars: true,
+        loops: true,
+        passes: 2,
+        sequences: true,
+        unused: true,
+    }
+    input: {
+        function f() {
+            x();
+            var b = 1;
+            while (1);
+        }
+    }
+    expect_exact: "function f(){for(x();1;);}"
+}

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