Skip to content

Commit 2003f8b

Browse files
Copilotjakebailey
andcommitted
Add test case for JSDoc type assertion panic
Co-authored-by: jakebailey <[email protected]>
1 parent bb819a1 commit 2003f8b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

internal/astnav/tokens_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ func TestGetTokenAtPosition(t *testing.T) {
4343
)
4444
})
4545

46+
t.Run("JSDoc type assertion", func(t *testing.T) {
47+
t.Parallel()
48+
fileText := `function foo(x) {
49+
const s = /**@type {string}*/(x)
50+
}`
51+
file := parser.ParseSourceFile(ast.SourceFileParseOptions{
52+
FileName: "/test.js",
53+
Path: "/test.js",
54+
}, fileText, core.ScriptKindJS)
55+
56+
// Position of 'x' inside the parenthesized expression (position 52)
57+
position := 52
58+
59+
// This should not panic
60+
token := astnav.GetTouchingPropertyName(file, position)
61+
if token == nil {
62+
t.Fatal("Expected to get a token, got nil")
63+
}
64+
t.Logf("Got token: kind=%s, pos=%d, end=%d", token.Kind, token.Pos(), token.End())
65+
})
66+
4667
t.Run("pointer equality", func(t *testing.T) {
4768
t.Parallel()
4869
fileText := `

0 commit comments

Comments
 (0)