Skip to content

Commit

Permalink
Merge pull request #12858 from Knagis/master
Browse files Browse the repository at this point in the history
Fixed missing whitespace in jsDoc comments. Fixes #12236
  • Loading branch information
sandersn committed Dec 12, 2016
2 parents 055c0af + aa4a0b6 commit 525a06f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/compiler/parser.ts
Expand Up @@ -6337,7 +6337,7 @@ namespace ts {
break;
case SyntaxKind.AsteriskToken:
const asterisk = scanner.getTokenText();
if (state === JSDocState.SawAsterisk) {
if (state === JSDocState.SawAsterisk || state === JSDocState.SavingComments) {
// If we've already seen an asterisk, then we can no longer parse a tag on this line
state = JSDocState.SavingComments;
pushComment(asterisk);
Expand All @@ -6358,14 +6358,19 @@ namespace ts {
case SyntaxKind.WhitespaceTrivia:
// only collect whitespace if we're already saving comments or have just crossed the comment indent margin
const whitespace = scanner.getTokenText();
if (state === JSDocState.SavingComments || margin !== undefined && indent + whitespace.length > margin) {
if (state === JSDocState.SavingComments) {
comments.push(whitespace);
}
else if (margin !== undefined && indent + whitespace.length > margin) {
comments.push(whitespace.slice(margin - indent - 1));
}
indent += whitespace.length;
break;
case SyntaxKind.EndOfFileToken:
break;
default:
// anything other than whitespace or asterisk at the beginning of the line starts the comment text
state = JSDocState.SavingComments;
pushComment(scanner.getTokenText());
break;
}
Expand Down
13 changes: 12 additions & 1 deletion tests/cases/fourslash/commentsLinePreservation.ts
Expand Up @@ -105,6 +105,14 @@
//// * second time information about the param again
//// */
////function /*l*/l(param1: string) { /*9*/param1 = "hello"; }
//// /**
//// * This is firstLine
//// This is second Line
//// [1]: third * line
//// @param param1 first Line text
//// second line text
//// */
////function /*m*/m(param1: string) { /*10*/param1 = "hello"; }

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

l: ["function l(param1: string): void", "This is firstLine\nThis is second Line"],
9: ["(parameter) param1: string", "first Line text\nblank line that shouldnt be shown when starting this \nsecond time information about the param again"]
9: ["(parameter) param1: string", "first Line text\nblank line that shouldnt be shown when starting this \nsecond time information about the param again"],

m: ["function m(param1: string): void", "This is firstLine\nThis is second Line\n[1]: third * line"],
10: ["(parameter) param1: string", "first Line text\nsecond line text"]
});

0 comments on commit 525a06f

Please sign in to comment.