mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 14:34:35 -06:00
Combine repeatString helper functions (#21235)
This commit is contained in:
parent
f96dc84a70
commit
e248d08e4c
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user