Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f1668e

Browse files
author
Andy
authored
Use type predicate for getFirstJSDocTag (microsoft#22573)
* Use type predicate for getFirstJSDocTag* Restore API
1 parent3728ec3 commit5f1668e

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

‎src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21471,7 +21471,7 @@ namespace ts {
2147121471
return;
2147221472
}
2147321473

21474-
const augmentsTags =getAllJSDocTagsOfKind(classLike, SyntaxKind.JSDocAugmentsTag);
21474+
const augmentsTags =getJSDocTags(classLike).filter(isJSDocAugmentsTag);
2147521475
Debug.assert(augmentsTags.length > 0);
2147621476
if (augmentsTags.length > 1) {
2147721477
error(augmentsTags[1], Diagnostics.Class_declarations_cannot_have_more_than_one_augments_or_extends_tag);

‎src/compiler/utilities.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4435,33 +4435,33 @@ namespace ts {
44354435
* for example on a variable declaration whose initializer is a function expression.
44364436
*/
44374437
exportfunctionhasJSDocParameterTags(node:FunctionLikeDeclaration|SignatureDeclaration):boolean{
4438-
return!!getFirstJSDocTag(node,SyntaxKind.JSDocParameterTag);
4438+
return!!getFirstJSDocTag(node,isJSDocParameterTag);
44394439
}
44404440

44414441
/** Gets the JSDoc augments tag for the node if present */
44424442
exportfunctiongetJSDocAugmentsTag(node:Node):JSDocAugmentsTag|undefined{
4443-
returngetFirstJSDocTag(node,SyntaxKind.JSDocAugmentsTag)asJSDocAugmentsTag;
4443+
returngetFirstJSDocTag(node,isJSDocAugmentsTag);
44444444
}
44454445

44464446
/** Gets the JSDoc class tag for the node if present */
44474447
exportfunctiongetJSDocClassTag(node:Node):JSDocClassTag|undefined{
4448-
returngetFirstJSDocTag(node,SyntaxKind.JSDocClassTag)asJSDocClassTag;
4448+
returngetFirstJSDocTag(node,isJSDocClassTag);
44494449
}
44504450

44514451
/** Gets the JSDoc return tag for the node if present */
44524452
exportfunctiongetJSDocReturnTag(node:Node):JSDocReturnTag|undefined{
4453-
returngetFirstJSDocTag(node,SyntaxKind.JSDocReturnTag)asJSDocReturnTag;
4453+
returngetFirstJSDocTag(node,isJSDocReturnTag);
44544454
}
44554455

44564456
/** Gets the JSDoc template tag for the node if present */
44574457
exportfunctiongetJSDocTemplateTag(node:Node):JSDocTemplateTag|undefined{
4458-
returngetFirstJSDocTag(node,SyntaxKind.JSDocTemplateTag)asJSDocTemplateTag;
4458+
returngetFirstJSDocTag(node,isJSDocTemplateTag);
44594459
}
44604460

44614461
/** Gets the JSDoc type tag for the node if present and valid */
44624462
exportfunctiongetJSDocTypeTag(node:Node):JSDocTypeTag|undefined{
44634463
// We should have already issued an error if there were multiple type jsdocs, so just use the first one.
4464-
consttag=getFirstJSDocTag(node,SyntaxKind.JSDocTypeTag)asJSDocTypeTag;
4464+
consttag=getFirstJSDocTag(node,isJSDocTypeTag);
44654465
if(tag&&tag.typeExpression&&tag.typeExpression.type){
44664466
returntag;
44674467
}
@@ -4480,7 +4480,7 @@ namespace ts {
44804480
* tag directly on the node would be returned.
44814481
*/
44824482
exportfunctiongetJSDocType(node:Node):TypeNode|undefined{
4483-
lettag:JSDocTypeTag|JSDocParameterTag=getFirstJSDocTag(node,SyntaxKind.JSDocTypeTag)asJSDocTypeTag;
4483+
lettag:JSDocTypeTag|JSDocParameterTag|undefined=getFirstJSDocTag(node,isJSDocTypeTag);
44844484
if(!tag&&isParameter(node)){
44854485
tag=find(getJSDocParameterTags(node),tag=>!!tag.typeExpression);
44864486
}
@@ -4500,7 +4500,7 @@ namespace ts {
45004500
}
45014501

45024502
/** Get all JSDoc tags related to a node, including those on parent nodes. */
4503-
exportfunctiongetJSDocTags(node:Node):ReadonlyArray<JSDocTag>|undefined{
4503+
exportfunctiongetJSDocTags(node:Node):ReadonlyArray<JSDocTag>{
45044504
lettags=(nodeasJSDocContainer).jsDocCache;
45054505
// If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing.
45064506
if(tags===undefined){
@@ -4510,17 +4510,14 @@ namespace ts {
45104510
}
45114511

45124512
/** Get the first JSDoc tag of a specified kind, or undefined if not present. */
4513-
functiongetFirstJSDocTag(node:Node,kind:SyntaxKind):JSDocTag|undefined{
4514-
consttags=getJSDocTags(node);
4515-
returnfind(tags,doc=>doc.kind===kind);
4513+
functiongetFirstJSDocTag<TextendsJSDocTag>(node:Node,predicate:(tag:JSDocTag)=>tag isT):T|undefined{
4514+
returnfind(getJSDocTags(node),predicate);
45164515
}
45174516

45184517
/** Gets all JSDoc tags of a specified kind, or undefined if not present. */
45194518
exportfunctiongetAllJSDocTagsOfKind(node:Node,kind:SyntaxKind):ReadonlyArray<JSDocTag>|undefined{
4520-
consttags=getJSDocTags(node);
4521-
returnfilter(tags,doc=>doc.kind===kind);
4519+
returngetJSDocTags(node).filter(doc=>doc.kind===kind);
45224520
}
4523-
45244521
}
45254522

45264523
// Simple node tests of the form `node.kind === SyntaxKind.Foo`.
@@ -5163,6 +5160,10 @@ namespace ts {
51635160
returnnode.kind===SyntaxKind.JSDocAugmentsTag;
51645161
}
51655162

5163+
exportfunctionisJSDocClassTag(node:Node):node isJSDocClassTag{
5164+
returnnode.kind===SyntaxKind.JSDocClassTag;
5165+
}
5166+
51665167
exportfunctionisJSDocParameterTag(node:Node):node isJSDocParameterTag{
51675168
returnnode.kind===SyntaxKind.JSDocParameterTag;
51685169
}

‎tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ declare namespace ts {
30343034
*/
30353035
functiongetJSDocReturnType(node:Node):TypeNode|undefined;
30363036
/** Get all JSDoc tags related to a node, including those on parent nodes. */
3037-
functiongetJSDocTags(node:Node):ReadonlyArray<JSDocTag>|undefined;
3037+
functiongetJSDocTags(node:Node):ReadonlyArray<JSDocTag>;
30383038
/** Gets all JSDoc tags of a specified kind, or undefined if not present. */
30393039
functiongetAllJSDocTagsOfKind(node:Node,kind:SyntaxKind):ReadonlyArray<JSDocTag>|undefined;
30403040
}
@@ -3190,6 +3190,7 @@ declare namespace ts {
31903190
functionisJSDocVariadicType(node:Node):node isJSDocVariadicType;
31913191
functionisJSDoc(node:Node):node isJSDoc;
31923192
functionisJSDocAugmentsTag(node:Node):node isJSDocAugmentsTag;
3193+
functionisJSDocClassTag(node:Node):node isJSDocClassTag;
31933194
functionisJSDocParameterTag(node:Node):node isJSDocParameterTag;
31943195
functionisJSDocReturnTag(node:Node):node isJSDocReturnTag;
31953196
functionisJSDocTypeTag(node:Node):node isJSDocTypeTag;

‎tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,7 @@ declare namespace ts {
30893089
*/
30903090
functiongetJSDocReturnType(node:Node):TypeNode|undefined;
30913091
/** Get all JSDoc tags related to a node, including those on parent nodes. */
3092-
functiongetJSDocTags(node:Node):ReadonlyArray<JSDocTag>|undefined;
3092+
functiongetJSDocTags(node:Node):ReadonlyArray<JSDocTag>;
30933093
/** Gets all JSDoc tags of a specified kind, or undefined if not present. */
30943094
functiongetAllJSDocTagsOfKind(node:Node,kind:SyntaxKind):ReadonlyArray<JSDocTag>|undefined;
30953095
}
@@ -3245,6 +3245,7 @@ declare namespace ts {
32453245
functionisJSDocVariadicType(node:Node):node isJSDocVariadicType;
32463246
functionisJSDoc(node:Node):node isJSDoc;
32473247
functionisJSDocAugmentsTag(node:Node):node isJSDocAugmentsTag;
3248+
functionisJSDocClassTag(node:Node):node isJSDocClassTag;
32483249
functionisJSDocParameterTag(node:Node):node isJSDocParameterTag;
32493250
functionisJSDocReturnTag(node:Node):node isJSDocReturnTag;
32503251
functionisJSDocTypeTag(node:Node):node isJSDocTypeTag;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp