Skip to content
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

Fix name resolution in typedef and allow defaults for template tags #45483

Merged
merged 5 commits into from
Sep 9, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Inline parseBracketNameInTemplateTag
  • Loading branch information
rbuckton committed Aug 27, 2021
commit 8460ea4361cf937f91877b0d5f0cfeb497656168
31 changes: 14 additions & 17 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8053,22 +8053,6 @@ namespace ts {
return token() === SyntaxKind.OpenBraceToken ? parseJSDocTypeExpression() : undefined;
}

function parseBracketNameInTemplateTag(): { name: Identifier, defaultType?: TypeNode } {
const isBracketed = parseOptionalJsdoc(SyntaxKind.OpenBracketToken);
if (isBracketed) {
skipWhitespace();
}
const name = parseJSDocIdentifierName(Diagnostics.Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces);
let defaultType: TypeNode | undefined;
if (isBracketed) {
skipWhitespace();
parseExpected(SyntaxKind.EqualsToken);
defaultType = doInsideOfContext(NodeFlags.JSDoc, parseJSDocType);
parseExpected(SyntaxKind.CloseBracketToken);
}
return { name, defaultType };
}

function parseBracketNameInPropertyAndParamTag(): { name: EntityName, isBracketed: boolean } {
// Looking for something like '[foo]', 'foo', '[foo.bar]' or 'foo.bar'
const isBracketed = parseOptionalJsdoc(SyntaxKind.OpenBracketToken);
Expand Down Expand Up @@ -8457,7 +8441,20 @@ namespace ts {

function parseTemplateTagTypeParameter() {
const typeParameterPos = getNodePos();
const { name, defaultType } = parseBracketNameInTemplateTag();
const isBracketed = parseOptionalJsdoc(SyntaxKind.OpenBracketToken);
if (isBracketed) {
skipWhitespace();
}
const name = parseJSDocIdentifierName(Diagnostics.Unexpected_token_A_type_parameter_name_was_expected_without_curly_braces);

let defaultType: TypeNode | undefined;
if (isBracketed) {
skipWhitespace();
parseExpected(SyntaxKind.EqualsToken);
defaultType = doInsideOfContext(NodeFlags.JSDoc, parseJSDocType);
parseExpected(SyntaxKind.CloseBracketToken);
}

if (nodeIsMissing(name)) {
return undefined;
}
Expand Down