Skip to content

Commit 466557c

Browse files
author
Andy
authored
Support parsing @template {T} in addition to @template T (microsoft#21270)
1 parent dffa8b1 commit 466557c

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/compiler/parser.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6830,7 +6830,7 @@ namespace ts {
68306830
}
68316831

68326832
function parseTemplateTag(atToken: AtToken, tagName: Identifier): JSDocTemplateTag | undefined {
6833-
if (forEach(tags, t => t.kind === SyntaxKind.JSDocTemplateTag)) {
6833+
if (some(tags, isJSDocTemplateTag)) {
68346834
parseErrorAtPosition(tagName.pos, scanner.getTokenPos() - tagName.pos, Diagnostics._0_tag_already_specified, tagName.escapedText);
68356835
}
68366836

@@ -6839,14 +6839,14 @@ namespace ts {
68396839
const typeParametersPos = getNodePos();
68406840

68416841
while (true) {
6842-
const name = parseJSDocIdentifierName();
6842+
const typeParameter = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter);
6843+
const name = parseJSDocIdentifierNameWithOptionalBraces();
68436844
skipWhitespace();
68446845
if (!name) {
68456846
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
68466847
return undefined;
68476848
}
68486849

6849-
const typeParameter = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter, name.pos);
68506850
typeParameter.name = name;
68516851
finishNode(typeParameter);
68526852

@@ -6869,6 +6869,15 @@ namespace ts {
68696869
return result;
68706870
}
68716871

6872+
function parseJSDocIdentifierNameWithOptionalBraces(): Identifier | undefined {
6873+
const parsedBrace = parseOptional(SyntaxKind.OpenBraceToken);
6874+
const res = parseJSDocIdentifierName();
6875+
if (parsedBrace) {
6876+
parseExpected(SyntaxKind.CloseBraceToken);
6877+
}
6878+
return res;
6879+
}
6880+
68726881
function nextJSDocToken(): JsDocSyntaxKind {
68736882
return currentToken = scanner.scanJSDocToken();
68746883
}

tests/baselines/reference/quickInfoJsDocTags.baseline

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
],
6464
"documentation": [
6565
{
66-
"text": "DocT} A template",
66+
"text": "Doc",
6767
"kind": "text"
6868
}
6969
],
@@ -76,6 +76,10 @@
7676
"name": "augments",
7777
"text": "C<T> Augments it"
7878
},
79+
{
80+
"name": "template",
81+
"text": "{T} A template"
82+
},
7983
{
8084
"name": "type",
8185
"text": "{number | string} A type"

0 commit comments

Comments
 (0)