generator: implement missing node types
This commit is contained in:
parent
d376bd3c0e
commit
a5a8f08bb8
@ -2,7 +2,12 @@ var _ = require("lodash");
|
|||||||
|
|
||||||
exports.UnaryExpression = function (node, print) {
|
exports.UnaryExpression = function (node, print) {
|
||||||
this.push(node.operator);
|
this.push(node.operator);
|
||||||
if (/[a-z]$/.test(node.operator)) this.push(" ");
|
|
||||||
|
var arg = node.argument;
|
||||||
|
if (/[a-z]$/.test(node.operator) || arg.type === "UpdateExpression" || arg.type === "UnaryExpression") {
|
||||||
|
this.push(" ");
|
||||||
|
}
|
||||||
|
|
||||||
print(node.argument);
|
print(node.argument);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,8 +32,9 @@ exports.ConditionalExpression = function (node, print) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.NewExpression = function (node, print) {
|
exports.NewExpression = function (node, print) {
|
||||||
this.push("new ");
|
this.push("new (");
|
||||||
print(node.callee);
|
print(node.callee);
|
||||||
|
this.push(")");
|
||||||
if (node.arguments) {
|
if (node.arguments) {
|
||||||
this.push("(");
|
this.push("(");
|
||||||
this.printJoin(print, node.arguments, ", ");
|
this.printJoin(print, node.arguments, ", ");
|
||||||
@ -36,7 +42,6 @@ exports.NewExpression = function (node, print) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.SequenceExpression = function (node, print) {
|
exports.SequenceExpression = function (node, print) {
|
||||||
this.printJoin(print, node.expressions, ", ");
|
this.printJoin(print, node.expressions, ", ");
|
||||||
};
|
};
|
||||||
@ -52,13 +57,6 @@ exports.CallExpression = function (node, print) {
|
|||||||
this.push(")");
|
this.push(")");
|
||||||
};
|
};
|
||||||
|
|
||||||
exports._maybeParans = function (node, print) {
|
|
||||||
var is = _.contains(["FunctionExpression", "BinaryExpression", "AssignmentExpression"], node.type);
|
|
||||||
if (is) this.push("(");
|
|
||||||
print(node);
|
|
||||||
if (is) this.push(")");
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.YieldExpression = function (node, print) {
|
exports.YieldExpression = function (node, print) {
|
||||||
this.push("yield");
|
this.push("yield");
|
||||||
if (node.delegate) this.push("*");
|
if (node.delegate) this.push("*");
|
||||||
@ -69,17 +67,17 @@ exports.YieldExpression = function (node, print) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.EmptyStatement = function () {
|
exports.EmptyStatement = function () {
|
||||||
|
this.semicolon();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.ExpressionStatement = function (node, print) {
|
exports.ExpressionStatement = function (node, print) {
|
||||||
print(node.expression);
|
print(node.expression);
|
||||||
this.push(";");
|
this.semicolon();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.BinaryExpression =
|
exports.BinaryExpression =
|
||||||
exports.LogicalExpression =
|
exports.LogicalExpression =
|
||||||
exports.AssignmentExpression = function (node, print) {
|
exports.AssignmentExpression = function (node, print, parent) {
|
||||||
print(node.left)
|
print(node.left)
|
||||||
this.push(" " + node.operator + " ");
|
this.push(" " + node.operator + " ");
|
||||||
print(node.right);
|
print(node.right);
|
||||||
@ -103,19 +101,29 @@ exports.ParenthesizedExpression = function (node, print) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.TaggedTemplateExpression = function (node, print) {
|
exports.TaggedTemplateExpression = function (node, print) {
|
||||||
throw new Error("TaggedTemplateExpression");
|
print(node.tag);
|
||||||
|
print(node.quasi);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.TemplateElement = function (node, print) {
|
exports.TemplateElement = function (node, print) {
|
||||||
throw new Error("TemplateElement");
|
this.push(node.value.raw);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.TemplateLiteral = function (node, print) {
|
exports.TemplateLiteral = function (node, print) {
|
||||||
this.push("`");
|
this.push("`");
|
||||||
|
|
||||||
var self = this;
|
var quasis = node.quasis;
|
||||||
_.each(expr.quasis, function (quasi) {
|
var self = this;
|
||||||
|
var len = quasis.length;
|
||||||
|
|
||||||
|
_.each(quasis, function (quasi, i) {
|
||||||
|
print(quasi);
|
||||||
|
|
||||||
|
if (i + 1 < len) {
|
||||||
|
self.push("${ ");
|
||||||
|
print(node.expressions[i]);
|
||||||
|
self.push(" }");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.push("`");
|
this.push("`");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user