From 12112646ee35f30994c5cdf104105e86892af9ab Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 23 Oct 2020 16:35:48 -0700 Subject: [PATCH 1/3] Make 'getIndentString' just use a loop. --- src/compiler/utilities.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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]; } From 04dce9444ad2cf7d8aeae97c4001ecfcb4a5efc9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 23 Oct 2020 17:41:36 -0700 Subject: [PATCH 2/3] Added test. --- .../compiler/commentWithUnreasonableIndentationLevel01.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/cases/compiler/commentWithUnreasonableIndentationLevel01.ts 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 From 4b8065162ada3ace51f3570a707e486e7139a34a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 23 Oct 2020 17:42:17 -0700 Subject: [PATCH 3/3] Accepted baselines. --- ...mmentWithUnreasonableIndentationLevel01.js | 22 +++++++++++++++++++ ...WithUnreasonableIndentationLevel01.symbols | 9 ++++++++ ...ntWithUnreasonableIndentationLevel01.types | 9 ++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/baselines/reference/commentWithUnreasonableIndentationLevel01.js create mode 100644 tests/baselines/reference/commentWithUnreasonableIndentationLevel01.symbols create mode 100644 tests/baselines/reference/commentWithUnreasonableIndentationLevel01.types 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 +