better whitespace for VariableDeclarations

This commit is contained in:
Sebastian McKenzie
2015-01-19 22:09:05 +11:00
parent 857abf5024
commit 4a1addc558
2 changed files with 9 additions and 8 deletions

View File

@@ -169,20 +169,19 @@ exports.DebuggerStatement = function () {
exports.VariableDeclaration = function (node, print, parent) {
this.push(node.kind + " ");
var inits = 0;
var noInits = 0;
var hasInits = false;
// don't add whitespace to loop heads
if (!t.isFor(parent)) {
for (var i = 0; i < node.declarations.length; i++) {
if (node.declarations[i].init) {
inits++;
} else {
noInits++;
// has an init so let's split it up over multiple lines
hasInits = true;
}
}
}
var sep = ",";
if (inits > noInits) { // more inits than no inits so let's add a newline
if (hasInits) {
sep += "\n" + util.repeat(node.kind.length + 1);
} else {
sep += " ";