mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Merge pull request #18706 from aozgaa/dev/aozgaa/JsDocExtendsSupport
support @extends in jsdoc
This commit is contained in:
@@ -20032,14 +20032,20 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void {
|
||||
const cls = getJSDocHost(node);
|
||||
if (!isClassDeclaration(cls) && !isClassExpression(cls)) {
|
||||
error(cls, Diagnostics.JSDoc_augments_is_not_attached_to_a_class_declaration);
|
||||
const classLike = getJSDocHost(node);
|
||||
if (!isClassDeclaration(classLike) && !isClassExpression(classLike)) {
|
||||
error(classLike, Diagnostics.JSDoc_augments_is_not_attached_to_a_class_declaration);
|
||||
return;
|
||||
}
|
||||
|
||||
const augmentsTags = getAllJSDocTagsOfKind(classLike, SyntaxKind.JSDocAugmentsTag);
|
||||
Debug.assert(augmentsTags.length > 0);
|
||||
if (augmentsTags.length > 1) {
|
||||
error(augmentsTags[1], Diagnostics.Class_declarations_cannot_have_more_than_one_augments_or_extends_tag);
|
||||
}
|
||||
|
||||
const name = getIdentifierFromEntityNameExpression(node.class.expression);
|
||||
const extend = getClassExtendsHeritageClauseElement(cls);
|
||||
const extend = getClassExtendsHeritageClauseElement(classLike);
|
||||
if (extend) {
|
||||
const className = getIdentifierFromEntityNameExpression(extend.expression);
|
||||
if (className && name.escapedText !== className.escapedText) {
|
||||
|
||||
@@ -3531,6 +3531,10 @@
|
||||
"category": "Error",
|
||||
"code": 8024
|
||||
},
|
||||
"Class declarations cannot have more than one `@augments` or `@extends` tag.": {
|
||||
"category": "Error",
|
||||
"code": 8025
|
||||
},
|
||||
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": {
|
||||
"category": "Error",
|
||||
"code": 9002
|
||||
|
||||
@@ -6373,6 +6373,7 @@ namespace ts {
|
||||
if (tagName) {
|
||||
switch (tagName.escapedText) {
|
||||
case "augments":
|
||||
case "extends":
|
||||
tag = parseAugmentsTag(atToken, tagName);
|
||||
break;
|
||||
case "class":
|
||||
|
||||
@@ -2159,6 +2159,10 @@ namespace ts {
|
||||
kind: SyntaxKind.JSDocTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that `@extends` is a synonym of `@augments`.
|
||||
* Both tags are represented by this interface.
|
||||
*/
|
||||
export interface JSDocAugmentsTag extends JSDocTag {
|
||||
kind: SyntaxKind.JSDocAugmentsTag;
|
||||
class: ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression };
|
||||
|
||||
@@ -4241,6 +4241,12 @@ namespace ts {
|
||||
return find(tags, doc => doc.kind === kind);
|
||||
}
|
||||
|
||||
/** Gets all JSDoc tags of a specified kind, or undefined if not present. */
|
||||
export function getAllJSDocTagsOfKind(node: Node, kind: SyntaxKind): ReadonlyArray<JSDocTag> | undefined {
|
||||
const tags = getJSDocTags(node);
|
||||
return filter(tags, doc => doc.kind === kind);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Simple node tests of the form `node.kind === SyntaxKind.Foo`.
|
||||
|
||||
Reference in New Issue
Block a user