diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 623f068899272..3326de196896b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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]; } diff --git a/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.js b/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.js new file mode 100644 index 0000000000000..55b410e34dc21 --- /dev/null +++ b/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.js @@ -0,0 +1,22 @@ +//// [commentWithUnreasonableIndentationLevel01.ts] +// Repro from #41223 + +/** + * This is a comment with dumb indentation for some auto-generated thing. + */ +export class SomeAutoGeneratedThing {} + +//// [commentWithUnreasonableIndentationLevel01.js] +"use strict"; +// Repro from #41223 +exports.__esModule = true; +exports.SomeAutoGeneratedThing = void 0; +/** + * This is a comment with dumb indentation for some auto-generated thing. + */ +var SomeAutoGeneratedThing = /** @class */ (function () { + function SomeAutoGeneratedThing() { + } + return SomeAutoGeneratedThing; +}()); +exports.SomeAutoGeneratedThing = SomeAutoGeneratedThing; diff --git a/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.symbols b/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.symbols new file mode 100644 index 0000000000000..41a9e2db6c24a --- /dev/null +++ b/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts === +// Repro from #41223 + +/** + * This is a comment with dumb indentation for some auto-generated thing. + */ +export class SomeAutoGeneratedThing {} +>SomeAutoGeneratedThing : Symbol(SomeAutoGeneratedThing, Decl(commentWithUnreasonableIndentationLevel01.ts, 0, 0)) + diff --git a/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.types b/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.types new file mode 100644 index 0000000000000..10de2478a7d0d --- /dev/null +++ b/tests/baselines/reference/commentWithUnreasonableIndentationLevel01.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts === +// Repro from #41223 + +/** + * This is a comment with dumb indentation for some auto-generated thing. + */ +export class SomeAutoGeneratedThing {} +>SomeAutoGeneratedThing : SomeAutoGeneratedThing + diff --git a/tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts b/tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts new file mode 100644 index 0000000000000..18f0996477e97 --- /dev/null +++ b/tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts @@ -0,0 +1,7 @@ + +// Repro from #41223 + +/** + * This is a comment with dumb indentation for some auto-generated thing. + */ +export class SomeAutoGeneratedThing {} \ No newline at end of file