aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-04-08 19:10:56 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-04-08 19:10:56 -0700
commitc0fdf61aafb9914f9415f3ce85fa9c1d9b16f115 (patch)
tree66b2b82c7dd6621669ca9e78a134441adf25dc14 /tools/js-optimizer.js
parentd93fd8156ba2530d5ff12caaf9b0eaf557f60de5 (diff)
do not eliminate loop vars if there are non-loop vars in the else that are influenced by the loop var or the helper
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 086ed30e..e75ff317 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -3550,6 +3550,25 @@ function eliminate(ast, memSafe) {
}
}
}
+ // remove loop vars that are used in the rest of the else
+ for (var i = 0; i < assigns.length; i++) {
+ if (assigns[i][0] === 'stat' && assigns[i][1][0] === 'assign') {
+ var assign = assigns[i][1];
+ if (!(assign[1] === true && assign[2][0] === 'name' && assign[3][0] === 'name') || loopers.indexOf(assign[2][1]) < 0) {
+ // this is not one of the loop assigns
+ traverse(assign, function(node, type) {
+ if (type === 'name') {
+ var index = loopers.indexOf(node[1]);
+ if (index < 0) index = helpers.indexOf(node[1]);
+ if (index >= 0) {
+ loopers.splice(index, 1);
+ helpers.splice(index, 1);
+ }
+ }
+ });
+ }
+ }
+ }
if (loopers.length === 0) return;
for (var l = 0; l < loopers.length; l++) {
var looper = loopers[l];