tw.in_loop = this;
push(tw);
this.body.walk(tw);
- if (has_break_or_continue(this, tw.parent())) {
+ if (has_loop_control(this, tw.parent())) {
pop(tw);
push(tw);
}
if (this.condition) this.condition.walk(tw);
this.body.walk(tw);
if (this.step) {
- if (has_break_or_continue(this, tw.parent())) {
+ if (has_loop_control(this, tw.parent())) {
pop(tw);
push(tw);
}
return compressor.option("loops") ? make_node(AST_For, self, self).optimize(compressor) : self;
});
- function has_break_or_continue(loop, parent) {
+ function has_loop_control(loop, parent, type) {
+ if (!type) type = AST_LoopControl;
var found = false;
var tw = new TreeWalker(function(node) {
if (found || node instanceof AST_Scope) return true;
- if (node instanceof AST_LoopControl && tw.loopcontrol_target(node) === loop) {
+ if (node instanceof type && tw.loopcontrol_target(node) === loop) {
return found = true;
}
});
]
})
}).optimize(compressor);
- if (!has_break_or_continue(self, compressor.parent())) {
+ if (!has_loop_control(self, compressor.parent())) {
return make_node(AST_BlockStatement, self.body, {
body: [
self.body,
}).optimize(compressor);
}
}
- if (self.body instanceof AST_BlockStatement) {
+ if (self.body instanceof AST_BlockStatement && !has_loop_control(self, compressor.parent(), AST_Continue)) {
var body = self.body.body;
for (var i = body.length; --i >= 0;) {
var stat = body[i];
if (stat instanceof AST_If
&& !stat.alternative
&& stat.body instanceof AST_Break
- && compressor.loopcontrol_target(stat.body) === compressor.self()) {
+ && compressor.loopcontrol_target(stat.body) === self) {
self.condition = make_node(AST_Binary, self, {
operator: "&&",
left: stat.condition.negate(compressor),