only use needsParens if the node has changed parent

This commit is contained in:
Sebastian McKenzie 2014-11-09 16:28:05 +11:00
parent 8c40db5658
commit e3c6ee5c88

View File

@ -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();