an AST_If is too a StatementWithBody
This commit is contained in:
@@ -286,16 +286,16 @@ var AST_Continue = DEFNODE("Continue", null, {
|
||||
|
||||
/* -----[ 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 ]----- */
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ function Compressor(options, false_by_default) {
|
||||
SQUEEZE(AST_If, function(self, compressor){
|
||||
self = self.clone();
|
||||
self.condition = self.condition.squeeze(compressor);
|
||||
self.consequent = self.consequent.squeeze(compressor);
|
||||
self.body = self.body.squeeze(compressor);
|
||||
if (self.alternative)
|
||||
self.alternative = self.alternative.squeeze(compressor);
|
||||
return self;
|
||||
|
||||
@@ -447,6 +447,10 @@ function OutputStream(options) {
|
||||
});
|
||||
};
|
||||
|
||||
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();
|
||||
@@ -476,7 +480,7 @@ function OutputStream(options) {
|
||||
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();
|
||||
@@ -492,7 +496,7 @@ function OutputStream(options) {
|
||||
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");
|
||||
@@ -517,7 +521,7 @@ function OutputStream(options) {
|
||||
}
|
||||
});
|
||||
output.space();
|
||||
force_statement(self.body, output);
|
||||
self._do_print_body(output);
|
||||
});
|
||||
DEFPRINT(AST_ForIn, function(self, output){
|
||||
output.print("for");
|
||||
@@ -530,7 +534,7 @@ function OutputStream(options) {
|
||||
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");
|
||||
@@ -539,7 +543,7 @@ function OutputStream(options) {
|
||||
self.expression.print(output);
|
||||
});
|
||||
output.space();
|
||||
force_statement(self.body, output);
|
||||
self._do_print_body(output);
|
||||
});
|
||||
|
||||
/* -----[ functions ]----- */
|
||||
@@ -606,22 +610,22 @@ function OutputStream(options) {
|
||||
// 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;
|
||||
@@ -631,7 +635,7 @@ function OutputStream(options) {
|
||||
}
|
||||
else break;
|
||||
}
|
||||
self.consequent.print(output);
|
||||
self.body.print(output);
|
||||
};
|
||||
DEFPRINT(AST_If, function(self, output){
|
||||
output.print("if");
|
||||
@@ -647,7 +651,7 @@ function OutputStream(options) {
|
||||
output.space();
|
||||
self.alternative.print(output);
|
||||
} else {
|
||||
force_statement(self.consequent, output);
|
||||
self._do_print_body(output);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -999,7 +999,7 @@ function parse($TEXT, exigent_mode) {
|
||||
}
|
||||
return new AST_If({
|
||||
condition : cond,
|
||||
consequent : body,
|
||||
body : body,
|
||||
alternative : belse
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user