Skip to content

Commit c9f05af

Browse files
authored
Merge pull request microsoft#37891 from Neonit/jsDocIndentationPreservation
Fix indentation preservation in JSDoc (microsoft#37717)
2 parents 4c7ea8e + d6af9b7 commit c9f05af

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/compiler/parser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7217,7 +7217,8 @@ namespace ts {
72177217
let state = JSDocState.SawAsterisk;
72187218
let margin: number | undefined;
72197219
// + 4 for leading '/** '
7220-
let indent = start - Math.max(content.lastIndexOf("\n", start), 0) + 4;
7220+
// + 1 because the last index of \n is always one index before the first character in the line and coincidentally, if there is no \n before start, it is -1, which is also one index before the first character
7221+
let indent = start - (content.lastIndexOf("\n", start) + 1) + 4;
72217222
function pushComment(text: string) {
72227223
if (!margin) {
72237224
margin = indent;
@@ -7273,7 +7274,7 @@ namespace ts {
72737274
comments.push(whitespace);
72747275
}
72757276
else if (margin !== undefined && indent + whitespace.length > margin) {
7276-
comments.push(whitespace.slice(margin - indent - 1));
7277+
comments.push(whitespace.slice(margin - indent));
72777278
}
72787279
indent += whitespace.length;
72797280
break;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
///<reference path="fourslash.ts" />
2+
// @allowJs: true
3+
// @Filename: Foo.js
4+
5+
/////**
6+
//// * Does some stuff.
7+
//// * Second line.
8+
//// * Third line.
9+
//// */
10+
////function foo/**/(){}
11+
12+
goTo.marker();
13+
verify.quickInfoIs("function foo(): void", "Does some stuff.\n Second line.\n\tThird line.");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
///<reference path="fourslash.ts" />
2+
// @allowJs: true
3+
// @Filename: Foo.js
4+
5+
/////**
6+
//// Does some stuff.
7+
//// Second line.
8+
//// Third line.
9+
////*/
10+
////function foo/**/(){}
11+
12+
goTo.marker();
13+
verify.quickInfoIs("function foo(): void", "Does some stuff.\n Second line.\n\tThird line.");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
///<reference path="fourslash.ts" />
2+
// @allowJs: true
3+
// @Filename: Foo.js
4+
5+
/////**
6+
//// Does some stuff.
7+
//// Second line.
8+
//// Third line.
9+
////*/
10+
////function foo/**/(){}
11+
12+
goTo.marker();
13+
verify.quickInfoIs("function foo(): void", "Does some stuff.\n Second line.\n\tThird line.");

0 commit comments

Comments
 (0)