Skip to content

Support parsing @template {T} in addition to @template T #21270

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
1 commit merged into from
Jan 18, 2018
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
15 changes: 12 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6830,7 +6830,7 @@ namespace ts {
}

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

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

while (true) {
const name = parseJSDocIdentifierName();
const typeParameter = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter);
const name = parseJSDocIdentifierNameWithOptionalBraces();
skipWhitespace();
if (!name) {
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
return undefined;
}

const typeParameter = <TypeParameterDeclaration>createNode(SyntaxKind.TypeParameter, name.pos);
typeParameter.name = name;
finishNode(typeParameter);

Expand All @@ -6869,6 +6869,15 @@ namespace ts {
return result;
}

function parseJSDocIdentifierNameWithOptionalBraces(): Identifier | undefined {
const parsedBrace = parseOptional(SyntaxKind.OpenBraceToken);
const res = parseJSDocIdentifierName();
if (parsedBrace) {
parseExpected(SyntaxKind.CloseBraceToken);
}
return res;
}

function nextJSDocToken(): JsDocSyntaxKind {
return currentToken = scanner.scanJSDocToken();
}
Expand Down
6 changes: 5 additions & 1 deletion tests/baselines/reference/quickInfoJsDocTags.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
],
"documentation": [
{
"text": "DocT} A template",
"text": "Doc",
"kind": "text"
}
],
Expand All @@ -76,6 +76,10 @@
"name": "augments",
"text": "C<T> Augments it"
},
{
"name": "template",
"text": "{T} A template"
},
{
"name": "type",
"text": "{number | string} A type"
Expand Down