generator: implement missing node types

This commit is contained in:
Sebastian McKenzie 2014-10-31 21:23:45 +11:00
parent d376bd3c0e
commit a5a8f08bb8

View File

@ -2,7 +2,12 @@ var _ = require("lodash");
exports.UnaryExpression = function (node, print) {
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);
};
@ -27,8 +32,9 @@ exports.ConditionalExpression = function (node, print) {
};
exports.NewExpression = function (node, print) {
this.push("new ");
this.push("new (");
print(node.callee);
this.push(")");
if (node.arguments) {
this.push("(");
this.printJoin(print, node.arguments, ", ");
@ -36,7 +42,6 @@ exports.NewExpression = function (node, print) {
}
};
exports.SequenceExpression = function (node, print) {
this.printJoin(print, node.expressions, ", ");
};
@ -52,13 +57,6 @@ exports.CallExpression = function (node, print) {
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) {
this.push("yield");
if (node.delegate) this.push("*");
@ -69,17 +67,17 @@ exports.YieldExpression = function (node, print) {
};
exports.EmptyStatement = function () {
this.semicolon();
};
exports.ExpressionStatement = function (node, print) {
print(node.expression);
this.push(";");
this.semicolon();
};
exports.BinaryExpression =
exports.LogicalExpression =
exports.AssignmentExpression = function (node, print) {
exports.AssignmentExpression = function (node, print, parent) {
print(node.left)
this.push(" " + node.operator + " ");
print(node.right);
@ -103,19 +101,29 @@ exports.ParenthesizedExpression = function (node, print) {
};
exports.TaggedTemplateExpression = function (node, print) {
throw new Error("TaggedTemplateExpression");
print(node.tag);
print(node.quasi);
};
exports.TemplateElement = function (node, print) {
throw new Error("TemplateElement");
this.push(node.value.raw);
};
exports.TemplateLiteral = function (node, print) {
this.push("`");
var quasis = node.quasis;
var self = this;
_.each(expr.quasis, function (quasi) {
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("`");