fix output for certain edge cases
the statements if, for, do, while and with might have an AST_EmptyStatement as body; if that's the case, we need to make sure that the semicolon gets in the output.
This commit is contained in:
@@ -144,6 +144,11 @@ function OutputStream(options) {
|
||||
might_need_semicolon = true;
|
||||
};
|
||||
|
||||
function force_semicolon() {
|
||||
might_need_semicolon = false;
|
||||
print(";");
|
||||
};
|
||||
|
||||
function next_indent() {
|
||||
return indentation + options.indent_level;
|
||||
};
|
||||
@@ -198,6 +203,7 @@ function OutputStream(options) {
|
||||
colon : colon,
|
||||
last : function() { return last },
|
||||
semicolon : semicolon,
|
||||
force_semicolon : force_semicolon,
|
||||
print_name : function(name) { print(make_name(name)) },
|
||||
print_string : function(str) { print(encode_string(str)) },
|
||||
with_indent : with_indent,
|
||||
@@ -398,7 +404,7 @@ function OutputStream(options) {
|
||||
DEFPRINT(AST_Do, function(self, output){
|
||||
output.print("do");
|
||||
output.space();
|
||||
self.body.print(output);
|
||||
force_statement(self.body, output);
|
||||
output.space();
|
||||
output.print("while");
|
||||
output.space();
|
||||
@@ -414,7 +420,7 @@ function OutputStream(options) {
|
||||
self.condition.print(output);
|
||||
});
|
||||
output.space();
|
||||
self.body.print(output);
|
||||
force_statement(self.body, output);
|
||||
});
|
||||
DEFPRINT(AST_For, function(self, output){
|
||||
output.print("for");
|
||||
@@ -439,7 +445,7 @@ function OutputStream(options) {
|
||||
}
|
||||
});
|
||||
output.space();
|
||||
self.body.print(output);
|
||||
force_statement(self.body, output);
|
||||
});
|
||||
DEFPRINT(AST_ForIn, function(self, output){
|
||||
output.print("for");
|
||||
@@ -452,7 +458,7 @@ function OutputStream(options) {
|
||||
self.object.print(output);
|
||||
});
|
||||
output.space();
|
||||
self.body.print(output);
|
||||
force_statement(self.body, output);
|
||||
});
|
||||
DEFPRINT(AST_With, function(self, output){
|
||||
output.print("with");
|
||||
@@ -461,7 +467,7 @@ function OutputStream(options) {
|
||||
self.expression.print(output);
|
||||
});
|
||||
output.space();
|
||||
self.body.print(output);
|
||||
force_statement(self.body, output);
|
||||
});
|
||||
|
||||
/* -----[ functions ]----- */
|
||||
@@ -572,7 +578,7 @@ function OutputStream(options) {
|
||||
output.space();
|
||||
self.alternative.print(output);
|
||||
} else {
|
||||
self.consequent.print(output);
|
||||
force_statement(self.consequent, output);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -832,6 +838,13 @@ function OutputStream(options) {
|
||||
if (self.mods) output.print(self.mods);
|
||||
});
|
||||
|
||||
function force_statement(stat, output) {
|
||||
if (stat instanceof AST_EmptyStatement)
|
||||
output.force_semicolon();
|
||||
else
|
||||
stat.print(output);
|
||||
};
|
||||
|
||||
// return true if the node at the top of the stack (that means the
|
||||
// innermost node in the current output) is lexically the first in
|
||||
// a statement.
|
||||
|
||||
Reference in New Issue
Block a user