Skip to content

Commit 525a06f

Browse files
authored
Merge pull request #12858 from Knagis/master
Fixed missing whitespace in jsDoc comments. Fixes #12236
2 parents 055c0af + aa4a0b6 commit 525a06f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/compiler/parser.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6337,7 +6337,7 @@ namespace ts {
63376337
break;
63386338
case SyntaxKind.AsteriskToken:
63396339
const asterisk = scanner.getTokenText();
6340-
if (state === JSDocState.SawAsterisk) {
6340+
if (state === JSDocState.SawAsterisk || state === JSDocState.SavingComments) {
63416341
// If we've already seen an asterisk, then we can no longer parse a tag on this line
63426342
state = JSDocState.SavingComments;
63436343
pushComment(asterisk);
@@ -6358,14 +6358,19 @@ namespace ts {
63586358
case SyntaxKind.WhitespaceTrivia:
63596359
// only collect whitespace if we're already saving comments or have just crossed the comment indent margin
63606360
const whitespace = scanner.getTokenText();
6361-
if (state === JSDocState.SavingComments || margin !== undefined && indent + whitespace.length > margin) {
6361+
if (state === JSDocState.SavingComments) {
6362+
comments.push(whitespace);
6363+
}
6364+
else if (margin !== undefined && indent + whitespace.length > margin) {
63626365
comments.push(whitespace.slice(margin - indent - 1));
63636366
}
63646367
indent += whitespace.length;
63656368
break;
63666369
case SyntaxKind.EndOfFileToken:
63676370
break;
63686371
default:
6372+
// anything other than whitespace or asterisk at the beginning of the line starts the comment text
6373+
state = JSDocState.SavingComments;
63696374
pushComment(scanner.getTokenText());
63706375
break;
63716376
}

tests/cases/fourslash/commentsLinePreservation.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@
105105
//// * second time information about the param again
106106
//// */
107107
////function /*l*/l(param1: string) { /*9*/param1 = "hello"; }
108+
//// /**
109+
//// * This is firstLine
110+
//// This is second Line
111+
//// [1]: third * line
112+
//// @param param1 first Line text
113+
//// second line text
114+
//// */
115+
////function /*m*/m(param1: string) { /*10*/param1 = "hello"; }
108116

109117
verify.quickInfos({
110118
a: ["var a: string", "This is firstLine\nThis is second Line\n\nThis is fourth Line"],
@@ -136,5 +144,8 @@ verify.quickInfos({
136144
8: ["(parameter) param1: string", "hello "],
137145

138146
l: ["function l(param1: string): void", "This is firstLine\nThis is second Line"],
139-
9: ["(parameter) param1: string", "first Line text\nblank line that shouldnt be shown when starting this \nsecond time information about the param again"]
147+
9: ["(parameter) param1: string", "first Line text\nblank line that shouldnt be shown when starting this \nsecond time information about the param again"],
148+
149+
m: ["function m(param1: string): void", "This is firstLine\nThis is second Line\n[1]: third * line"],
150+
10: ["(parameter) param1: string", "first Line text\nsecond line text"]
140151
});

0 commit comments

Comments
 (0)