only use GeneratorBuffer::space if it's for pretty printing so we can drop all spaces easily

This commit is contained in:
Sebastian McKenzie
2015-01-26 18:13:39 +11:00
parent 59283c1148
commit c72f9d894d
4 changed files with 22 additions and 12 deletions

View File

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

View File

@@ -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 ? " />" : ">");

View File

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

View File

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