Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6884,7 +6884,8 @@ namespace ts {
let state = JSDocState.SawAsterisk;
let margin: number | undefined;
// + 4 for leading '/** '
let indent = start - Math.max(content.lastIndexOf("\n", start), 0) + 4;
// + 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
let indent = start - (content.lastIndexOf("\n", start) + 1) + 4;
function pushComment(text: string) {
if (!margin) {
margin = indent;
Expand Down Expand Up @@ -6940,7 +6941,7 @@ namespace ts {
comments.push(whitespace);
}
else if (margin !== undefined && indent + whitespace.length > margin) {
comments.push(whitespace.slice(margin - indent - 1));
comments.push(whitespace.slice(margin - indent));
}
indent += whitespace.length;
break;
Expand Down
13 changes: 13 additions & 0 deletions tests/cases/fourslash/jsDocIndentationPreservation1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
///<reference path="fourslash.ts" />
// @allowJs: true
// @Filename: Foo.js

/////**
//// * Does some stuff.
//// * Second line.
//// * Third line.
//// */
////function foo/**/(){}

goTo.marker();
verify.quickInfoIs("function foo(): void", "Does some stuff.\n Second line.\n\tThird line.");
13 changes: 13 additions & 0 deletions tests/cases/fourslash/jsDocIndentationPreservation2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
///<reference path="fourslash.ts" />
// @allowJs: true
// @Filename: Foo.js

/////**
//// Does some stuff.
//// Second line.
//// Third line.
////*/
////function foo/**/(){}

goTo.marker();
verify.quickInfoIs("function foo(): void", "Does some stuff.\n Second line.\n\tThird line.");
13 changes: 13 additions & 0 deletions tests/cases/fourslash/jsDocIndentationPreservation3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
///<reference path="fourslash.ts" />
// @allowJs: true
// @Filename: Foo.js

/////**
//// Does some stuff.
//// Second line.
//// Third line.
////*/
////function foo/**/(){}

goTo.marker();
verify.quickInfoIs("function foo(): void", "Does some stuff.\n Second line.\n\tThird line.");