diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-09-16 16:29:17 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-09-16 16:29:17 +0300 |
commit | 0f418d654e035b8547340c4d4c03802a01a532b8 (patch) | |
tree | 7b4eba8afd339aaef67e1b88928b65e4fc125641 /lib/compress.js | |
parent | 21c34a17922f826d3c1d1fa230fb08788393f69b (diff) | |
download | tracifyjs-0f418d654e035b8547340c4d4c03802a01a532b8.tar.gz tracifyjs-0f418d654e035b8547340c4d4c03802a01a532b8.zip |
more sequencesizing (WIP)
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 7440a5bd..bd14529b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -189,6 +189,7 @@ function Compressor(options, false_by_default) { } if (compressor.option("sequences")) { statements = sequencesize(statements, compressor); + statements = sequencesize_2(statements, compressor); } if (compressor.option("if_return")) { statements = handle_if_return(statements, compressor); @@ -371,6 +372,52 @@ function Compressor(options, false_by_default) { return ret; }; + function sequencesize_2(statements, compressor) { + var ret = [], prev = null; + statements.forEach(function(stat){ + if (prev) { + if (stat instanceof AST_For && stat.init && !(stat.init instanceof AST_Definitions)) { + if (prev.body instanceof AST_Seq) { + prev.body.add(stat.init); + prev.body = prev.body.optimize(compressor); + stat.init = prev.body; + } else { + stat.init = AST_Seq.cons(prev.body, stat.init).optimize(compressor); + } + ret.pop(); + } + else if (stat instanceof AST_For && !stat.init) { + stat.init = prev.body; + ret.pop(); + } + else if (stat instanceof AST_If) { + if (prev.body instanceof AST_Seq) { + prev.body.add(stat.condition); + prev.body = prev.body.optimize(compressor); + stat.condition = prev.body; + } else { + stat.condition = AST_Seq.cons(prev.body, stat.condition).optimize(compressor); + } + ret.pop(); + } + else if (stat instanceof AST_With) { + if (prev.body instanceof AST_Seq) { + prev.body.add(stat.expression); + prev.body = prev.body.optimize(compressor); + stat.expression = prev.body; + } else { + stat.expression = AST_Seq.cons(prev.body, stat.expression).optimize(compressor); + } + ret.pop(); + } + } + ret.push(stat); + prev = stat instanceof AST_SimpleStatement ? stat : null; + }); + CHANGED = ret.length != statements.length; + return ret; + }; + function join_consecutive_vars(statements, compressor) { var prev = null; return statements.reduce(function(a, stat){ |