Skip to content

Commit 20f3060

Browse files
authored
Add JSDocOverloadTag to ForEachChildTable (#51907)
* add JSDocOverloadTag to ForEachChildTable * fix tests * change imports order
1 parent ba793e6 commit 20f3060

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ const forEachChildTable: ForEachChildTable = {
11051105
[SyntaxKind.JSDocThisTag]: forEachChildInJSDocTypeLikeTag,
11061106
[SyntaxKind.JSDocEnumTag]: forEachChildInJSDocTypeLikeTag,
11071107
[SyntaxKind.JSDocThrowsTag]: forEachChildInJSDocTypeLikeTag,
1108+
[SyntaxKind.JSDocOverloadTag]: forEachChildInJSDocTypeLikeTag,
11081109
[SyntaxKind.JSDocSignature]: function forEachChildInJSDocSignature<T>(node: JSDocSignature, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
11091110
return forEach(node.typeParameters, cbNode) ||
11101111
forEach(node.parameters, cbNode) ||
@@ -1198,7 +1199,7 @@ function forEachChildInJSDocParameterOrPropertyTag<T>(node: JSDocParameterTag |
11981199
(typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment));
11991200
}
12001201

1201-
function forEachChildInJSDocTypeLikeTag<T>(node: JSDocReturnTag | JSDocTypeTag | JSDocThisTag | JSDocEnumTag | JSDocThrowsTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
1202+
function forEachChildInJSDocTypeLikeTag<T>(node: JSDocReturnTag | JSDocTypeTag | JSDocThisTag | JSDocEnumTag | JSDocThrowsTag | JSDocOverloadTag, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
12021203
return visitNode(cbNode, node.tagName) ||
12031204
visitNode(cbNode, node.typeExpression) ||
12041205
(typeof node.comment === "string" ? undefined : visitNodes(cbNode, cbNodes, node.comment));

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ export type ForEachChildNodes =
10021002
| JSDocDeprecatedTag
10031003
| JSDocThrowsTag
10041004
| JSDocOverrideTag
1005+
| JSDocOverloadTag
10051006
;
10061007

10071008
/** @internal */

src/compiler/utilitiesPublic.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import {
7575
getElementOrPropertyAccessArgumentExpressionOrName,
7676
getEmitScriptTarget,
7777
getJSDocCommentsAndTags,
78+
getJSDocRoot,
7879
getJSDocTypeParameterDeclarations,
7980
hasAccessorModifier,
8081
hasDecorators,
@@ -191,6 +192,7 @@ import {
191192
LabeledStatement,
192193
lastOrUndefined,
193194
LeftHandSideExpression,
195+
length,
194196
LiteralExpression,
195197
LiteralToken,
196198
MemberName,
@@ -1210,12 +1212,10 @@ function formatJSDocLink(link: JSDocLink | JSDocLinkCode | JSDocLinkPlain) {
12101212
*/
12111213
export function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters): readonly TypeParameterDeclaration[] {
12121214
if (isJSDocSignature(node)) {
1213-
if (isJSDoc(node.parent)) {
1214-
const overloadTag = find(node.parent.tags, (tag) => {
1215-
return isJSDocOverloadTag(tag) && tag.typeExpression === node;
1216-
});
1217-
if (overloadTag) {
1218-
return flatMap(node.parent.tags, tag => isJSDocTemplateTag(tag) ? tag.typeParameters : undefined);
1215+
if (isJSDocOverloadTag(node.parent)) {
1216+
const jsDoc = getJSDocRoot(node.parent);
1217+
if (jsDoc && length(jsDoc.tags)) {
1218+
return flatMap(jsDoc.tags, tag => isJSDocTemplateTag(tag) ? tag.typeParameters : undefined);
12191219
}
12201220
}
12211221
return emptyArray;

0 commit comments

Comments
 (0)