only align variable declarations if at least one declarator has an init

This commit is contained in:
Sebastian McKenzie
2015-01-08 00:44:53 +11:00
parent c5cd729c3d
commit a2ed0ea9c5

View File

@@ -157,7 +157,22 @@ exports.DebuggerStatement = function () {
exports.VariableDeclaration = function (node, print, parent) {
this.push(node.kind + " ");
print.join(node.declarations, { separator: ",\n" + this.getIndent(2) });
var hasInits = false;
for (var i in node.declarations) {
if (node.declarations[i].init) {
hasInits = true;
break;
}
}
var sep = ",";
if (hasInits) {
sep += "\n" + this.getIndent(2);
} else {
sep += " ";
}
print.join(node.declarations, { separator: sep });
if (!t.isFor(parent)) {
this.semicolon();