diff --git a/lib/compress.js b/lib/compress.js index 2cc02e68..ee80901e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1677,10 +1677,9 @@ merge(Compressor.prototype, { } else if (stat instanceof AST_For) { if (prev instanceof AST_Var && (!stat.init || stat.init.TYPE == prev.TYPE)) { if (stat.init) { - stat.init.definitions = prev.definitions.concat(stat.init.definitions); - } else { - stat.init = prev; + prev.definitions = prev.definitions.concat(stat.init.definitions); } + stat.init = prev; statements[j] = stat; CHANGED = true; } else if (defs && stat.init && defs.TYPE == stat.init.TYPE && declarations_only(stat.init)) { diff --git a/test/compress/sequences.js b/test/compress/sequences.js index ccf653cb..3d12fb0b 100644 --- a/test/compress/sequences.js +++ b/test/compress/sequences.js @@ -833,3 +833,29 @@ hoist_decl: { for (y(); 0;) z(); } } + +for_init_var: { + options = { + join_vars: true, + unused: false, + } + input: { + var a = "PASS"; + (function() { + var b = 42; + for (var c = 5; c > 0;) c--; + a = "FAIL"; + var a; + })(); + console.log(a); + } + expect: { + var a = "PASS"; + (function() { + for (var b = 42, c = 5, a; c > 0;) c--; + a = "FAIL"; + })(); + console.log(a); + } + expect_stdout: "PASS" +}