diff options
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/loops.js | 44 |
2 files changed, 44 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index f0f3d09b..fd839fa1 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -810,7 +810,7 @@ merge(Compressor.prototype, { CHANGED = true; } else if (stat instanceof AST_For - && prev instanceof AST_Definitions + && prev instanceof AST_Var && (!stat.init || stat.init.TYPE == prev.TYPE)) { CHANGED = true; a.pop(); diff --git a/test/compress/loops.js b/test/compress/loops.js index 91aa1c5f..78f618aa 100644 --- a/test/compress/loops.js +++ b/test/compress/loops.js @@ -144,4 +144,46 @@ parse_do_while_without_semicolon: { expect: { do x(); while (false);y(); } -}
\ No newline at end of file +} + + +keep_collapse_const_in_own_block_scope: { + options = { + join_vars: true, + loops: true + } + input: { + var i=2; + const c=5; + while(i--) + console.log(i); + console.log(c); + } + expect: { + var i=2; + const c=5; + for(;i--;) + console.log(i); + console.log(c); + } +} + +keep_collapse_const_in_own_block_scope_2: { + options = { + join_vars: true, + loops: true + } + input: { + const c=5; + var i=2; // Moves to loop, while it did not in previous test + while(i--) + console.log(i); + console.log(c); + } + expect: { + const c=5; + for(var i=2;i--;) + console.log(i); + console.log(c); + } +} |