From 4a1addc558db97d3b25e70c4fdfef5fe9a2cbf65 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 19 Jan 2015 22:09:05 +1100 Subject: [PATCH] better whitespace for VariableDeclarations --- lib/6to5/generation/generators/statements.js | 11 +++++------ .../expected.js | 6 ++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/6to5/generation/generators/statements.js b/lib/6to5/generation/generators/statements.js index 6cc66dd255..473ce5a18b 100644 --- a/lib/6to5/generation/generators/statements.js +++ b/lib/6to5/generation/generators/statements.js @@ -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 += " "; diff --git a/test/fixtures/generation/types/VariableDeclaration-VariableDeclarator/expected.js b/test/fixtures/generation/types/VariableDeclaration-VariableDeclarator/expected.js index 86c14e5b1f..487fff2ae2 100644 --- a/test/fixtures/generation/types/VariableDeclaration-VariableDeclarator/expected.js +++ b/test/fixtures/generation/types/VariableDeclaration-VariableDeclarator/expected.js @@ -5,8 +5,10 @@ let foo = "foo"; var foo = "bar"; const foo = "foo"; -let foo, bar = "bar"; -var foo, bar = "bar"; +let foo, + bar = "bar"; +var foo, + bar = "bar"; let foo = "foo", bar = "bar";