Skip to content

Commit 8f2a38f

Browse files
authored
fix(50117): Using @extends in JavaScript + JSDoc removes method documentations (microsoft#50256)
* fix(50117): show jsdoc from an inherited members * show jsdoc from inherited members from class expressions
1 parent d54f52e commit 8f2a38f

File tree

5 files changed

+200
-6
lines changed

5 files changed

+200
-6
lines changed

src/compiler/utilities.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ import {
260260
isImportTypeNode,
261261
isInterfaceDeclaration,
262262
isJSDoc,
263+
isJSDocAugmentsTag,
263264
isJSDocFunctionType,
264265
isJSDocLinkLike,
265266
isJSDocMemberName,
@@ -2763,7 +2764,7 @@ export function isExpressionNode(node: Node): boolean {
27632764
case SyntaxKind.MetaProperty:
27642765
return true;
27652766
case SyntaxKind.ExpressionWithTypeArguments:
2766-
return !isHeritageClause(node.parent);
2767+
return !isHeritageClause(node.parent) && !isJSDocAugmentsTag(node.parent);
27672768
case SyntaxKind.QualifiedName:
27682769
while (node.parent.kind === SyntaxKind.QualifiedName) {
27692770
node = node.parent;
@@ -6117,11 +6118,18 @@ export interface ClassImplementingOrExtendingExpressionWithTypeArguments {
61176118
}
61186119
/** @internal */
61196120
export function tryGetClassImplementingOrExtendingExpressionWithTypeArguments(node: Node): ClassImplementingOrExtendingExpressionWithTypeArguments | undefined {
6120-
return isExpressionWithTypeArguments(node)
6121-
&& isHeritageClause(node.parent)
6122-
&& isClassLike(node.parent.parent)
6123-
? { class: node.parent.parent, isImplements: node.parent.token === SyntaxKind.ImplementsKeyword }
6124-
: undefined;
6121+
if (isExpressionWithTypeArguments(node)) {
6122+
if (isHeritageClause(node.parent) && isClassLike(node.parent.parent)) {
6123+
return { class: node.parent.parent, isImplements: node.parent.token === SyntaxKind.ImplementsKeyword };
6124+
}
6125+
if (isJSDocAugmentsTag(node.parent)) {
6126+
const host = getEffectiveJSDocHost(node.parent);
6127+
if (host && isClassLike(host)) {
6128+
return { class: host, isImplements: false };
6129+
}
6130+
}
6131+
}
6132+
return undefined;
61256133
}
61266134

61276135
/** @internal */
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/a.js",
5+
"position": 175,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "method",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 169,
13+
"length": 6
14+
},
15+
"displayParts": [
16+
{
17+
"text": "(",
18+
"kind": "punctuation"
19+
},
20+
{
21+
"text": "method",
22+
"kind": "text"
23+
},
24+
{
25+
"text": ")",
26+
"kind": "punctuation"
27+
},
28+
{
29+
"text": " ",
30+
"kind": "space"
31+
},
32+
{
33+
"text": "B",
34+
"kind": "className"
35+
},
36+
{
37+
"text": ".",
38+
"kind": "punctuation"
39+
},
40+
{
41+
"text": "method",
42+
"kind": "methodName"
43+
},
44+
{
45+
"text": "(",
46+
"kind": "punctuation"
47+
},
48+
{
49+
"text": ")",
50+
"kind": "punctuation"
51+
},
52+
{
53+
"text": ":",
54+
"kind": "punctuation"
55+
},
56+
{
57+
"text": " ",
58+
"kind": "space"
59+
},
60+
{
61+
"text": "void",
62+
"kind": "keyword"
63+
}
64+
],
65+
"documentation": [
66+
{
67+
"text": "Method documentation.",
68+
"kind": "text"
69+
}
70+
]
71+
}
72+
}
73+
]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/a.js",
5+
"position": 183,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "method",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 177,
13+
"length": 6
14+
},
15+
"displayParts": [
16+
{
17+
"text": "(",
18+
"kind": "punctuation"
19+
},
20+
{
21+
"text": "method",
22+
"kind": "text"
23+
},
24+
{
25+
"text": ")",
26+
"kind": "punctuation"
27+
},
28+
{
29+
"text": " ",
30+
"kind": "space"
31+
},
32+
{
33+
"text": "B",
34+
"kind": "className"
35+
},
36+
{
37+
"text": ".",
38+
"kind": "punctuation"
39+
},
40+
{
41+
"text": "method",
42+
"kind": "methodName"
43+
},
44+
{
45+
"text": "(",
46+
"kind": "punctuation"
47+
},
48+
{
49+
"text": ")",
50+
"kind": "punctuation"
51+
},
52+
{
53+
"text": ":",
54+
"kind": "punctuation"
55+
},
56+
{
57+
"text": " ",
58+
"kind": "space"
59+
},
60+
{
61+
"text": "void",
62+
"kind": "keyword"
63+
}
64+
],
65+
"documentation": [
66+
{
67+
"text": "Method documentation.",
68+
"kind": "text"
69+
}
70+
]
71+
}
72+
}
73+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// @allowJs: true
4+
// @checkJs: true
5+
// @filename: /a.js
6+
/////** @template T */
7+
////class A {
8+
//// /** Method documentation. */
9+
//// method() {}
10+
////}
11+
////
12+
/////** @extends {A<number>} */
13+
////class B extends A {
14+
//// method() {}
15+
////}
16+
////
17+
////const b = new B();
18+
////b.method/**/;
19+
20+
verify.baselineQuickInfo();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// @allowJs: true
4+
// @checkJs: true
5+
// @filename: /a.js
6+
/////** @template T */
7+
////class A {
8+
//// /** Method documentation. */
9+
//// method() {}
10+
////}
11+
////
12+
/////** @extends {A<number>} */
13+
////const B = class extends A {
14+
//// method() {}
15+
////}
16+
////
17+
////const b = new B();
18+
////b.method/**/;
19+
20+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)