Skip to content

Commit cbe994f

Browse files
Copilotjakebailey
andcommitted
Add additional test case for JSDoc type assertion with comment
Co-authored-by: jakebailey <[email protected]>
1 parent 563d999 commit cbe994f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/astnav/tokens_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ func TestGetTokenAtPosition(t *testing.T) {
7070
}
7171
})
7272

73+
t.Run("JSDoc type assertion with comment", func(t *testing.T) {
74+
t.Parallel()
75+
// Exact code from the issue report
76+
fileText := `function foo(x) {
77+
const s = /**@type {string}*/(x) // Go-to-definition on x causes panic
78+
}`
79+
file := parser.ParseSourceFile(ast.SourceFileParseOptions{
80+
FileName: "/test.js",
81+
Path: "/test.js",
82+
}, fileText, core.ScriptKindJS)
83+
84+
// Find position of 'x' in the type assertion
85+
xPos := 52 // Position of 'x' in (x)
86+
87+
// This should not panic
88+
token := astnav.GetTouchingPropertyName(file, xPos)
89+
assert.Assert(t, token != nil, "Expected to get a token")
90+
})
91+
7392
t.Run("pointer equality", func(t *testing.T) {
7493
t.Parallel()
7594
fileText := `

0 commit comments

Comments
 (0)