diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d37e1d102bbdd..0423988d58b81 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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; } @@ -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; diff --git a/tests/baselines/reference/quickInfoJSDocAtBeforeSpace.baseline b/tests/baselines/reference/quickInfoJSDocAtBeforeSpace.baseline new file mode 100644 index 0000000000000..aece0bd313f63 --- /dev/null +++ b/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" + } + ] + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts b/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts new file mode 100644 index 0000000000000..e1e016de437fc --- /dev/null +++ b/tests/cases/fourslash/quickInfoJSDocAtBeforeSpace.ts @@ -0,0 +1,19 @@ +/// + +//// /** +//// * @return Don't @ me +//// */ +//// function /*f*/f() { } +//// /** +//// * @return One final @ +//// */ +//// function /*g*/g() { } +//// /** +//// * @return An @ +//// * But another line +//// */ +//// function /*h*/h() { } + + +verify.baselineQuickInfo() +