aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-15 10:54:59 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-15 10:54:59 +0300
commit86c14d0988960b5fc52551f143f0ae4361794b4b (patch)
treeefc560cb369af8688e39341aac33f405d851a40b
parent43fd45154bac89b89330e13bd1f167e2a927a23c (diff)
downloadtracifyjs-86c14d0988960b5fc52551f143f0ae4361794b4b.tar.gz
tracifyjs-86c14d0988960b5fc52551f143f0ae4361794b4b.zip
join_vars:
var XXX; for (var YYY; ...) ==> for (var XXX,YYY; ...)
-rw-r--r--lib/compress.js16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 369094ee..96047291 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -327,7 +327,21 @@ function Compressor(options, false_by_default) {
if (stat instanceof AST_Definitions && prev && prev.TYPE == stat.TYPE) {
prev.definitions = prev.definitions.concat(stat.definitions);
CHANGED = true;
- } else {
+ }
+ else if (stat instanceof AST_For
+ && prev instanceof AST_Definitions
+ && (!stat.init || stat.init.TYPE == prev.TYPE)) {
+ CHANGED = true;
+ a.pop();
+ if (stat.init) {
+ stat.init.definitions = prev.definitions.concat(stat.init.definitions);
+ } else {
+ stat.init = prev;
+ }
+ a.push(stat);
+ prev = stat;
+ }
+ else {
prev = stat;
a.push(stat);
}