Avoid processing indentation for every pushed string.

This commit is contained in:
Logan Smyth 2016-04-25 22:20:31 -07:00
parent 8336aa52e8
commit f566700657
2 changed files with 5 additions and 9 deletions

View File

@ -273,14 +273,8 @@ export default class Buffer {
push(str: string, noIndent?: boolean) {
if (!this.format.compact && this._indent && !noIndent && str !== "\n") {
// we have an indent level and we aren't pushing a newline
let indent = this.getIndent();
// replace all newlines with newlines with the indentation
str = str.replace(/\n/g, `\n${indent}`);
// we've got a newline before us so prepend on the indentation
if (this.endsWith("\n")) this.push(indent, true /* noIndent */);
if (this.endsWith("\n")) this.push(this.getIndent(), true /* noIndent */);
}
// see startTerminatorless() instance method

View File

@ -206,12 +206,14 @@ export function DebuggerStatement() {
function variableDeclarationIdent() {
// "let " or "var " indentation.
this.push(",\n ");
this.push(",\n");
this.push(" ");
}
function constDeclarationIdent() {
// "const " indentation.
this.push(",\n ");
this.push(",\n");
this.push(" ");
}
export function VariableDeclaration(node: Object, parent: Object) {