Skip to content

At starts jsdoc tag only after whitespace #42364

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 2 commits into from
Jan 25, 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
5 changes: 4 additions & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7532,6 +7532,7 @@ namespace ts {
function parseTagComments(indent: number, initialMargin?: string): string | undefined {
const comments: string[] = [];
let state = JSDocState.BeginningOfLine;
let previousWhitespace = true;
let margin: number | undefined;
function pushComment(text: string) {
if (!margin) {
Expand All @@ -7557,7 +7558,8 @@ namespace ts {
indent = 0;
break;
case SyntaxKind.AtToken:
if (state === JSDocState.SavingBackticks) {
if (state === JSDocState.SavingBackticks || !previousWhitespace && state === JSDocState.SavingComments) {
// @ doesn't start a new tag inside ``, and inside a comment, only after whitespace
comments.push(scanner.getTokenText());
break;
}
Expand Down Expand Up @@ -7614,6 +7616,7 @@ namespace ts {
pushComment(scanner.getTokenText());
break;
}
previousWhitespace = token() === SyntaxKind.WhitespaceTrivia;
tok = nextTokenJSDoc();
}

Expand Down
18 changes: 17 additions & 1 deletion src/testRunner/unittests/jsDocParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ namespace ts {
* Comments
* @author Early Close Caret > <a@b>
* @author No Line Breaks:
* <the.email@address> must be on the same line to parse
* <the email @address> must be on the same line to parse
* @author Long Comment <long@comment.org> I
* want to keep commenting down here, I dunno.
*/`);
Expand All @@ -340,6 +340,22 @@ namespace ts {
`/**
* @example
* Some\n\n * text\r\n * with newlines.
*/`);
parsesCorrectly("Chained tags, no leading whitespace", `/**@a @b @c@d*/`);
parsesCorrectly("Initial star is not a tag", `/***@a*/`);
parsesCorrectly("Initial star space is not a tag", `/*** @a*/`);
parsesCorrectly("Initial email address is not a tag", `/**bill@example.com*/`);
parsesCorrectly("no space before @ is not a new tag",
`/**
* @param this (@is@)
* @param fine its@fine
@zerowidth
*@singlestar
**@doublestar
*/`);
parsesCorrectly("@@ does not start a new tag",
`/**
* @param this is (@@fine@@and) is one comment
*/`);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 54,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
"0": {
"kind": "JSDocParameterTag",
"pos": 7,
"end": 52,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 8,
"end": 13,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "param"
},
"comment": "is (@@fine@@and) is one comment",
"name": {
"kind": "Identifier",
"pos": 14,
"end": 18,
"modifierFlagsCache": 0,
"transformFlags": 0,
"originalKeywordKind": "ThisKeyword",
"escapedText": "this"
},
"isNameFirst": true,
"isBracketed": false
},
"length": 1,
"pos": 7,
"end": 52,
"hasTrailingComma": false,
"transformFlags": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 15,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
"0": {
"kind": "JSDocTag",
"pos": 3,
"end": 6,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 4,
"end": 5,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "a"
}
},
"1": {
"kind": "JSDocTag",
"pos": 6,
"end": 9,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 7,
"end": 8,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "b"
}
},
"2": {
"kind": "JSDocTag",
"pos": 9,
"end": 11,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 10,
"end": 11,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "c"
}
},
"3": {
"kind": "JSDocTag",
"pos": 11,
"end": 13,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 12,
"end": 13,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "d"
}
},
"length": 4,
"pos": 3,
"end": 13,
"hasTrailingComma": false,
"transformFlags": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 21,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "bill@example.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 8,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "*@a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 8,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "*@a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 9,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "* @a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 9,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "* @a"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 738,
"end": 739,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
Expand Down Expand Up @@ -262,7 +262,7 @@
"16": {
"kind": "JSDocAuthorTag",
"pos": 559,
"end": 598,
"end": 599,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
Expand All @@ -273,18 +273,18 @@
"transformFlags": 0,
"escapedText": "author"
},
"comment": "No Line Breaks:<the.email"
"comment": "No Line Breaks:<the email"
},
"17": {
"kind": "JSDocTag",
"pos": 598,
"end": 606,
"pos": 599,
"end": 607,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 599,
"end": 606,
"pos": 600,
"end": 607,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "address"
Expand All @@ -293,14 +293,14 @@
},
"18": {
"kind": "JSDocAuthorTag",
"pos": 645,
"end": 736,
"pos": 646,
"end": 737,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 646,
"end": 652,
"pos": 647,
"end": 653,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "author"
Expand All @@ -309,7 +309,7 @@
},
"length": 19,
"pos": 7,
"end": 736,
"end": 737,
"hasTrailingComma": false,
"transformFlags": 0
}
Expand Down
Loading