Skip to content

Don't start jsdoc tag before whitespace #43602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2021
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
10 changes: 8 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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()