/* -----[ IF ]----- */
-var AST_If = DEFNODE("If", "condition consequent alternative", {
+var AST_If = DEFNODE("If", "condition alternative", {
$documentation: "A `if` statement",
_walk: function(visitor) {
return visitor._visit(this, function(){
this.condition._walk(visitor);
- this.consequent._walk(visitor);
+ this.body._walk(visitor);
if (this.alternative) this.alternative._walk(visitor);
});
}
-});
+}, AST_StatementWithBody);
/* -----[ SWITCH ]----- */
});
};
+ AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output){
+ force_statement(this.body, output);
+ });
+
DEFPRINT(AST_Statement, function(self, output){
self.body.print(output);
output.semicolon();
DEFPRINT(AST_Do, function(self, output){
output.print("do");
output.space();
- force_statement(self.body, output);
+ self._do_print_body(output);
output.space();
output.print("while");
output.space();
self.condition.print(output);
});
output.space();
- force_statement(self.body, output);
+ self._do_print_body(output);
});
DEFPRINT(AST_For, function(self, output){
output.print("for");
}
});
output.space();
- force_statement(self.body, output);
+ self._do_print_body(output);
});
DEFPRINT(AST_ForIn, function(self, output){
output.print("for");
self.object.print(output);
});
output.space();
- force_statement(self.body, output);
+ self._do_print_body(output);
});
DEFPRINT(AST_With, function(self, output){
output.print("with");
self.expression.print(output);
});
output.space();
- force_statement(self.body, output);
+ self._do_print_body(output);
});
/* -----[ functions ]----- */
// IF *without* an ELSE block (then the outer ELSE would refer
// to the inner IF). This function checks for this case and
// adds the block brackets if needed.
- if (!self.consequent)
+ if (!self.body)
return output.semicolon();
- if (self.consequent instanceof AST_Do
+ if (self.body instanceof AST_Do
&& output.option("ie_proof")) {
// https://github.com/mishoo/UglifyJS/issues/#issue/57 IE
// croaks with "syntax error" on code like this: if (foo)
// do ... while(cond); else ... we need block brackets
// around do/while
- make_block(self.consequent, output);
+ make_block(self.body, output);
return;
}
- var b = self.consequent;
+ var b = self.body;
while (true) {
if (b instanceof AST_If) {
if (!b.alternative) {
- make_block(self.consequent, output);
+ make_block(self.body, output);
return;
}
b = b.alternative;
}
else break;
}
- self.consequent.print(output);
+ self.body.print(output);
};
DEFPRINT(AST_If, function(self, output){
output.print("if");
output.space();
self.alternative.print(output);
} else {
- force_statement(self.consequent, output);
+ self._do_print_body(output);
}
});