[Pkg-javascript-commits] [uglifyjs] 204/491: fix `unused` patching of `AST_For.init` blocks (#2289)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:36 UTC 2018


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

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit e5cf7972eab25581f9aa020bc8dbdd8bf25743cb
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Aug 29 01:10:04 2017 +0800

    fix `unused` patching of `AST_For.init` blocks (#2289)
    
    fixes #2288
---
 lib/compress.js              |  9 +++++----
 test/compress/drop-unused.js | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 7a16ba8..9121d0c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2423,17 +2423,18 @@ merge(Compressor.prototype, {
                 // We fix it at this stage by moving the `var` outside the `for`.
                 if (node instanceof AST_For) {
                     descend(node, this);
+                    var block;
                     if (node.init instanceof AST_BlockStatement) {
-                        var block = node.init;
+                        block = node.init;
                         node.init = block.body.pop();
                         block.body.push(node);
-                        return in_list ? MAP.splice(block.body) : block;
-                    } else if (node.init instanceof AST_SimpleStatement) {
+                    }
+                    if (node.init instanceof AST_SimpleStatement) {
                         node.init = node.init.body;
                     } else if (is_empty(node.init)) {
                         node.init = null;
                     }
-                    return node;
+                    return !block ? node : in_list ? MAP.splice(block.body) : block;
                 }
                 if (node instanceof AST_LabeledStatement && node.body instanceof AST_For) {
                     descend(node, this);
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 34d47d0..c904854 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1239,3 +1239,25 @@ issue_2226_3: {
     }
     expect_stdout: "3"
 }
+
+issue_2288: {
+    options = {
+        unused: true,
+    }
+    beautify = {
+        beautify: true,
+    }
+    input: {
+        function foo(o) {
+            for (var j = o.a, i = 0; i < 0; i++);
+            for (var i = 0; i < 0; i++);
+        }
+    }
+    expect: {
+        function foo(o) {
+            o.a;
+            for (i = 0; i < 0; i++);
+            for (var i = 0; i < 0; i++);
+        }
+    }
+}

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