diff --git a/lib/6to5/generation/node.js b/lib/6to5/generation/node.js index 23d260901f..560ba9d9bf 100644 --- a/lib/6to5/generation/node.js +++ b/lib/6to5/generation/node.js @@ -8,6 +8,8 @@ function Node(node, parent) { this.node = node; } +// + Node.whitespace = { FunctionExpression: 1, FunctionStatement: 1, @@ -27,6 +29,29 @@ _.each(Node.whitespace, function (amounts, type) { Node.whitespace[type] = amounts; }); +// + +Node.PRECEDENCE = {}; + +_.each([ + ["||"], + ["&&"], + ["|"], + ["^"], + ["&"], + ["==", "===", "!=", "!=="], + ["<", ">", "<=", ">=", "in", "instanceof"], + [">>", "<<", ">>>"], + ["+", "-"], + ["*", "/", "%"] +], function (tier, i) { + _.each(tier, function (op) { + Node.PRECEDENCE[op] = i; + }); +}); + +// + Node.prototype.needsWhitespace = function (type) { var node = this.node; if (!node) return 0; @@ -109,10 +134,10 @@ Node.prototype.needsParans = function () { if (t.isBinary(parent)) { var parentOp = parent.operator; - var parentPos = t.PRECEDENCE[parentOp]; + var parentPos = Node.PRECEDENCE[parentOp]; var nodeOp = node.operator; - var nodePos = t.PRECEDENCE[nodeOp]; + var nodePos = Node.PRECEDENCE[nodeOp]; if (parentPos > nodePos) { return true;