Skip to content

Commit 2a8c4d1

Browse files
authored
Support @this tags (microsoft#24927)
* Type check `@this` tags No special support in fourslash yet, so quickinfo probably doesn't work. * Do no require braces and update API baselines
1 parent debcf12 commit 2a8c4d1

18 files changed

+975
-838
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14890,6 +14890,10 @@ namespace ts {
1489014890
return getTypeFromTypeNode(jsDocFunctionType.parameters[0].type!);
1489114891
}
1489214892
}
14893+
const thisTag = getJSDocThisTag(node);
14894+
if (thisTag && thisTag.typeExpression) {
14895+
return getTypeFromTypeNode(thisTag.typeExpression);
14896+
}
1489314897
}
1489414898

1489514899
function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean {

src/parser/parser.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ namespace ts {
491491
case SyntaxKind.JSDocCallbackTag:
492492
return visitNode(cbNode, (node as JSDocCallbackTag).fullName) ||
493493
visitNode(cbNode, (node as JSDocCallbackTag).typeExpression);
494+
case SyntaxKind.JSDocThisTag:
495+
return visitNode(cbNode, (node as JSDocThisTag).typeExpression);
494496
case SyntaxKind.JSDocSignature:
495497
return visitNodes(cbNode, cbNodes, node.decorators) ||
496498
visitNodes(cbNode, cbNodes, node.modifiers) ||
@@ -6497,6 +6499,9 @@ namespace ts {
64976499
case "constructor":
64986500
tag = parseClassTag(atToken, tagName);
64996501
break;
6502+
case "this":
6503+
tag = parseThisTag(atToken, tagName);
6504+
break;
65006505
case "arg":
65016506
case "argument":
65026507
case "param":
@@ -6768,6 +6773,15 @@ namespace ts {
67686773
return finishNode(tag);
67696774
}
67706775

6776+
function parseThisTag(atToken: AtToken, tagName: Identifier): JSDocThisTag {
6777+
const tag = <JSDocThisTag>createNode(SyntaxKind.JSDocThisTag, atToken.pos);
6778+
tag.atToken = atToken;
6779+
tag.tagName = tagName;
6780+
tag.typeExpression = parseJSDocTypeExpression(/*mayOmitBraces*/ true);
6781+
skipWhitespace();
6782+
return finishNode(tag);
6783+
}
6784+
67716785
function parseTypedefTag(atToken: AtToken, tagName: Identifier, indent: number): JSDocTypedefTag {
67726786
const typeExpression = tryParseTypeExpression();
67736787
skipWhitespace();

src/parser/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ namespace ts {
371371
JSDocCallbackTag,
372372
JSDocParameterTag,
373373
JSDocReturnTag,
374+
JSDocThisTag,
374375
JSDocTypeTag,
375376
JSDocTemplateTag,
376377
JSDocTypedefTag,
@@ -2323,6 +2324,11 @@ namespace ts {
23232324
kind: SyntaxKind.JSDocClassTag;
23242325
}
23252326

2327+
export interface JSDocThisTag extends JSDocTag {
2328+
kind: SyntaxKind.JSDocThisTag;
2329+
typeExpression?: JSDocTypeExpression;
2330+
}
2331+
23262332
export interface JSDocTemplateTag extends JSDocTag {
23272333
kind: SyntaxKind.JSDocTemplateTag;
23282334
typeParameters: NodeArray<TypeParameterDeclaration>;

src/parser/utilities.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4970,6 +4970,11 @@ namespace ts {
49704970
return getFirstJSDocTag(node, isJSDocClassTag);
49714971
}
49724972

4973+
/** Gets the JSDoc this tag for the node if present */
4974+
export function getJSDocThisTag(node: Node): JSDocThisTag | undefined {
4975+
return getFirstJSDocTag(node, isJSDocThisTag);
4976+
}
4977+
49734978
/** Gets the JSDoc return tag for the node if present */
49744979
export function getJSDocReturnTag(node: Node): JSDocReturnTag | undefined {
49754980
return getFirstJSDocTag(node, isJSDocReturnTag);
@@ -5701,6 +5706,10 @@ namespace ts {
57015706
return node.kind === SyntaxKind.JSDocClassTag;
57025707
}
57035708

5709+
export function isJSDocThisTag(node: Node): node is JSDocThisTag {
5710+
return node.kind === SyntaxKind.JSDocThisTag;
5711+
}
5712+
57045713
export function isJSDocParameterTag(node: Node): node is JSDocParameterTag {
57055714
return node.kind === SyntaxKind.JSDocParameterTag;
57065715
}

tests/baselines/reference/APISample_Watch.errors.txt

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,75 @@
11
typescript_standalone.d.ts(21,28): error TS1005: ';' expected.
22
typescript_standalone.d.ts(21,41): error TS1005: ';' expected.
3-
typescript_standalone.d.ts(8913,28): error TS1005: ';' expected.
4-
typescript_standalone.d.ts(8913,42): error TS1005: ';' expected.
5-
typescript_standalone.d.ts(9173,28): error TS1005: ';' expected.
6-
typescript_standalone.d.ts(9173,46): error TS1005: ';' expected.
7-
typescript_standalone.d.ts(9523,28): error TS1005: ';' expected.
8-
typescript_standalone.d.ts(9523,36): error TS1005: ';' expected.
9-
typescript_standalone.d.ts(9547,28): error TS1005: ';' expected.
10-
typescript_standalone.d.ts(9547,36): error TS1005: ';' expected.
11-
typescript_standalone.d.ts(9634,28): error TS1005: ';' expected.
12-
typescript_standalone.d.ts(9634,38): error TS1005: ';' expected.
13-
typescript_standalone.d.ts(10799,28): error TS1005: ';' expected.
14-
typescript_standalone.d.ts(10799,57): error TS1005: ';' expected.
15-
typescript_standalone.d.ts(10810,28): error TS1005: ';' expected.
16-
typescript_standalone.d.ts(10810,41): error TS1005: ';' expected.
17-
typescript_standalone.d.ts(10820,28): error TS1005: ';' expected.
18-
typescript_standalone.d.ts(10820,48): error TS1005: ';' expected.
19-
typescript_standalone.d.ts(10895,28): error TS1005: ';' expected.
20-
typescript_standalone.d.ts(10895,47): error TS1005: ';' expected.
21-
typescript_standalone.d.ts(10952,28): error TS1005: ';' expected.
22-
typescript_standalone.d.ts(10952,47): error TS1005: ';' expected.
23-
typescript_standalone.d.ts(11006,28): error TS1005: ';' expected.
24-
typescript_standalone.d.ts(11006,52): error TS1005: ';' expected.
25-
typescript_standalone.d.ts(11026,28): error TS1005: ';' expected.
26-
typescript_standalone.d.ts(11026,44): error TS1005: ';' expected.
27-
typescript_standalone.d.ts(11036,28): error TS1005: ';' expected.
28-
typescript_standalone.d.ts(11036,35): error TS1005: ';' expected.
29-
typescript_standalone.d.ts(11070,28): error TS1005: ';' expected.
30-
typescript_standalone.d.ts(11070,40): error TS1005: ';' expected.
31-
typescript_standalone.d.ts(11073,28): error TS1005: ';' expected.
32-
typescript_standalone.d.ts(11073,43): error TS1005: ';' expected.
33-
typescript_standalone.d.ts(11077,28): error TS1005: ';' expected.
34-
typescript_standalone.d.ts(11077,45): error TS1005: ';' expected.
35-
typescript_standalone.d.ts(11095,28): error TS1005: ';' expected.
36-
typescript_standalone.d.ts(11095,56): error TS1005: ';' expected.
37-
typescript_standalone.d.ts(11121,28): error TS1005: ';' expected.
38-
typescript_standalone.d.ts(11121,36): error TS1005: ';' expected.
39-
typescript_standalone.d.ts(11124,28): error TS1005: ';' expected.
40-
typescript_standalone.d.ts(11124,43): error TS1005: ';' expected.
41-
typescript_standalone.d.ts(11136,28): error TS1005: ';' expected.
42-
typescript_standalone.d.ts(11136,43): error TS1005: ';' expected.
43-
typescript_standalone.d.ts(11166,28): error TS1005: ';' expected.
44-
typescript_standalone.d.ts(11166,40): error TS1005: ';' expected.
45-
typescript_standalone.d.ts(11200,28): error TS1005: ';' expected.
46-
typescript_standalone.d.ts(11200,40): error TS1005: ';' expected.
47-
typescript_standalone.d.ts(11211,28): error TS1005: ';' expected.
48-
typescript_standalone.d.ts(11211,40): error TS1005: ';' expected.
49-
typescript_standalone.d.ts(11235,28): error TS1005: ';' expected.
50-
typescript_standalone.d.ts(11235,40): error TS1005: ';' expected.
3+
typescript_standalone.d.ts(8921,28): error TS1005: ';' expected.
4+
typescript_standalone.d.ts(8921,42): error TS1005: ';' expected.
5+
typescript_standalone.d.ts(9181,28): error TS1005: ';' expected.
6+
typescript_standalone.d.ts(9181,46): error TS1005: ';' expected.
7+
typescript_standalone.d.ts(9531,28): error TS1005: ';' expected.
8+
typescript_standalone.d.ts(9531,36): error TS1005: ';' expected.
9+
typescript_standalone.d.ts(9555,28): error TS1005: ';' expected.
10+
typescript_standalone.d.ts(9555,36): error TS1005: ';' expected.
11+
typescript_standalone.d.ts(9642,28): error TS1005: ';' expected.
12+
typescript_standalone.d.ts(9642,38): error TS1005: ';' expected.
13+
typescript_standalone.d.ts(10807,28): error TS1005: ';' expected.
14+
typescript_standalone.d.ts(10807,57): error TS1005: ';' expected.
15+
typescript_standalone.d.ts(10818,28): error TS1005: ';' expected.
16+
typescript_standalone.d.ts(10818,41): error TS1005: ';' expected.
17+
typescript_standalone.d.ts(10828,28): error TS1005: ';' expected.
18+
typescript_standalone.d.ts(10828,48): error TS1005: ';' expected.
19+
typescript_standalone.d.ts(10903,28): error TS1005: ';' expected.
20+
typescript_standalone.d.ts(10903,47): error TS1005: ';' expected.
21+
typescript_standalone.d.ts(10960,28): error TS1005: ';' expected.
22+
typescript_standalone.d.ts(10960,47): error TS1005: ';' expected.
23+
typescript_standalone.d.ts(11014,28): error TS1005: ';' expected.
24+
typescript_standalone.d.ts(11014,52): error TS1005: ';' expected.
25+
typescript_standalone.d.ts(11034,28): error TS1005: ';' expected.
26+
typescript_standalone.d.ts(11034,44): error TS1005: ';' expected.
27+
typescript_standalone.d.ts(11044,28): error TS1005: ';' expected.
28+
typescript_standalone.d.ts(11044,35): error TS1005: ';' expected.
29+
typescript_standalone.d.ts(11078,28): error TS1005: ';' expected.
30+
typescript_standalone.d.ts(11078,40): error TS1005: ';' expected.
31+
typescript_standalone.d.ts(11081,28): error TS1005: ';' expected.
32+
typescript_standalone.d.ts(11081,43): error TS1005: ';' expected.
33+
typescript_standalone.d.ts(11085,28): error TS1005: ';' expected.
34+
typescript_standalone.d.ts(11085,45): error TS1005: ';' expected.
35+
typescript_standalone.d.ts(11103,28): error TS1005: ';' expected.
36+
typescript_standalone.d.ts(11103,56): error TS1005: ';' expected.
37+
typescript_standalone.d.ts(11129,28): error TS1005: ';' expected.
38+
typescript_standalone.d.ts(11129,36): error TS1005: ';' expected.
39+
typescript_standalone.d.ts(11132,28): error TS1005: ';' expected.
40+
typescript_standalone.d.ts(11132,43): error TS1005: ';' expected.
41+
typescript_standalone.d.ts(11144,28): error TS1005: ';' expected.
42+
typescript_standalone.d.ts(11144,43): error TS1005: ';' expected.
43+
typescript_standalone.d.ts(11174,28): error TS1005: ';' expected.
44+
typescript_standalone.d.ts(11174,40): error TS1005: ';' expected.
45+
typescript_standalone.d.ts(11208,28): error TS1005: ';' expected.
46+
typescript_standalone.d.ts(11208,40): error TS1005: ';' expected.
47+
typescript_standalone.d.ts(11219,28): error TS1005: ';' expected.
48+
typescript_standalone.d.ts(11219,40): error TS1005: ';' expected.
5149
typescript_standalone.d.ts(11243,28): error TS1005: ';' expected.
5250
typescript_standalone.d.ts(11243,40): error TS1005: ';' expected.
53-
typescript_standalone.d.ts(11247,28): error TS1005: ';' expected.
54-
typescript_standalone.d.ts(11247,40): error TS1005: ';' expected.
55-
typescript_standalone.d.ts(11277,28): error TS1005: ';' expected.
56-
typescript_standalone.d.ts(11277,40): error TS1005: ';' expected.
57-
typescript_standalone.d.ts(11320,28): error TS1005: ';' expected.
58-
typescript_standalone.d.ts(11320,41): error TS1005: ';' expected.
59-
typescript_standalone.d.ts(11507,28): error TS1005: ';' expected.
60-
typescript_standalone.d.ts(11507,37): error TS1005: ';' expected.
61-
typescript_standalone.d.ts(11509,28): error TS1005: ';' expected.
62-
typescript_standalone.d.ts(11509,37): error TS1005: ';' expected.
63-
typescript_standalone.d.ts(11513,28): error TS1005: ';' expected.
64-
typescript_standalone.d.ts(11513,37): error TS1005: ';' expected.
51+
typescript_standalone.d.ts(11251,28): error TS1005: ';' expected.
52+
typescript_standalone.d.ts(11251,40): error TS1005: ';' expected.
53+
typescript_standalone.d.ts(11255,28): error TS1005: ';' expected.
54+
typescript_standalone.d.ts(11255,40): error TS1005: ';' expected.
55+
typescript_standalone.d.ts(11285,28): error TS1005: ';' expected.
56+
typescript_standalone.d.ts(11285,40): error TS1005: ';' expected.
57+
typescript_standalone.d.ts(11328,28): error TS1005: ';' expected.
58+
typescript_standalone.d.ts(11328,41): error TS1005: ';' expected.
6559
typescript_standalone.d.ts(11515,28): error TS1005: ';' expected.
6660
typescript_standalone.d.ts(11515,37): error TS1005: ';' expected.
6761
typescript_standalone.d.ts(11517,28): error TS1005: ';' expected.
6862
typescript_standalone.d.ts(11517,37): error TS1005: ';' expected.
69-
typescript_standalone.d.ts(11519,28): error TS1005: ';' expected.
70-
typescript_standalone.d.ts(11519,37): error TS1005: ';' expected.
7163
typescript_standalone.d.ts(11521,28): error TS1005: ';' expected.
7264
typescript_standalone.d.ts(11521,37): error TS1005: ';' expected.
73-
typescript_standalone.d.ts(11530,28): error TS1005: ';' expected.
74-
typescript_standalone.d.ts(11530,37): error TS1005: ';' expected.
75-
typescript_standalone.d.ts(11532,28): error TS1005: ';' expected.
76-
typescript_standalone.d.ts(11532,37): error TS1005: ';' expected.
77-
typescript_standalone.d.ts(11534,28): error TS1005: ';' expected.
78-
typescript_standalone.d.ts(11534,37): error TS1005: ';' expected.
79-
typescript_standalone.d.ts(11536,28): error TS1005: ';' expected.
80-
typescript_standalone.d.ts(11536,37): error TS1005: ';' expected.
65+
typescript_standalone.d.ts(11523,28): error TS1005: ';' expected.
66+
typescript_standalone.d.ts(11523,37): error TS1005: ';' expected.
67+
typescript_standalone.d.ts(11525,28): error TS1005: ';' expected.
68+
typescript_standalone.d.ts(11525,37): error TS1005: ';' expected.
69+
typescript_standalone.d.ts(11527,28): error TS1005: ';' expected.
70+
typescript_standalone.d.ts(11527,37): error TS1005: ';' expected.
71+
typescript_standalone.d.ts(11529,28): error TS1005: ';' expected.
72+
typescript_standalone.d.ts(11529,37): error TS1005: ';' expected.
8173
typescript_standalone.d.ts(11538,28): error TS1005: ';' expected.
8274
typescript_standalone.d.ts(11538,37): error TS1005: ';' expected.
8375
typescript_standalone.d.ts(11540,28): error TS1005: ';' expected.
@@ -100,34 +92,42 @@ typescript_standalone.d.ts(11556,28): error TS1005: ';' expected.
10092
typescript_standalone.d.ts(11556,37): error TS1005: ';' expected.
10193
typescript_standalone.d.ts(11558,28): error TS1005: ';' expected.
10294
typescript_standalone.d.ts(11558,37): error TS1005: ';' expected.
103-
typescript_standalone.d.ts(11568,28): error TS1005: ';' expected.
104-
typescript_standalone.d.ts(11568,37): error TS1005: ';' expected.
105-
typescript_standalone.d.ts(11570,28): error TS1005: ';' expected.
106-
typescript_standalone.d.ts(11570,37): error TS1005: ';' expected.
107-
typescript_standalone.d.ts(11572,28): error TS1005: ';' expected.
108-
typescript_standalone.d.ts(11572,37): error TS1005: ';' expected.
109-
typescript_standalone.d.ts(11574,28): error TS1005: ';' expected.
110-
typescript_standalone.d.ts(11574,37): error TS1005: ';' expected.
95+
typescript_standalone.d.ts(11560,28): error TS1005: ';' expected.
96+
typescript_standalone.d.ts(11560,37): error TS1005: ';' expected.
97+
typescript_standalone.d.ts(11562,28): error TS1005: ';' expected.
98+
typescript_standalone.d.ts(11562,37): error TS1005: ';' expected.
99+
typescript_standalone.d.ts(11564,28): error TS1005: ';' expected.
100+
typescript_standalone.d.ts(11564,37): error TS1005: ';' expected.
101+
typescript_standalone.d.ts(11566,28): error TS1005: ';' expected.
102+
typescript_standalone.d.ts(11566,37): error TS1005: ';' expected.
111103
typescript_standalone.d.ts(11576,28): error TS1005: ';' expected.
112104
typescript_standalone.d.ts(11576,37): error TS1005: ';' expected.
113105
typescript_standalone.d.ts(11578,28): error TS1005: ';' expected.
114106
typescript_standalone.d.ts(11578,37): error TS1005: ';' expected.
115107
typescript_standalone.d.ts(11580,28): error TS1005: ';' expected.
116108
typescript_standalone.d.ts(11580,37): error TS1005: ';' expected.
117109
typescript_standalone.d.ts(11582,28): error TS1005: ';' expected.
118-
typescript_standalone.d.ts(11582,72): error TS1005: ';' expected.
110+
typescript_standalone.d.ts(11582,37): error TS1005: ';' expected.
119111
typescript_standalone.d.ts(11584,28): error TS1005: ';' expected.
120-
typescript_standalone.d.ts(11584,52): error TS1005: ';' expected.
121-
typescript_standalone.d.ts(11656,28): error TS1005: ';' expected.
122-
typescript_standalone.d.ts(11656,72): error TS1005: ';' expected.
123-
typescript_standalone.d.ts(11658,28): error TS1005: ';' expected.
124-
typescript_standalone.d.ts(11658,38): error TS1005: ';' expected.
125-
typescript_standalone.d.ts(11660,28): error TS1005: ';' expected.
126-
typescript_standalone.d.ts(11660,71): error TS1005: ';' expected.
127-
typescript_standalone.d.ts(11662,28): error TS1005: ';' expected.
128-
typescript_standalone.d.ts(11662,40): error TS1005: ';' expected.
129-
typescript_standalone.d.ts(11738,28): error TS1005: ';' expected.
130-
typescript_standalone.d.ts(11738,48): error TS1005: ';' expected.
112+
typescript_standalone.d.ts(11584,37): error TS1005: ';' expected.
113+
typescript_standalone.d.ts(11586,28): error TS1005: ';' expected.
114+
typescript_standalone.d.ts(11586,37): error TS1005: ';' expected.
115+
typescript_standalone.d.ts(11588,28): error TS1005: ';' expected.
116+
typescript_standalone.d.ts(11588,37): error TS1005: ';' expected.
117+
typescript_standalone.d.ts(11590,28): error TS1005: ';' expected.
118+
typescript_standalone.d.ts(11590,72): error TS1005: ';' expected.
119+
typescript_standalone.d.ts(11592,28): error TS1005: ';' expected.
120+
typescript_standalone.d.ts(11592,52): error TS1005: ';' expected.
121+
typescript_standalone.d.ts(11664,28): error TS1005: ';' expected.
122+
typescript_standalone.d.ts(11664,72): error TS1005: ';' expected.
123+
typescript_standalone.d.ts(11666,28): error TS1005: ';' expected.
124+
typescript_standalone.d.ts(11666,38): error TS1005: ';' expected.
125+
typescript_standalone.d.ts(11668,28): error TS1005: ';' expected.
126+
typescript_standalone.d.ts(11668,71): error TS1005: ';' expected.
127+
typescript_standalone.d.ts(11670,28): error TS1005: ';' expected.
128+
typescript_standalone.d.ts(11670,40): error TS1005: ';' expected.
129+
typescript_standalone.d.ts(11746,28): error TS1005: ';' expected.
130+
typescript_standalone.d.ts(11746,48): error TS1005: ';' expected.
131131

132132

133133
==== tests/cases/compiler/APISample_Watch.ts (0 errors) ====

0 commit comments

Comments
 (0)