[Pkg-javascript-commits] [uglifyjs] 82/190: Fix hoisting the var in ForIn

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:15 UTC 2016


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

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit fe4e9f9d97dcc6594a8fc49e04630aa619ff1866
Author: Mihai Bazon <mihai.bazon at gmail.com>
Date:   Tue Jan 5 13:56:52 2016 +0200

    Fix hoisting the var in ForIn
    
    Close #913
---
 lib/compress.js            |  5 ++++-
 test/compress/issue-913.js | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 44e1979..1f5988f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1276,7 +1276,10 @@ merge(Compressor.prototype, {
                             var seq = node.to_assignments();
                             var p = tt.parent();
                             if (p instanceof AST_ForIn && p.init === node) {
-                                if (seq == null) return node.definitions[0].name;
+                                if (seq == null) {
+                                    var def = node.definitions[0].name;
+                                    return make_node(AST_SymbolRef, def, def);
+                                }
                                 return seq;
                             }
                             if (p instanceof AST_For && p.init === node) {
diff --git a/test/compress/issue-913.js b/test/compress/issue-913.js
new file mode 100644
index 0000000..9d34d9d
--- /dev/null
+++ b/test/compress/issue-913.js
@@ -0,0 +1,20 @@
+keep_var_for_in: {
+    options = {
+        hoist_vars: true,
+        unused: true
+    };
+    input: {
+        (function(obj){
+            var foo = 5;
+            for (var i in obj)
+                return foo;
+        })();
+    }
+    expect: {
+        (function(obj){
+            var i, foo = 5;
+            for (i in obj)
+                return foo;
+        })();
+    }
+}

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