Skip to content

Commit 31304ca

Browse files
authored
Fixed a crash on computed property name when computing inlay hints (#2892)
1 parent 59f44a9 commit 31304ca

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/ls/lsutil"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestInlayHintsPropertyDeclarationComputedName1(t *testing.T) {
12+
t.Parallel()
13+
14+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
15+
const content = `function foo() {
16+
const sym = Symbol();
17+
class C {
18+
[sym] = 123;
19+
}
20+
}`
21+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
22+
defer done()
23+
f.VerifyBaselineInlayHints(t, nil /*span*/, &lsutil.UserPreferences{
24+
InlayHints: lsutil.InlayHintsPreferences{
25+
IncludeInlayPropertyDeclarationTypeHints: true,
26+
},
27+
})
28+
}

internal/ls/inlay_hints.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ func (s *inlayHintState) visitVariableLikeDeclaration(decl *ast.VariableOrProper
245245
hintText = b.String()
246246
}
247247
if !s.preferences.IncludeInlayVariableTypeHintsWhenTypeMatchesName &&
248+
!ast.IsComputedPropertyName(decl.Name()) &&
248249
stringutil.EquateStringCaseInsensitive(decl.Name().Text(), hintText) {
249250
return
250251
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// === Inlay Hints ===
2+
[sym] = 123;
3+
^
4+
{
5+
"position": {
6+
"line": 3,
7+
"character": 9
8+
},
9+
"label": [
10+
{
11+
"value": ": "
12+
},
13+
{
14+
"value": "number"
15+
}
16+
],
17+
"kind": 1,
18+
"paddingLeft": true
19+
}

0 commit comments

Comments
 (0)