Skip to content

Commit 865c8d0

Browse files
CopilotRyanCavanaughgabritto
authored
Fix panic in getClassElementPropertyKeyType for private identifiers (#3819)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> Co-authored-by: Gabriela Araujo Britto <gabrielaa@microsoft.com> Co-authored-by: Gabriela Araujo Britto <garaujobritto@gmail.com>
1 parent 3215d45 commit 865c8d0

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30220,7 +30220,7 @@ func (c *Checker) getClassElementPropertyKeyType(element *ast.Node) *Type {
3022030220
}
3022130221
return c.stringType
3022230222
}
30223-
panic("Unhandled case in getClassElementPropertyKeyType")
30223+
return c.errorType
3022430224
}
3022530225

3022630226
func (c *Checker) getTypeOfPropertyOfContextualType(t *Type, name string) *Type {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/fourslash/tests/util"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestDecoratorCompletionOnPrivateMethod(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
const content = `
15+
// @experimentalDecorators: true
16+
declare function dec(target: any, key: string): void;
17+
class C {
18+
@dec/**/
19+
#method() {}
20+
}`
21+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
22+
defer done()
23+
// Verify completions don't panic on decorator applied to private method
24+
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
25+
IsIncomplete: false,
26+
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
27+
CommitCharacters: &DefaultCommitCharacters,
28+
EditRange: Ignored,
29+
},
30+
Items: &fourslash.CompletionsExpectedItems{
31+
Includes: []fourslash.CompletionsExpectedItem{
32+
"dec",
33+
},
34+
},
35+
})
36+
}

0 commit comments

Comments
 (0)