diff --git a/lib/6to5/generation/generator.js b/lib/6to5/generation/generator.js index 0ee1630016..ef9d8a7d4f 100644 --- a/lib/6to5/generation/generator.js +++ b/lib/6to5/generation/generator.js @@ -215,12 +215,8 @@ CodeGenerator.prototype.print = function (node, parent, opts) { var newline = function (leading) { var ignoreDuplicates = false; - if (!opts.statement) { - if (n.isUserWhitespacable(node, parent)) { - ignoreDuplicates = true; - } else { - return; - } + if (!opts.statement && !n.isUserWhitespacable(node, parent)) { + return; } var lines = 0; @@ -234,7 +230,7 @@ CodeGenerator.prototype.print = function (node, parent, opts) { } } else { // generated node - if (!leading) lines++; // definently include a single line + if (!leading) lines++; // always include at least a single line after var needs = n.needsWhitespaceAfter; if (leading) needs = n.needsWhitespaceBefore; @@ -252,12 +248,14 @@ CodeGenerator.prototype.print = function (node, parent, opts) { if (opts.before) opts.before(); this.map.mark(node, "start"); - var needsParans = node.start == null && n.needsParans(node, parent); - if (needsParans) this.push("("); + // only compute if this node needs parens if our parent has been changed + // since acorn would've wrapped us in a ParanthesizedExpression + var needsParens = parent !== node._parent && n.needsParens(node, parent); + if (needsParens) this.push("("); this[node.type](node, this.buildPrint(node), parent); - if (needsParans) this.push(")"); + if (needsParens) this.push(")"); this.map.mark(node, "end"); if (opts.after) opts.after();