Drop the unneeded noIndent function param.

This commit is contained in:
Logan Smyth 2016-04-25 22:47:00 -07:00
parent f566700657
commit 22e2c88269
5 changed files with 18 additions and 26 deletions

View File

@ -213,8 +213,7 @@ export default class Buffer {
}
this.removeLast(" ");
this._removeSpacesAfterLastNewline();
this.push(repeat("\n", i), true /* noIndent */);
this.push(repeat("\n", i));
}
/**
@ -271,10 +270,10 @@ export default class Buffer {
* Push a string to the buffer, maintaining indentation and newlines.
*/
push(str: string, noIndent?: boolean) {
if (!this.format.compact && this._indent && !noIndent && str !== "\n") {
push(str: string) {
if (!this.format.compact && this._indent && str[0] !== "\n") {
// we've got a newline before us so prepend on the indentation
if (this.endsWith("\n")) this.push(this.getIndent(), true /* noIndent */);
if (this.endsWith("\n")) str = this.getIndent() + str;
}
// see startTerminatorless() instance method
@ -290,7 +289,7 @@ export default class Buffer {
if (cha === "\n" || cha === "/") {
// we're going to break this terminator expression so we need to add a parentheses
this.push("(", true /* noIndent */);
str = "(" + str;
this.indent();
parenPushNewlineState.printed = true;
}

View File

@ -35,7 +35,7 @@ export function JSXExpressionContainer(node: Object) {
}
export function JSXText(node: Object) {
this.push(node.value, true);
this.push(node.value);
}
export function JSXElement(node: Object) {

View File

@ -3,24 +3,25 @@ export function TaggedTemplateExpression(node: Object) {
this.print(node.quasi, node);
}
export function TemplateElement(node: Object) {
this.push(node.value.raw, true/* noIndent */);
export function TemplateElement(node: Object, parent: Object) {
const isFirst = parent.quasis[0] === node;
const isLast = parent.quasis[parent.quasis.length - 1] === node;
let value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${");
if (!isFirst) this.push(" ");
this.push(value);
if (!isLast) this.push(" ");
}
export function TemplateLiteral(node: Object) {
this.push("`");
let quasis = node.quasis;
for (let i = 0; i < quasis.length; i++) {
this.print(quasis[i], node);
if (i + 1 < quasis.length) {
this.push("${ ", true /* noIndent */);
this.print(node.expressions[i], node);
this.push(" }");
}
}
this.push("`", true /* noIndent */);
}

View File

@ -125,9 +125,7 @@ export function NullLiteral() {
export function NumericLiteral(node: Object) {
let raw = this.getPossibleRaw(node);
if (raw != null) {
// Write an empty string to add indentation on just this first time.
this.push("");
this.push(raw, true /* noIndent */);
this.push(raw);
return;
}
@ -137,9 +135,7 @@ export function NumericLiteral(node: Object) {
export function StringLiteral(node: Object, parent: Object) {
let raw = this.getPossibleRaw(node);
if (raw != null) {
// Write an empty string to add indentation on just this first time.
this.push("");
this.push(raw, true /* noIndent */);
this.push(raw);
return;
}

View File

@ -287,10 +287,6 @@ export default class Printer extends Buffer {
val = val.replace(/\n/g, `\n${repeat(" ", indent)}`);
}
if (column === 0) {
val = this.getIndent() + val;
}
// force a newline for line comments when retainLines is set in case the next printed node
// doesn't catch up
if ((this.format.compact || this.format.concise || this.format.retainLines) &&
@ -299,7 +295,7 @@ export default class Printer extends Buffer {
}
//
this.push(val, true /* noIndent */);
this.push(val);
// whitespace after
this.newline(this.whitespace.getNewlinesAfter(comment));