don't move expressions containing the binary in operator into the for initializer
(opera can't parse it) close #25
This commit is contained in:
@@ -427,12 +427,23 @@ merge(Compressor.prototype, {
|
|||||||
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 = cons_seq(stat.init);
|
var opera = {};
|
||||||
}
|
try {
|
||||||
else if (stat instanceof AST_For && !stat.init) {
|
prev.body.walk(new TreeWalker(function(node){
|
||||||
stat.init = prev.body;
|
if (node instanceof AST_Binary && node.operator == "in")
|
||||||
ret.pop();
|
throw opera;
|
||||||
|
}));
|
||||||
|
if (stat.init && !(stat.init instanceof AST_Definitions)) {
|
||||||
|
stat.init = cons_seq(stat.init);
|
||||||
|
}
|
||||||
|
else if (!stat.init) {
|
||||||
|
stat.init = prev.body;
|
||||||
|
ret.pop();
|
||||||
|
}
|
||||||
|
} catch(ex) {
|
||||||
|
if (ex !== opera) throw ex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (stat instanceof AST_If) {
|
else if (stat instanceof AST_If) {
|
||||||
stat.condition = cons_seq(stat.condition);
|
stat.condition = cons_seq(stat.condition);
|
||||||
|
|||||||
@@ -127,3 +127,35 @@ lift_sequences_4: {
|
|||||||
x = baz;
|
x = baz;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for_sequences: {
|
||||||
|
options = { sequences: true };
|
||||||
|
input: {
|
||||||
|
// 1
|
||||||
|
foo();
|
||||||
|
bar();
|
||||||
|
for (; false;);
|
||||||
|
// 2
|
||||||
|
foo();
|
||||||
|
bar();
|
||||||
|
for (x = 5; false;);
|
||||||
|
// 3
|
||||||
|
x = (foo in bar);
|
||||||
|
for (; false;);
|
||||||
|
// 4
|
||||||
|
x = (foo in bar);
|
||||||
|
for (y = 5; false;);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
// 1
|
||||||
|
for (foo(), bar(); false;);
|
||||||
|
// 2
|
||||||
|
for (foo(), bar(), x = 5; false;);
|
||||||
|
// 3
|
||||||
|
x = (foo in bar);
|
||||||
|
for (; false;);
|
||||||
|
// 4
|
||||||
|
x = (foo in bar);
|
||||||
|
for (y = 5; false;);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user