Skip to content

Commit 1b1530a

Browse files
authored
fix(47713): allow JSDoc tags on CaseClause nodes (#47741)
1 parent 67f47bf commit 1b1530a

File tree

6 files changed

+85
-6
lines changed

6 files changed

+85
-6
lines changed

src/compiler/parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6005,11 +6005,12 @@ namespace ts {
60056005

60066006
function parseCaseClause(): CaseClause {
60076007
const pos = getNodePos();
6008+
const hasJSDoc = hasPrecedingJSDocComment();
60086009
parseExpected(SyntaxKind.CaseKeyword);
60096010
const expression = allowInAnd(parseExpression);
60106011
parseExpected(SyntaxKind.ColonToken);
60116012
const statements = parseList(ParsingContext.SwitchClauseStatements, parseStatement);
6012-
return finishNode(factory.createCaseClause(expression, statements), pos);
6013+
return withJSDoc(finishNode(factory.createCaseClause(expression, statements), pos), hasJSDoc);
60136014
}
60146015

60156016
function parseDefaultClause(): DefaultClause {

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,7 @@ namespace ts {
930930
| ExportDeclaration
931931
| NamedTupleMember
932932
| ExportSpecifier
933+
| CaseClause
933934
| EndOfFileToken
934935
;
935936

@@ -2801,7 +2802,7 @@ namespace ts {
28012802
readonly clauses: NodeArray<CaseOrDefaultClause>;
28022803
}
28032804

2804-
export interface CaseClause extends Node {
2805+
export interface CaseClause extends Node, JSDocContainer {
28052806
readonly kind: SyntaxKind.CaseClause;
28062807
readonly parent: CaseBlock;
28072808
readonly expression: Expression;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ declare namespace ts {
572572
}
573573
export interface JSDocContainer {
574574
}
575-
export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | EndOfFileToken;
575+
export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | CaseClause | EndOfFileToken;
576576
export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType;
577577
export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement;
578578
export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute;
@@ -1498,7 +1498,7 @@ declare namespace ts {
14981498
readonly parent: SwitchStatement;
14991499
readonly clauses: NodeArray<CaseOrDefaultClause>;
15001500
}
1501-
export interface CaseClause extends Node {
1501+
export interface CaseClause extends Node, JSDocContainer {
15021502
readonly kind: SyntaxKind.CaseClause;
15031503
readonly parent: CaseBlock;
15041504
readonly expression: Expression;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ declare namespace ts {
572572
}
573573
export interface JSDocContainer {
574574
}
575-
export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | EndOfFileToken;
575+
export type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ClassStaticBlockDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | VariableDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | NamespaceExportDeclaration | ExportAssignment | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | ExportDeclaration | NamedTupleMember | ExportSpecifier | CaseClause | EndOfFileToken;
576576
export type HasType = SignatureDeclaration | VariableDeclaration | ParameterDeclaration | PropertySignature | PropertyDeclaration | TypePredicateNode | ParenthesizedTypeNode | TypeOperatorNode | MappedTypeNode | AssertionExpression | TypeAliasDeclaration | JSDocTypeExpression | JSDocNonNullableType | JSDocNullableType | JSDocOptionalType | JSDocVariadicType;
577577
export type HasTypeArguments = CallExpression | NewExpression | TaggedTemplateExpression | JsxOpeningElement | JsxSelfClosingElement;
578578
export type HasInitializer = HasExpressionInitializer | ForStatement | ForInStatement | ForOfStatement | JsxAttribute;
@@ -1498,7 +1498,7 @@ declare namespace ts {
14981498
readonly parent: SwitchStatement;
14991499
readonly clauses: NodeArray<CaseOrDefaultClause>;
15001500
}
1501-
export interface CaseClause extends Node {
1501+
export interface CaseClause extends Node, JSDocContainer {
15021502
readonly kind: SyntaxKind.CaseClause;
15031503
readonly parent: CaseBlock;
15041504
readonly expression: Expression;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/quickInfoLink4.ts",
5+
"position": 47,
6+
"name": ""
7+
},
8+
"quickInfo": {
9+
"kind": "type",
10+
"kindModifiers": "",
11+
"textSpan": {
12+
"start": 47,
13+
"length": 1
14+
},
15+
"displayParts": [
16+
{
17+
"text": "type",
18+
"kind": "keyword"
19+
},
20+
{
21+
"text": " ",
22+
"kind": "space"
23+
},
24+
{
25+
"text": "A",
26+
"kind": "aliasName"
27+
},
28+
{
29+
"text": " ",
30+
"kind": "space"
31+
},
32+
{
33+
"text": "=",
34+
"kind": "operator"
35+
},
36+
{
37+
"text": " ",
38+
"kind": "space"
39+
},
40+
{
41+
"text": "1",
42+
"kind": "stringLiteral"
43+
},
44+
{
45+
"text": " ",
46+
"kind": "space"
47+
},
48+
{
49+
"text": "|",
50+
"kind": "punctuation"
51+
},
52+
{
53+
"text": " ",
54+
"kind": "space"
55+
},
56+
{
57+
"text": "2",
58+
"kind": "stringLiteral"
59+
}
60+
],
61+
"documentation": []
62+
}
63+
}
64+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
///<reference path="fourslash.ts" />
2+
3+
////type A = 1 | 2;
4+
////
5+
////switch (0 as A) {
6+
//// /** {@link /**/A} */
7+
//// case 1:
8+
//// case 2:
9+
//// break;
10+
////}
11+
12+
verify.noErrors()
13+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)