Skip to content

Commit 8665f92

Browse files
authored
Fixed crash on ComputedPropertyName when computing interactive inlay hints (#61857)
1 parent 36f7fba commit 8665f92

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/services/inlayHints.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
isBindingPattern,
4343
isCallExpression,
4444
isCallSignatureDeclaration,
45+
isComputedPropertyName,
4546
isConditionalTypeNode,
4647
isConstructorTypeNode,
4748
isConstructSignatureDeclaration,
@@ -886,6 +887,12 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] {
886887
Debug.assertNode(node, isThisTypeNode);
887888
parts.push({ text: "this" });
888889
break;
890+
case SyntaxKind.ComputedPropertyName:
891+
Debug.assertNode(node, isComputedPropertyName);
892+
parts.push({ text: "[" });
893+
visitForDisplayParts(node.expression);
894+
parts.push({ text: "]" });
895+
break;
889896
default:
890897
Debug.failBadSyntaxKind(node);
891898
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// === Inlay Hints ===
2+
test((state) => {});
3+
^
4+
{
5+
"text": "",
6+
"displayParts": [
7+
{
8+
"text": ": "
9+
},
10+
{
11+
"text": "{"
12+
},
13+
{
14+
"text": " "
15+
},
16+
{
17+
"text": "["
18+
},
19+
{
20+
"text": "STATE_SIGNAL",
21+
"span": {
22+
"start": 14,
23+
"length": 12
24+
},
25+
"file": "/tests/cases/fourslash/inlayHintsFunctionParameterTypes5.ts"
26+
},
27+
{
28+
"text": "]"
29+
},
30+
{
31+
"text": ": "
32+
},
33+
{
34+
"text": "unknown"
35+
},
36+
{
37+
"text": " "
38+
},
39+
{
40+
"text": "}"
41+
}
42+
],
43+
"position": 143,
44+
"kind": "Type",
45+
"whitespaceBefore": true
46+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// https://github.com/microsoft/TypeScript/issues/61845
4+
5+
//// declare const STATE_SIGNAL: unique symbol;
6+
////
7+
//// declare function test(
8+
//// cb: (state: { [STATE_SIGNAL]: unknown }) => void,
9+
//// ): unknown;
10+
////
11+
//// test((state) => {});
12+
13+
verify.baselineInlayHints(undefined, {
14+
includeInlayFunctionParameterTypeHints: true,
15+
interactiveInlayHints: true,
16+
});

0 commit comments

Comments
 (0)