From ff696cd7bc507ad0ffc5444bff39de9b6ad10a7e Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Tue, 2 Oct 2012 12:02:33 +0300 Subject: [PATCH] drop more unused names --- lib/compress.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 14e722d3..86d1ce7c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -863,20 +863,35 @@ merge(Compressor.prototype, { compressor.warn("Dropping unused variable {name} [{file}:{line},{col}]", w); return false; }); - var side_effects = []; + // place uninitialized names at the start def = mergeSort(def, function(a, b){ if (!a.value && b.value) return -1; if (!b.value && a.value) return 1; return 0; }); - while (def.length > 0 && def[def.length - 1]._unused_side_effects) { - side_effects.unshift(def.pop().value); + // for unused names whose initialization has + // side effects, we can cascade the init. code + // into the next one, or next statement. + var side_effects = []; + for (var i = 0; i < def.length;) { + var x = def[i]; + if (x._unused_side_effects) { + side_effects.push(x.value); + def.splice(i, 1); + } else { + if (side_effects.length > 0) { + side_effects.push(x.value); + x.value = AST_Seq.from_array(side_effects); + side_effects = []; + } + ++i; + } } if (side_effects.length > 0) { side_effects = make_node(AST_BlockStatement, node, { - body: side_effects.map(function(ss){ - return make_node(AST_SimpleStatement, ss, { body: ss }); - }) + body: [ make_node(AST_SimpleStatement, node, { + body: AST_Seq.from_array(side_effects) + }) ] }); } else { side_effects = null; -- 2.34.1