[Pkg-javascript-commits] [uglifyjs] 04/50: fix `unused` on for-in statements (#1843)

Jonas Smedegaard dr at jones.dk
Thu Aug 17 23:06:43 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 2c21dc5e8ebaea276c92ad227ef14a12ff3fa248
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Mon Apr 24 03:14:01 2017 +0800

    fix `unused` on for-in statements (#1843)
    
    Only need to avoid `var` within the initialisation block.
    
    fixes #1841
---
 lib/compress.js            |  2 +-
 test/compress/functions.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 135dde1..411c284 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1992,7 +1992,7 @@ merge(Compressor.prototype, {
                         }
                         return node;
                     }
-                    if (drop_vars && node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn)) {
+                    if (drop_vars && node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn && tt.parent().init === node)) {
                         var def = node.definitions.filter(function(def){
                             if (def.value) def.value = def.value.transform(tt);
                             var sym = def.name.definition();
diff --git a/test/compress/functions.js b/test/compress/functions.js
index dca4062..7d1928c 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -93,3 +93,57 @@ issue_485_crashing_1530: {
         this, void 0;
     }
 }
+
+issue_1841_1: {
+    options = {
+        keep_fargs: false,
+        pure_getters: "strict",
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        var b = 10;
+        !function(arg) {
+            for (var key in "hi")
+                var n = arg.baz, n = [ b = 42 ];
+        }(--b);
+        console.log(b);
+    }
+    expect: {
+        var b = 10;
+        !function() {
+            for (var key in "hi") {
+                b = 42;
+            }
+        }(--b);
+        console.log(b);
+    }
+    expect_exact: "42"
+}
+
+issue_1841_2: {
+    options = {
+        keep_fargs: false,
+        pure_getters: false,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        var b = 10;
+        !function(arg) {
+            for (var key in "hi")
+                var n = arg.baz, n = [ b = 42 ];
+        }(--b);
+        console.log(b);
+    }
+    expect: {
+        var b = 10;
+        !function(arg) {
+            for (var key in "hi") {
+                arg.baz, b = 42;
+            }
+        }(--b);
+        console.log(b);
+    }
+    expect_exact: "42"
+}

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