Skip to content

Commit

Permalink
Don't start jsdoc tag before whitespace (#43602)
Browse files Browse the repository at this point in the history
Fixes #43580
  • Loading branch information
sandersn committed Apr 12, 2021
1 parent 0487b38 commit 7c10135
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/compiler/parser.ts
Expand Up @@ -7655,8 +7655,9 @@ namespace ts {
indent = 0;
break;
case SyntaxKind.AtToken:
if (state === JSDocState.SavingBackticks || !previousWhitespace && state === JSDocState.SavingComments) {
// @ doesn't start a new tag inside ``, and inside a comment, only after whitespace
if (state === JSDocState.SavingBackticks
|| state === JSDocState.SavingComments && (!previousWhitespace || lookAhead(isNextJSDocTokenWhitespace))) {
// @ doesn't start a new tag inside ``, and inside a comment, only after whitespace or not before whitespace
comments.push(scanner.getTokenText());
break;
}
Expand Down Expand Up @@ -7735,6 +7736,11 @@ namespace ts {
}
}

function isNextJSDocTokenWhitespace() {
const next = nextTokenJSDoc();
return next === SyntaxKind.WhitespaceTrivia || next === SyntaxKind.NewLineTrivia;
}

function parseJSDocLink(start: number) {
if (!tryParse(parseJSDocLinkPrefix)) {
return undefined;
Expand Down
185 changes: 185 additions & 0 deletions tests/baselines/reference/quickInfoJSDocAtBeforeSpace.baseline
@@ -0,0 +1,185 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts",
"position": 39,
"name": "f"
},
"quickInfo": {
"kind": "function",
"kindModifiers": "",
"textSpan": {
"start": 39,
"length": 1
},
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "f",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"documentation": [],
"tags": [
{
"name": "return",
"text": [
{
"text": "Don't @ me",
"kind": "text"
}
]
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts",
"position": 87,
"name": "g"
},
"quickInfo": {
"kind": "function",
"kindModifiers": "",
"textSpan": {
"start": 87,
"length": 1
},
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "g",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"documentation": [],
"tags": [
{
"name": "return",
"text": [
{
"text": "One final @",
"kind": "text"
}
]
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts",
"position": 148,
"name": "h"
},
"quickInfo": {
"kind": "function",
"kindModifiers": "",
"textSpan": {
"start": 148,
"length": 1
},
"displayParts": [
{
"text": "function",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "h",
"kind": "functionName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"documentation": [],
"tags": [
{
"name": "return",
"text": [
{
"text": "An @\nBut another line",
"kind": "text"
}
]
}
]
}
}
]
19 changes: 19 additions & 0 deletions tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts
@@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />

//// /**
//// * @return Don't @ me
//// */
//// function /*f*/f() { }
//// /**
//// * @return One final @
//// */
//// function /*g*/g() { }
//// /**
//// * @return An @
//// * But another line
//// */
//// function /*h*/h() { }


verify.baselineQuickInfo()

0 comments on commit 7c10135

Please sign in to comment.