diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 84bf3bb1752..df870034270 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1535,8 +1535,8 @@ Actual: ${stringify(fullActual)}`); const addSpanInfoString = () => { if (previousSpanInfo) { resultString += currentLine; - let thisLineMarker = repeatString(startColumn, " ") + repeatString(length, "~"); - thisLineMarker += repeatString(this.alignmentForExtraInfo - thisLineMarker.length - prefixString.length + 1, " "); + let thisLineMarker = ts.repeatString(" ", startColumn) + ts.repeatString("~", length); + thisLineMarker += ts.repeatString(" ", this.alignmentForExtraInfo - thisLineMarker.length - prefixString.length + 1); resultString += thisLineMarker; resultString += "=> Pos: (" + (pos - length) + " to " + (pos - 1) + ") "; resultString += " " + previousSpanInfo; @@ -1551,7 +1551,7 @@ Actual: ${stringify(fullActual)}`); if (resultString.length) { resultString += "\n--------------------------------"; } - currentLine = "\n" + nextLine.toString() + repeatString(3 - nextLine.toString().length, " ") + ">" + this.activeFile.content.substring(pos, fileLineMap[nextLine]) + "\n "; + currentLine = "\n" + nextLine.toString() + ts.repeatString(" ", 3 - nextLine.toString().length) + ">" + this.activeFile.content.substring(pos, fileLineMap[nextLine]) + "\n "; startColumn = 0; length = 0; } @@ -2787,7 +2787,7 @@ Actual: ${stringify(fullActual)}`); const items = this.languageService.getNavigationBarItems(this.activeFile.fileName); Harness.IO.log(`Navigation bar (${items.length} items)`); for (const item of items) { - Harness.IO.log(`${repeatString(item.indent, " ")}name: ${item.text}, kind: ${item.kind}, childItems: ${item.childItems.map(child => child.text)}`); + Harness.IO.log(`${ts.repeatString(" ", item.indent)}name: ${item.text}, kind: ${item.kind}, childItems: ${item.childItems.map(child => child.text)}`); } } @@ -3689,14 +3689,6 @@ ${code} }; } - function repeatString(count: number, char: string) { - let result = ""; - for (let i = 0; i < count; i++) { - result += char; - } - return result; - } - function stringify(data: any, replacer?: (key: string, value: any) => any): string { return JSON.stringify(data, replacer, 2); } diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 49fb1420db8..c020e638692 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -1277,13 +1277,13 @@ namespace ts.formatting { } if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat("\t", tabs); + internedTabsIndentation[tabs] = tabString = repeatString("\t", tabs); } else { tabString = internedTabsIndentation[tabs]; } - return spaces ? tabString + repeat(" ", spaces) : tabString; + return spaces ? tabString + repeatString(" ", spaces) : tabString; } else { let spacesString: string; @@ -1294,23 +1294,14 @@ namespace ts.formatting { } if (internedSpacesIndentation[quotient] === undefined) { - spacesString = repeat(" ", options.indentSize * quotient); + spacesString = repeatString(" ", options.indentSize * quotient); internedSpacesIndentation[quotient] = spacesString; } else { spacesString = internedSpacesIndentation[quotient]; } - return remainder ? spacesString + repeat(" ", remainder) : spacesString; - } - - function repeat(value: string, count: number): string { - let s = ""; - for (let i = 0; i < count; i++) { - s += value; - } - - return s; + return remainder ? spacesString + repeatString(" ", remainder) : spacesString; } } } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index abfe5a7a55d..344a44a9f18 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1110,6 +1110,14 @@ namespace ts { export function getSnapshotText(snap: IScriptSnapshot): string { return snap.getText(0, snap.getLength()); } + + export function repeatString(str: string, count: number): string { + let result = ""; + for (let i = 0; i < count; i++) { + result += str; + } + return result; + } } // Display-part writer helpers