From: Mihai Bazon Date: Tue, 5 Jan 2016 11:56:52 +0000 (+0200) Subject: Fix hoisting the var in ForIn X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=fe4e9f9d97dcc6594a8fc49e04630aa619ff1866;p=UglifyJS.git Fix hoisting the var in ForIn Close #913 --- diff --git a/lib/compress.js b/lib/compress.js index 44e19799..1f5988f7 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 00000000..9d34d9d9 --- /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; + })(); + } +}