diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index cd61ad8ec80..4f1c62f8c99 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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(); } diff --git a/src/testRunner/unittests/jsDocParsing.ts b/src/testRunner/unittests/jsDocParsing.ts index a2f5037be2a..f346ca8b02d 100644 --- a/src/testRunner/unittests/jsDocParsing.ts +++ b/src/testRunner/unittests/jsDocParsing.ts @@ -331,7 +331,7 @@ namespace ts { * Comments * @author Early Close Caret > * @author No Line Breaks: - * must be on the same line to parse + * must be on the same line to parse * @author Long Comment 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 */`); }); }); diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@@ does not start a new tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@@ does not start a new tag.json new file mode 100644 index 00000000000..8da37b34c35 --- /dev/null +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.@@ does not start a new tag.json @@ -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 + } +} \ No newline at end of file diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Chained tags, no leading whitespace.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Chained tags, no leading whitespace.json new file mode 100644 index 00000000000..1a848db2bb8 --- /dev/null +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Chained tags, no leading whitespace.json @@ -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 + } +} \ No newline at end of file diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial email address is not a tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial email address is not a tag.json new file mode 100644 index 00000000000..a2ad2693915 --- /dev/null +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial email address is not a tag.json @@ -0,0 +1,9 @@ +{ + "kind": "JSDocComment", + "pos": 0, + "end": 21, + "flags": "JSDoc", + "modifierFlagsCache": 0, + "transformFlags": 0, + "comment": "bill@example.com" +} \ No newline at end of file diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star ignores tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star ignores tag.json new file mode 100644 index 00000000000..14d6d34b842 --- /dev/null +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star ignores tag.json @@ -0,0 +1,9 @@ +{ + "kind": "JSDocComment", + "pos": 0, + "end": 8, + "flags": "JSDoc", + "modifierFlagsCache": 0, + "transformFlags": 0, + "comment": "*@a" +} \ No newline at end of file diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star is not a tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star is not a tag.json new file mode 100644 index 00000000000..14d6d34b842 --- /dev/null +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star is not a tag.json @@ -0,0 +1,9 @@ +{ + "kind": "JSDocComment", + "pos": 0, + "end": 8, + "flags": "JSDoc", + "modifierFlagsCache": 0, + "transformFlags": 0, + "comment": "*@a" +} \ No newline at end of file diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space ignores tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space ignores tag.json new file mode 100644 index 00000000000..6a0af3e105d --- /dev/null +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space ignores tag.json @@ -0,0 +1,9 @@ +{ + "kind": "JSDocComment", + "pos": 0, + "end": 9, + "flags": "JSDoc", + "modifierFlagsCache": 0, + "transformFlags": 0, + "comment": "* @a" +} \ No newline at end of file diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space is not a tag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space is not a tag.json new file mode 100644 index 00000000000..6a0af3e105d --- /dev/null +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.Initial star space is not a tag.json @@ -0,0 +1,9 @@ +{ + "kind": "JSDocComment", + "pos": 0, + "end": 9, + "flags": "JSDoc", + "modifierFlagsCache": 0, + "transformFlags": 0, + "comment": "* @a" +} \ No newline at end of file diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json index 9ab0162e2a8..4f92b492fca 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.authorTag.json @@ -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: