diff --git a/lib/6to5/generators/expressions.js b/lib/6to5/generators/expressions.js index b74612d07c..c7df89f842 100644 --- a/lib/6to5/generators/expressions.js +++ b/lib/6to5/generators/expressions.js @@ -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 self = this; - _.each(expr.quasis, function (quasi) { + var quasis = node.quasis; + 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("`");