Make 'getIndentString' just use a loop. (#41221)

* Make 'getIndentString' just use a loop.

* Added test.

* Accepted baselines.
This commit is contained in:
Daniel Rosenwasser authored and GitHub committed 2020-10-26 12:19:31 -07:00
1 parent 6c298474e4
commit 3517af8f80
5 files changed
+51 -2

No files matched your search

+4 -2
View File
@@ -3849,8 +3849,10 @@ namespace ts {
const indentStrings: string[] = ["", " "];
export function getIndentString(level: number) {
if (indentStrings[level] === undefined) {
indentStrings[level] = getIndentString(level - 1) + indentStrings[1];
// prepopulate cache
const singleLevel = indentStrings[1];
for (let current = indentStrings.length; current <= level; current++) {
indentStrings.push(indentStrings[current - 1] + singleLevel);
}
return indentStrings[level];
}
@@ -0,0 +1,22 @@
//// [commentWithUnreasonableIndentationLevel01.ts]
// Repro from #41223
/**
Line truncated
*/
export class SomeAutoGeneratedThing {}
//// [commentWithUnreasonableIndentationLevel01.js]
"use strict";
// Repro from #41223
exports.__esModule = true;
exports.SomeAutoGeneratedThing = void 0;
/**
Line truncated
*/
var SomeAutoGeneratedThing = /** @class */ (function () {
function SomeAutoGeneratedThing() {
}
return SomeAutoGeneratedThing;
}());
exports.SomeAutoGeneratedThing = SomeAutoGeneratedThing;
@@ -0,0 +1,9 @@
=== tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts ===
// Repro from #41223
/**
Line truncated
*/
export class SomeAutoGeneratedThing {}
>SomeAutoGeneratedThing : Symbol(SomeAutoGeneratedThing, Decl(commentWithUnreasonableIndentationLevel01.ts, 0, 0))
@@ -0,0 +1,9 @@
=== tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts ===
// Repro from #41223
/**
Line truncated
*/
export class SomeAutoGeneratedThing {}
>SomeAutoGeneratedThing : SomeAutoGeneratedThing
@@ -0,0 +1,7 @@
// Repro from #41223
/**
Line truncated
*/
export class SomeAutoGeneratedThing {}