Combine repeatString helper functions (#21235)

This commit is contained in:
Andy
2018-01-17 12:43:41 -08:00
committed by GitHub
parent f96dc84a70
commit e248d08e4c
3 changed files with 16 additions and 25 deletions

View File

@@ -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;
}
}
}

View File

@@ -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