From c72f9d894d5097c1493f4ece9c565fb9791da7c1 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Mon, 26 Jan 2015 18:13:39 +1100 Subject: [PATCH] only use GeneratorBuffer::space if it's for pretty printing so we can drop all spaces easily --- lib/6to5/generation/generators/expressions.js | 4 +++- lib/6to5/generation/generators/jsx.js | 2 +- lib/6to5/generation/generators/methods.js | 9 ++++++--- lib/6to5/generation/generators/statements.js | 19 ++++++++++++------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/6to5/generation/generators/expressions.js b/lib/6to5/generation/generators/expressions.js index 5989e8f8d0..962f7d6389 100644 --- a/lib/6to5/generation/generators/expressions.js +++ b/lib/6to5/generation/generators/expressions.js @@ -112,7 +112,9 @@ exports.LogicalExpression = exports.AssignmentPattern = exports.AssignmentExpression = function (node, print) { print(node.left); - this.push(" " + node.operator + " "); + this.space(); + this.push(node.operator); + this.space(); print(node.right); }; diff --git a/lib/6to5/generation/generators/jsx.js b/lib/6to5/generation/generators/jsx.js index 15bf937e16..e4175839a6 100644 --- a/lib/6to5/generation/generators/jsx.js +++ b/lib/6to5/generation/generators/jsx.js @@ -63,7 +63,7 @@ exports.JSXOpeningElement = function (node, print) { this.push("<"); print(node.name); if (node.attributes.length > 0) { - this.space(); + this.push(" "); print.join(node.attributes, { separator: " " }); } this.push(node.selfClosing ? " />" : ">"); diff --git a/lib/6to5/generation/generators/methods.js b/lib/6to5/generation/generators/methods.js index c812d0e808..0a3caf3a59 100644 --- a/lib/6to5/generation/generators/methods.js +++ b/lib/6to5/generation/generators/methods.js @@ -36,7 +36,7 @@ exports._method = function (node, print) { } this._params(value, print); - this.space(); + this.push(" "); print(value.body); }; @@ -45,8 +45,11 @@ exports.FunctionExpression = function (node, print) { if (node.async) this.push("async "); this.push("function"); if (node.generator) this.push("*"); - this.space(); - if (node.id) print(node.id); + this.push(" "); + if (node.id) { + this.space(); + print(node.id); + } this._params(node, print); this.space(); print(node.body); diff --git a/lib/6to5/generation/generators/statements.js b/lib/6to5/generation/generators/statements.js index 473ce5a18b..55fcfd092e 100644 --- a/lib/6to5/generation/generators/statements.js +++ b/lib/6to5/generation/generators/statements.js @@ -15,12 +15,13 @@ exports.IfStatement = function (node, print) { this.keyword("if"); this.push("("); print(node.test); - this.push(") "); + this.push(")"); + this.space(); print.indentOnComments(node.consequent); if (node.alternate) { - if (this.isLast("}")) this.space(); + if (this.isLast("}")) this.push(" "); this.keyword("else"); print.indentOnComments(node.alternate); } @@ -34,13 +35,13 @@ exports.ForStatement = function (node, print) { this.push(";"); if (node.test) { - this.space(); + this.push(" "); print(node.test); } this.push(";"); if (node.update) { - this.space(); + this.push(" "); print(node.update); } @@ -87,7 +88,7 @@ var buildLabelStatement = function (prefix, key) { var label = node[key || "label"]; if (label) { - this.space(); + this.push(" "); print(label); } @@ -144,7 +145,9 @@ exports.SwitchStatement = function (node, print) { this.keyword("switch"); this.push("("); print(node.discriminant); - this.push(") {"); + this.push(")"); + this.space(); + this.push("{"); print.sequence(node.cases, { indent: true }); this.push("}"); }; @@ -203,7 +206,9 @@ exports.PrivateDeclaration = function (node, print) { exports.VariableDeclarator = function (node, print) { if (node.init) { print(node.id); - this.push(" = "); + this.space(); + this.push("="); + this.space(); print(node.init); } else { print(node.id);