From f56670065727c9451d1aad9150afbca41163d417 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Mon, 25 Apr 2016 22:20:31 -0700 Subject: [PATCH] Avoid processing indentation for every pushed string. --- packages/babel-generator/src/buffer.js | 8 +------- packages/babel-generator/src/generators/statements.js | 6 ++++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/babel-generator/src/buffer.js b/packages/babel-generator/src/buffer.js index 7c0c52efd1..bbbf423a8c 100644 --- a/packages/babel-generator/src/buffer.js +++ b/packages/babel-generator/src/buffer.js @@ -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 diff --git a/packages/babel-generator/src/generators/statements.js b/packages/babel-generator/src/generators/statements.js index caea594d93..7bcc5a57da 100644 --- a/packages/babel-generator/src/generators/statements.js +++ b/packages/babel-generator/src/generators/statements.js @@ -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) {