}
var ab = aborts(stat.body);
- var lct = ab instanceof AST_LoopControl ? compressor.loopcontrol_target(ab.label) : null;
+ var lct = ab instanceof AST_LoopControl ? compressor.loopcontrol_target(ab) : null;
if (ab && ((ab instanceof AST_Return && !ab.value && in_lambda)
|| (ab instanceof AST_Continue && self === loop_body(lct))
|| (ab instanceof AST_Break && lct instanceof AST_BlockStatement && self === lct))) {
}
var ab = aborts(stat.alternative);
- var lct = ab instanceof AST_LoopControl ? compressor.loopcontrol_target(ab.label) : null;
+ var lct = ab instanceof AST_LoopControl ? compressor.loopcontrol_target(ab) : null;
if (ab && ((ab instanceof AST_Return && !ab.value && in_lambda)
|| (ab instanceof AST_Continue && self === loop_body(lct))
|| (ab instanceof AST_Break && lct instanceof AST_BlockStatement && self === lct))) {
extract_declarations_from_unreachable_code(compressor, stat, a);
} else {
if (stat instanceof AST_LoopControl) {
- var lct = compressor.loopcontrol_target(stat.label);
+ var lct = compressor.loopcontrol_target(stat);
if ((stat instanceof AST_Break
&& !(lct instanceof AST_IterationStatement)
&& loop_body(lct) === self) || (stat instanceof AST_Continue
OPT(AST_LabeledStatement, function(self, compressor){
if (self.body instanceof AST_Break
- && compressor.loopcontrol_target(self.body.label) === self.body) {
+ && compressor.loopcontrol_target(self.body) === self.body) {
return make_node(AST_EmptyStatement, self);
}
return self.label.references.length == 0 ? self.body : self;
return make_node(AST_For, self, {
body: self.body
});
- } else if (compressor.option("dead_code") && self instanceof AST_While) {
+ }
+ if (compressor.option("dead_code") && self instanceof AST_While) {
var a = [];
extract_declarations_from_unreachable_code(compressor, self.body, a);
return make_node(AST_BlockStatement, self, { body: a });
- } else {
- cond = make_node_from_constant(cond, self.condition).transform(compressor);
- self.condition = best_of_expression(cond, self.condition);
+ }
+ if (self instanceof AST_Do) {
+ var has_loop_control = false;
+ var tw = new TreeWalker(function(node) {
+ if (node instanceof AST_Scope || has_loop_control) return true;
+ if (node instanceof AST_LoopControl && tw.loopcontrol_target(node) === self)
+ return has_loop_control = true;
+ });
+ self.walk(tw);
+ if (!has_loop_control) return self.body;
}
}
if (self instanceof AST_While) {
var first = self.body instanceof AST_BlockStatement ? self.body.body[0] : self.body;
if (first instanceof AST_If) {
if (first.body instanceof AST_Break
- && compressor.loopcontrol_target(first.body.label) === compressor.self()) {
+ && compressor.loopcontrol_target(first.body) === compressor.self()) {
if (self.condition) {
self.condition = make_node(AST_Binary, self.condition, {
left: self.condition,
drop_it(first.alternative);
}
else if (first.alternative instanceof AST_Break
- && compressor.loopcontrol_target(first.alternative.label) === compressor.self()) {
+ && compressor.loopcontrol_target(first.alternative) === compressor.self()) {
if (self.condition) {
self.condition = make_node(AST_Binary, self.condition, {
left: self.condition,
self.body = body;
while (branch = body[body.length - 1]) {
var stat = branch.body[branch.body.length - 1];
- if (stat instanceof AST_Break && compressor.loopcontrol_target(stat.label) === self)
+ if (stat instanceof AST_Break && compressor.loopcontrol_target(stat) === self)
branch.body.pop();
if (branch.body.length || branch instanceof AST_Case
&& (default_branch || branch.expression.has_side_effects(compressor))) break;
if (has_break
|| node instanceof AST_Lambda
|| node instanceof AST_SimpleStatement) return true;
- if (node instanceof AST_Break && tw.loopcontrol_target(node.label) === self)
+ if (node instanceof AST_Break && tw.loopcontrol_target(node) === self)
has_break = true;
});
self.walk(tw);