diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-14 22:31:06 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-14 22:31:06 -0800 |
commit | c9799044984c5200d84bce9e5902250e92ed43ed (patch) | |
tree | eb9f381556f95b61ab4b43c3cbf26f0a300fc6dc /tools | |
parent | 4f03b02970575775eefa6856b8d04be9e5a11a8b (diff) |
refactor hoistMultiples shell for clarity
Diffstat (limited to 'tools')
-rw-r--r-- | tools/js-optimizer.js | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 9e400518..30ca2fed 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -911,23 +911,13 @@ function hoistMultiples(ast) { var post = statements[i+1]; // Look into some block types. shell() will then recreate the shell that we looked into var postInner = post; - var shell = function(x) { return x }; + var shellLabel = false, shellDo = false; while (true) { - /*if (postInner[0] == 'block') { - postInner = postInner[1][0]; - } else */if (postInner[0] == 'label') { - shell = (function(oldShell, oldPostInner) { - return function(x) { - return oldShell(['label', oldPostInner[1], x]); - }; - })(shell, postInner); + if (postInner[0] == 'label') { + shellLabel = postInner[1]; postInner = postInner[2]; } else if (postInner[0] == 'do') { - shell = (function(oldShell, oldPostInner) { - return function(x) { - return oldShell(['do', copy(oldPostInner[1]), ['block', [x]]]); - } - })(shell, postInner);; + shellDo = postInner[1]; postInner = postInner[2][1][0]; } else { break; // give up @@ -960,7 +950,12 @@ function hoistMultiples(ast) { postInner = postInner[3]; // Proceed to look in the else clause } if (modifiedI) { - statements[i] = shell(pre); + if (shellDo) { + statements[i] = ['do', shellDo, ['block', [statements[i]]]]; + } + if (shellLabel) { + statements[i] = ['label', shellLabel, statements[i]]; + } } } if (modified) return node; |