At starts jsdoc tag only after whitespace (#42364)

* Update tests

* @ begins JSDoc tag only after whitespace

Previously, inside a JSDoc tag's comment, @ would start a tag unless it
was surrounded by backticks. However, looking at real code showed that
only whitespace-preceded uses of @ were intended to start tags.
This commit is contained in:
Nathan Shively-Sanders
2021-01-25 09:42:24 -08:00
committed by GitHub
parent 89c173fddc
commit ca380af99b
11 changed files with 294 additions and 14 deletions
+4 -1
View File
@@ -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) {
@@ -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;
}
@@ -7614,6 +7616,7 @@ namespace ts {
pushComment(scanner.getTokenText());
break;
}
previousWhitespace = token() === SyntaxKind.WhitespaceTrivia;
tok = nextTokenJSDoc();
}
+17 -1
View File
@@ -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.
*/`);
@@ -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
*/`);
});
});
@@ -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
}
}
@@ -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
}
}
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 21,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "bill@example.com"
}
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 8,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "*@a"
}
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 8,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "*@a"
}
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 9,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "* @a"
}
@@ -0,0 +1,9 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 9,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"comment": "* @a"
}
@@ -1,7 +1,7 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 738,
"end": 739,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
@@ -262,7 +262,7 @@
"16": {
"kind": "JSDocAuthorTag",
"pos": 559,
"end": 598,
"end": 599,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
@@ -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"
@@ -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"
@@ -309,7 +309,7 @@
},
"length": 19,
"pos": 7,
"end": 736,
"end": 737,
"hasTrailingComma": false,
"transformFlags": 0
}
@@ -0,0 +1,99 @@
{
"kind": "JSDocComment",
"pos": 0,
"end": 91,
"flags": "JSDoc",
"modifierFlagsCache": 0,
"transformFlags": 0,
"tags": {
"0": {
"kind": "JSDocParameterTag",
"pos": 7,
"end": 29,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 8,
"end": 13,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "param"
},
"comment": "(@is@)",
"name": {
"kind": "Identifier",
"pos": 14,
"end": 18,
"modifierFlagsCache": 0,
"transformFlags": 0,
"originalKeywordKind": "ThisKeyword",
"escapedText": "this"
},
"isNameFirst": true,
"isBracketed": false
},
"1": {
"kind": "JSDocParameterTag",
"pos": 29,
"end": 50,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 30,
"end": 35,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "param"
},
"comment": "its@fine",
"name": {
"kind": "Identifier",
"pos": 36,
"end": 40,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "fine"
},
"isNameFirst": true,
"isBracketed": false
},
"2": {
"kind": "JSDocTag",
"pos": 50,
"end": 62,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 51,
"end": 60,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "zerowidth"
}
},
"3": {
"kind": "JSDocTag",
"pos": 62,
"end": 75,
"modifierFlagsCache": 0,
"transformFlags": 0,
"tagName": {
"kind": "Identifier",
"pos": 63,
"end": 73,
"modifierFlagsCache": 0,
"transformFlags": 0,
"escapedText": "singlestar"
},
"comment": "*@doublestar"
},
"length": 4,
"pos": 7,
"end": 75,
"hasTrailingComma": false,
"transformFlags": 0
}
}