File tree 10 files changed +96
-5
lines changed
10 files changed +96
-5
lines changed Original file line number Diff line number Diff line change @@ -20032,14 +20032,20 @@ namespace ts {
20032
20032
}
20033
20033
20034
20034
function checkJSDocAugmentsTag(node: JSDocAugmentsTag): void {
20035
- const cls = getJSDocHost(node);
20036
- if (!isClassDeclaration(cls ) && !isClassExpression(cls )) {
20037
- error(cls , Diagnostics.JSDoc_augments_is_not_attached_to_a_class_declaration);
20035
+ const classLike = getJSDocHost(node);
20036
+ if (!isClassDeclaration(classLike ) && !isClassExpression(classLike )) {
20037
+ error(classLike , Diagnostics.JSDoc_augments_is_not_attached_to_a_class_declaration);
20038
20038
return;
20039
20039
}
20040
20040
20041
+ const augmentsTags = getAllJSDocTagsOfKind(classLike, SyntaxKind.JSDocAugmentsTag);
20042
+ Debug.assert(augmentsTags.length > 0);
20043
+ if (augmentsTags.length > 1) {
20044
+ error(augmentsTags[1], Diagnostics.Class_declarations_cannot_have_more_than_one_augments_or_extends_tag);
20045
+ }
20046
+
20041
20047
const name = getIdentifierFromEntityNameExpression(node.class.expression);
20042
- const extend = getClassExtendsHeritageClauseElement(cls );
20048
+ const extend = getClassExtendsHeritageClauseElement(classLike );
20043
20049
if (extend) {
20044
20050
const className = getIdentifierFromEntityNameExpression(extend.expression);
20045
20051
if (className && name.escapedText !== className.escapedText) {
Original file line number Diff line number Diff line change 3531
3531
"category" : " Error" ,
3532
3532
"code" : 8024
3533
3533
},
3534
+ "Class declarations cannot have more than one `@augments` or `@extends` tag." : {
3535
+ "category" : " Error" ,
3536
+ "code" : 8025
3537
+ },
3534
3538
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause." : {
3535
3539
"category" : " Error" ,
3536
3540
"code" : 9002
Original file line number Diff line number Diff line change @@ -6373,6 +6373,7 @@ namespace ts {
6373
6373
if ( tagName ) {
6374
6374
switch ( tagName . escapedText ) {
6375
6375
case "augments" :
6376
+ case "extends" :
6376
6377
tag = parseAugmentsTag ( atToken , tagName ) ;
6377
6378
break ;
6378
6379
case "class" :
Original file line number Diff line number Diff line change @@ -2159,6 +2159,10 @@ namespace ts {
2159
2159
kind : SyntaxKind . JSDocTag ;
2160
2160
}
2161
2161
2162
+ /**
2163
+ * Note that `@extends` is a synonym of `@augments`.
2164
+ * Both tags are represented by this interface.
2165
+ */
2162
2166
export interface JSDocAugmentsTag extends JSDocTag {
2163
2167
kind : SyntaxKind . JSDocAugmentsTag ;
2164
2168
class : ExpressionWithTypeArguments & { expression : Identifier | PropertyAccessEntityNameExpression } ;
Original file line number Diff line number Diff line change @@ -4241,6 +4241,12 @@ namespace ts {
4241
4241
return find ( tags , doc => doc . kind === kind ) ;
4242
4242
}
4243
4243
4244
+ /** Gets all JSDoc tags of a specified kind, or undefined if not present. */
4245
+ export function getAllJSDocTagsOfKind ( node : Node , kind : SyntaxKind ) : ReadonlyArray < JSDocTag > | undefined {
4246
+ const tags = getJSDocTags ( node ) ;
4247
+ return filter ( tags , doc => doc . kind === kind ) ;
4248
+ }
4249
+
4244
4250
}
4245
4251
4246
4252
// Simple node tests of the form `node.kind === SyntaxKind.Foo`.
Original file line number Diff line number Diff line change @@ -1442,6 +1442,10 @@ declare namespace ts {
1442
1442
interface JSDocUnknownTag extends JSDocTag {
1443
1443
kind : SyntaxKind . JSDocTag ;
1444
1444
}
1445
+ /**
1446
+ * Note that `@extends` is a synonym of `@augments`.
1447
+ * Both tags are represented by this interface.
1448
+ */
1445
1449
interface JSDocAugmentsTag extends JSDocTag {
1446
1450
kind : SyntaxKind . JSDocAugmentsTag ;
1447
1451
class : ExpressionWithTypeArguments & {
@@ -2866,6 +2870,8 @@ declare namespace ts {
2866
2870
function getJSDocReturnType ( node : Node ) : TypeNode | undefined ;
2867
2871
/** Get all JSDoc tags related to a node, including those on parent nodes. */
2868
2872
function getJSDocTags ( node : Node ) : ReadonlyArray < JSDocTag > | undefined ;
2873
+ /** Gets all JSDoc tags of a specified kind, or undefined if not present. */
2874
+ function getAllJSDocTagsOfKind ( node : Node , kind : SyntaxKind ) : ReadonlyArray < JSDocTag > | undefined ;
2869
2875
}
2870
2876
declare namespace ts {
2871
2877
function isNumericLiteral ( node : Node ) : node is NumericLiteral ;
Original file line number Diff line number Diff line change @@ -1442,6 +1442,10 @@ declare namespace ts {
1442
1442
interface JSDocUnknownTag extends JSDocTag {
1443
1443
kind : SyntaxKind . JSDocTag ;
1444
1444
}
1445
+ /**
1446
+ * Note that `@extends` is a synonym of `@augments`.
1447
+ * Both tags are represented by this interface.
1448
+ */
1445
1449
interface JSDocAugmentsTag extends JSDocTag {
1446
1450
kind : SyntaxKind . JSDocAugmentsTag ;
1447
1451
class : ExpressionWithTypeArguments & {
@@ -2921,6 +2925,8 @@ declare namespace ts {
2921
2925
function getJSDocReturnType ( node : Node ) : TypeNode | undefined ;
2922
2926
/** Get all JSDoc tags related to a node, including those on parent nodes. */
2923
2927
function getJSDocTags ( node : Node ) : ReadonlyArray < JSDocTag > | undefined ;
2928
+ /** Gets all JSDoc tags of a specified kind, or undefined if not present. */
2929
+ function getAllJSDocTagsOfKind ( node : Node , kind : SyntaxKind ) : ReadonlyArray < JSDocTag > | undefined ;
2924
2930
}
2925
2931
declare namespace ts {
2926
2932
function isNumericLiteral ( node : Node ) : node is NumericLiteral ;
Original file line number Diff line number Diff line change 20
20
21
21
goTo . marker ( ) ;
22
22
verify . quickInfoIs ( "(local var) x: string" ) ;
23
-
Original file line number Diff line number Diff line change
1
+ ///<reference path="fourslash.ts" />
2
+
3
+ // @allowJs : true
4
+ // @checkJs : true
5
+ // @Filename : dummy.js
6
+
7
+ //// /**
8
+ //// * @augments {Thing<number> }
9
+ //// * @extends {Thing<string> }
10
+ //// */
11
+ //// class MyStringThing extends Thing {
12
+ //// constructor() {
13
+ //// super();
14
+ //// var x = this.mine;
15
+ //// x/**/;
16
+ //// }
17
+ //// }
18
+
19
+ // @Filename : declarations.d.ts
20
+ //// declare class Thing<T> {
21
+ //// mine: T;
22
+ //// }
23
+
24
+ // if more than one tag is present, report an error and take the type of the first entry.
25
+
26
+ goTo . marker ( ) ;
27
+ verify . quickInfoIs ( "(local var) x: number" ) ;
28
+ verify . getSemanticDiagnostics (
29
+ `[
30
+ {
31
+ "message": "Class declarations cannot have more than one \`@augments\` or \`@extends\` tag.",
32
+ "start": 36,
33
+ "length": 24,
34
+ "category": "error",
35
+ "code": 8025
36
+ }
37
+ ]` ) ;
Original file line number Diff line number Diff line change
1
+ ///<reference path="fourslash.ts" />
2
+
3
+ // @allowJs : true
4
+ // @Filename : dummy.js
5
+
6
+ //// /**
7
+ //// * @extends {Thing<string> }
8
+ //// */
9
+ //// class MyStringThing extends Thing {
10
+ //// constructor() {
11
+ //// var x = this.mine;
12
+ //// x/**/;
13
+ //// }
14
+ //// }
15
+
16
+ // @Filename : declarations.d.ts
17
+ //// declare class Thing<T> {
18
+ //// mine: T;
19
+ //// }
20
+
21
+ goTo . marker ( ) ;
22
+ verify . quickInfoIs ( "(local var) x: string" ) ;
You can’t perform that action at this time.
0 commit comments