diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 252ebe202f8..7ce2c8be943 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -260,6 +260,7 @@ import { isImportTypeNode, isInterfaceDeclaration, isJSDoc, + isJSDocAugmentsTag, isJSDocFunctionType, isJSDocLinkLike, isJSDocMemberName, @@ -2763,7 +2764,7 @@ export function isExpressionNode(node: Node): boolean { case SyntaxKind.MetaProperty: return true; case SyntaxKind.ExpressionWithTypeArguments: - return !isHeritageClause(node.parent); + return !isHeritageClause(node.parent) && !isJSDocAugmentsTag(node.parent); case SyntaxKind.QualifiedName: while (node.parent.kind === SyntaxKind.QualifiedName) { node = node.parent; @@ -6117,11 +6118,18 @@ export interface ClassImplementingOrExtendingExpressionWithTypeArguments { } /** @internal */ export function tryGetClassImplementingOrExtendingExpressionWithTypeArguments(node: Node): ClassImplementingOrExtendingExpressionWithTypeArguments | undefined { - return isExpressionWithTypeArguments(node) - && isHeritageClause(node.parent) - && isClassLike(node.parent.parent) - ? { class: node.parent.parent, isImplements: node.parent.token === SyntaxKind.ImplementsKeyword } - : undefined; + if (isExpressionWithTypeArguments(node)) { + if (isHeritageClause(node.parent) && isClassLike(node.parent.parent)) { + return { class: node.parent.parent, isImplements: node.parent.token === SyntaxKind.ImplementsKeyword }; + } + if (isJSDocAugmentsTag(node.parent)) { + const host = getEffectiveJSDocHost(node.parent); + if (host && isClassLike(host)) { + return { class: host, isImplements: false }; + } + } + } + return undefined; } /** @internal */ diff --git a/tests/baselines/reference/jsdocOnInheritedMembers1.baseline b/tests/baselines/reference/jsdocOnInheritedMembers1.baseline new file mode 100644 index 00000000000..c13ee2d742a --- /dev/null +++ b/tests/baselines/reference/jsdocOnInheritedMembers1.baseline @@ -0,0 +1,73 @@ +[ + { + "marker": { + "fileName": "/a.js", + "position": 175, + "name": "" + }, + "quickInfo": { + "kind": "method", + "kindModifiers": "", + "textSpan": { + "start": 169, + "length": 6 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "method", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "B", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "method", + "kind": "methodName" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "void", + "kind": "keyword" + } + ], + "documentation": [ + { + "text": "Method documentation.", + "kind": "text" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/baselines/reference/jsdocOnInheritedMembers2.baseline b/tests/baselines/reference/jsdocOnInheritedMembers2.baseline new file mode 100644 index 00000000000..c039b7c6404 --- /dev/null +++ b/tests/baselines/reference/jsdocOnInheritedMembers2.baseline @@ -0,0 +1,73 @@ +[ + { + "marker": { + "fileName": "/a.js", + "position": 183, + "name": "" + }, + "quickInfo": { + "kind": "method", + "kindModifiers": "", + "textSpan": { + "start": 177, + "length": 6 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "method", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "B", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "method", + "kind": "methodName" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "void", + "kind": "keyword" + } + ], + "documentation": [ + { + "text": "Method documentation.", + "kind": "text" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/jsdocOnInheritedMembers1.ts b/tests/cases/fourslash/jsdocOnInheritedMembers1.ts new file mode 100644 index 00000000000..54066ff6648 --- /dev/null +++ b/tests/cases/fourslash/jsdocOnInheritedMembers1.ts @@ -0,0 +1,20 @@ +/// + +// @allowJs: true +// @checkJs: true +// @filename: /a.js +/////** @template T */ +////class A { +//// /** Method documentation. */ +//// method() {} +////} +//// +/////** @extends {A} */ +////class B extends A { +//// method() {} +////} +//// +////const b = new B(); +////b.method/**/; + +verify.baselineQuickInfo(); diff --git a/tests/cases/fourslash/jsdocOnInheritedMembers2.ts b/tests/cases/fourslash/jsdocOnInheritedMembers2.ts new file mode 100644 index 00000000000..63bf7d65a66 --- /dev/null +++ b/tests/cases/fourslash/jsdocOnInheritedMembers2.ts @@ -0,0 +1,20 @@ +/// + +// @allowJs: true +// @checkJs: true +// @filename: /a.js +/////** @template T */ +////class A { +//// /** Method documentation. */ +//// method() {} +////} +//// +/////** @extends {A} */ +////const B = class extends A { +//// method() {} +////} +//// +////const b = new B(); +////b.method/**/; + +verify.baselineQuickInfo();