Skip to content

Commit 4a34294

Browse files
committed
Unify padding impls and consistently use them
1 parent 77d3a69 commit 4a34294

File tree

4 files changed

+16
-23
lines changed

4 files changed

+16
-23
lines changed

src/compiler/core.ts

+15
Original file line numberDiff line numberDiff line change
@@ -2051,4 +2051,19 @@ namespace ts {
20512051
}
20522052
}
20532053
}
2054+
2055+
export function padLeft(s: string, length: number) {
2056+
while (s.length < length) {
2057+
s = " " + s;
2058+
}
2059+
return s;
2060+
}
2061+
2062+
export function padRight(s: string, length: number) {
2063+
while (s.length < length) {
2064+
s = s + " ";
2065+
}
2066+
2067+
return s;
2068+
}
20542069
}

src/compiler/program.ts

-7
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,6 @@ namespace ts {
383383
return formatStyle + text + resetEscapeSequence;
384384
}
385385

386-
function padLeft(s: string, length: number) {
387-
while (s.length < length) {
388-
s = " " + s;
389-
}
390-
return s;
391-
}
392-
393386
function formatCodeSpan(file: SourceFile, start: number, length: number, indent: string, squiggleColor: ForegroundColorEscapeSequences, host: FormatDiagnosticsHost) {
394387
const { line: firstLine, character: firstLineChar } = getLineAndCharacterOfPosition(file, start);
395388
const { line: lastLine, character: lastLineChar } = getLineAndCharacterOfPosition(file, start + length);

src/executeCommandLine/executeCommandLine.ts

-15
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ namespace ts {
3333
return options.pretty;
3434
}
3535

36-
function padLeft(s: string, length: number) {
37-
while (s.length < length) {
38-
s = " " + s;
39-
}
40-
return s;
41-
}
42-
43-
function padRight(s: string, length: number) {
44-
while (s.length < length) {
45-
s = s + " ";
46-
}
47-
48-
return s;
49-
}
50-
5136
function getOptionsForHelp(commandLine: ParsedCommandLine) {
5237
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
5338
return !!commandLine.options.all ?

src/harness/fourslashImpl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ namespace FourSlash {
15631563
const output: string[] = [];
15641564
for (let lineNumber = contextStart.line; lineNumber <= contextEnd.line; lineNumber++) {
15651565
const spanLine = contextString.substring(contextLineMap[lineNumber], contextLineMap[lineNumber + 1]);
1566-
output.push(lineNumbers ? `${`${lineNumber + 1}: `.padStart(lineNumberPrefixLength, " ")}${spanLine}` : spanLine);
1566+
output.push(lineNumbers ? `${ts.padLeft(`${lineNumber + 1}: `, lineNumberPrefixLength)}${spanLine}` : spanLine);
15671567
if (selection) {
15681568
if (lineNumber < selectionStart.line || lineNumber > selectionEnd.line) {
15691569
continue;

0 commit comments

Comments
 (0)