From 4a34294908bed6701dcba2456ca7ac5eafe0ddff Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 19 Feb 2020 17:21:51 -0800 Subject: [PATCH] Unify padding impls and consistently use them --- src/compiler/core.ts | 15 +++++++++++++++ src/compiler/program.ts | 7 ------- src/executeCommandLine/executeCommandLine.ts | 15 --------------- src/harness/fourslashImpl.ts | 2 +- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 4f9b7bc5798..1e8326621d1 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2051,4 +2051,19 @@ namespace ts { } } } + + export function padLeft(s: string, length: number) { + while (s.length < length) { + s = " " + s; + } + return s; + } + + export function padRight(s: string, length: number) { + while (s.length < length) { + s = s + " "; + } + + return s; + } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c77fa837118..1fdf668f521 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -383,13 +383,6 @@ namespace ts { return formatStyle + text + resetEscapeSequence; } - function padLeft(s: string, length: number) { - while (s.length < length) { - s = " " + s; - } - return s; - } - function formatCodeSpan(file: SourceFile, start: number, length: number, indent: string, squiggleColor: ForegroundColorEscapeSequences, host: FormatDiagnosticsHost) { const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start); const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length); diff --git a/src/executeCommandLine/executeCommandLine.ts b/src/executeCommandLine/executeCommandLine.ts index 65240fbee46..6ce8e90a1df 100644 --- a/src/executeCommandLine/executeCommandLine.ts +++ b/src/executeCommandLine/executeCommandLine.ts @@ -33,21 +33,6 @@ namespace ts { return options.pretty; } - function padLeft(s: string, length: number) { - while (s.length < length) { - s = " " + s; - } - return s; - } - - function padRight(s: string, length: number) { - while (s.length < length) { - s = s + " "; - } - - return s; - } - function getOptionsForHelp(commandLine: ParsedCommandLine) { // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") return !!commandLine.options.all ? diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 3be657d4cd0..4beb2161c26 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -1563,7 +1563,7 @@ namespace FourSlash { const output: string[] = []; for (let lineNumber = contextStart.line; lineNumber <= contextEnd.line; lineNumber++) { const spanLine = contextString.substring(contextLineMap[lineNumber], contextLineMap[lineNumber + 1]); - output.push(lineNumbers ? `${`${lineNumber + 1}: `.padStart(lineNumberPrefixLength, " ")}${spanLine}` : spanLine); + output.push(lineNumbers ? `${ts.padLeft(`${lineNumber + 1}: `, lineNumberPrefixLength)}${spanLine}` : spanLine); if (selection) { if (lineNumber < selectionStart.line || lineNumber > selectionEnd.line) { continue;