generator: dry up ForXStatements and *Statements
This commit is contained in:
parent
96b08bf7df
commit
19b115c76b
@ -62,15 +62,6 @@ exports.MethodDefinition = function (node, print) {
|
||||
this._method(node, print);
|
||||
};
|
||||
|
||||
exports.ReturnStatement = function (node, print) {
|
||||
this.push("return");
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
print(node.argument);
|
||||
}
|
||||
this.semicolon();
|
||||
};
|
||||
|
||||
exports.FunctionDeclaration =
|
||||
exports.FunctionExpression = function (node, print) {
|
||||
this.push("function");
|
||||
|
||||
@ -52,25 +52,20 @@ exports.WhileStatement = function (node, print) {
|
||||
print.block(node.body);
|
||||
};
|
||||
|
||||
exports.ForInStatement = function (node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
print(node.left);
|
||||
this.push(" in ");
|
||||
print(node.right);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
var buildForXStatement = function (op) {
|
||||
return function (node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
print(node.left);
|
||||
this.push(" " + op + " ");
|
||||
print(node.right);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
};
|
||||
|
||||
exports.ForOfStatement = function (node, print) {
|
||||
this.keyword("for");
|
||||
this.push("(");
|
||||
print(node.left);
|
||||
this.push(" of ");
|
||||
print(node.right);
|
||||
this.push(")");
|
||||
print.block(node.body);
|
||||
};
|
||||
exports.ForInStatement = buildForXStatement("in");
|
||||
exports.ForOfStatement = buildForXStatement("of");
|
||||
|
||||
exports.DoWhileStatement = function (node, print) {
|
||||
this.keyword("do");
|
||||
@ -82,23 +77,23 @@ exports.DoWhileStatement = function (node, print) {
|
||||
this.push(");");
|
||||
};
|
||||
|
||||
exports.BreakStatement = function (node, print) {
|
||||
this.push("break");
|
||||
if (node.label) {
|
||||
this.space();
|
||||
print(node.label);
|
||||
}
|
||||
this.semicolon();
|
||||
var buildLabelStatement = function (prefix, key) {
|
||||
return function (node, print) {
|
||||
this.push(prefix);
|
||||
|
||||
var label = node[key || "label"];
|
||||
if (label) {
|
||||
this.space();
|
||||
print(label);
|
||||
}
|
||||
|
||||
this.semicolon();
|
||||
};
|
||||
};
|
||||
|
||||
exports.ContinueStatement = function (node, print) {
|
||||
this.push("continue");
|
||||
if (node.label) {
|
||||
this.space();
|
||||
print(node.label);
|
||||
}
|
||||
this.semicolon();
|
||||
};
|
||||
exports.ContinueStatement = buildLabelStatement("continue");
|
||||
exports.ReturnStatement = buildLabelStatement("return", "argument");
|
||||
exports.BreakStatement = buildLabelStatement("break");
|
||||
|
||||
exports.LabeledStatement = function (node, print) {
|
||||
print(node.label);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user