some cleanup
This commit is contained in:
@@ -189,7 +189,6 @@ function Compressor(options, false_by_default) {
|
|||||||
}
|
}
|
||||||
if (compressor.option("sequences")) {
|
if (compressor.option("sequences")) {
|
||||||
statements = sequencesize(statements, compressor);
|
statements = sequencesize(statements, compressor);
|
||||||
statements = sequencesize_2(statements, compressor);
|
|
||||||
}
|
}
|
||||||
if (compressor.option("if_return")) {
|
if (compressor.option("if_return")) {
|
||||||
statements = handle_if_return(statements, compressor);
|
statements = handle_if_return(statements, compressor);
|
||||||
@@ -348,73 +347,51 @@ function Compressor(options, false_by_default) {
|
|||||||
else push_seq(), ret.push(stat);
|
else push_seq(), ret.push(stat);
|
||||||
});
|
});
|
||||||
push_seq();
|
push_seq();
|
||||||
|
ret = sequencesize_2(ret, compressor);
|
||||||
// if the last node is return or throw, we can mix in the
|
|
||||||
// previous sequence which might help reducing the list to
|
|
||||||
// a single statement.
|
|
||||||
var exit = ret[ret.length - 1], prev = ret[ret.length - 2];
|
|
||||||
if (prev instanceof AST_SimpleStatement
|
|
||||||
&& exit instanceof AST_Exit && exit.value) {
|
|
||||||
ret.pop();
|
|
||||||
ret.pop();
|
|
||||||
if (prev.body instanceof AST_Seq) {
|
|
||||||
prev.body.add(exit.value);
|
|
||||||
prev.body = prev.body.optimize(compressor);
|
|
||||||
exit.value = prev.body;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
exit.value = AST_Seq.cons(prev.body, exit.value).optimize(compressor);
|
|
||||||
}
|
|
||||||
ret.push(exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
CHANGED = ret.length != statements.length;
|
CHANGED = ret.length != statements.length;
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
function sequencesize_2(statements, compressor) {
|
function sequencesize_2(statements, compressor) {
|
||||||
|
function cons_seq(right) {
|
||||||
|
ret.pop();
|
||||||
|
var left = prev.body;
|
||||||
|
if (left instanceof AST_Seq) {
|
||||||
|
left.add(right);
|
||||||
|
} else {
|
||||||
|
left = AST_Seq.cons(left, right);
|
||||||
|
}
|
||||||
|
return left.optimize(compressor);
|
||||||
|
};
|
||||||
var ret = [], prev = null;
|
var ret = [], prev = null;
|
||||||
statements.forEach(function(stat){
|
statements.forEach(function(stat){
|
||||||
if (prev) {
|
if (prev) {
|
||||||
if (stat instanceof AST_For && stat.init && !(stat.init instanceof AST_Definitions)) {
|
if (stat instanceof AST_For && stat.init && !(stat.init instanceof AST_Definitions)) {
|
||||||
if (prev.body instanceof AST_Seq) {
|
stat.init = cons_seq(stat.init);
|
||||||
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) {
|
else if (stat instanceof AST_For && !stat.init) {
|
||||||
stat.init = prev.body;
|
stat.init = prev.body;
|
||||||
ret.pop();
|
ret.pop();
|
||||||
}
|
}
|
||||||
else if (stat instanceof AST_If) {
|
else if (stat instanceof AST_If) {
|
||||||
if (prev.body instanceof AST_Seq) {
|
stat.condition = cons_seq(stat.condition);
|
||||||
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) {
|
else if (stat instanceof AST_With) {
|
||||||
if (prev.body instanceof AST_Seq) {
|
stat.expression = cons_seq(stat.expression);
|
||||||
prev.body.add(stat.expression);
|
}
|
||||||
prev.body = prev.body.optimize(compressor);
|
else if (stat instanceof AST_Exit && stat.value) {
|
||||||
stat.expression = prev.body;
|
stat.value = cons_seq(stat.value);
|
||||||
} else {
|
}
|
||||||
stat.expression = AST_Seq.cons(prev.body, stat.expression).optimize(compressor);
|
else if (stat instanceof AST_Exit) {
|
||||||
}
|
stat.value = cons_seq(make_node(AST_Undefined, stat));
|
||||||
ret.pop();
|
}
|
||||||
|
else if (stat instanceof AST_Switch) {
|
||||||
|
stat.expression = cons_seq(stat.expression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.push(stat);
|
ret.push(stat);
|
||||||
prev = stat instanceof AST_SimpleStatement ? stat : null;
|
prev = stat instanceof AST_SimpleStatement ? stat : null;
|
||||||
});
|
});
|
||||||
CHANGED = ret.length != statements.length;
|
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user