diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-10-02 12:02:33 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-10-02 12:02:33 +0300 |
commit | ff696cd7bc507ad0ffc5444bff39de9b6ad10a7e (patch) | |
tree | b31df0056b2f0aedbbfac4083ac328b84cb29d88 /lib | |
parent | 9e5dd81f1e98b5c77084e19345191d630576cc44 (diff) | |
download | tracifyjs-ff696cd7bc507ad0ffc5444bff39de9b6ad10a7e.tar.gz tracifyjs-ff696cd7bc507ad0ffc5444bff39de9b6ad10a7e.zip |
drop more unused names
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 27 |
1 files 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; |