diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 0ff050b0a7..b59a382777 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -30398,7 +30398,7 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy } else if ast.IsJSDocParameterTag(parent) && parent.Name() == node { if fn := ast.GetNodeAtPosition(ast.GetSourceFileOfNode(node), node.Pos(), false); fn != nil && ast.IsFunctionLike(fn) { for _, param := range fn.Parameters() { - if param.Name().Text() == node.Text() { + if ast.IsIdentifier(param.Name()) && param.Name().Text() == node.Text() { return c.getSymbolOfNode(param) } } diff --git a/internal/fourslash/tests/manual/findAllRefsJSDocArrayDestructuredParam_test.go b/internal/fourslash/tests/manual/findAllRefsJSDocArrayDestructuredParam_test.go new file mode 100644 index 0000000000..7dbcc3e67c --- /dev/null +++ b/internal/fourslash/tests/manual/findAllRefsJSDocArrayDestructuredParam_test.go @@ -0,0 +1,24 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +// Regression test for panic: "Unhandled case in Node.Text: *ast.BindingPattern" +// This tests array binding patterns specifically. +func TestFindAllRefsJSDocArrayDestructuredParam(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +/** + * @param /*1*/arr - array destructured parameter + */ +function f([x, y]) {} +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/internal/fourslash/tests/manual/findAllRefsJSDocDestructuredParam_test.go b/internal/fourslash/tests/manual/findAllRefsJSDocDestructuredParam_test.go new file mode 100644 index 0000000000..066c4d24fe --- /dev/null +++ b/internal/fourslash/tests/manual/findAllRefsJSDocDestructuredParam_test.go @@ -0,0 +1,25 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/typescript-go/internal/fourslash" + "github.com/microsoft/typescript-go/internal/testutil" +) + +// Regression test for panic: "Unhandled case in Node.Text: *ast.BindingPattern" +// This occurred when requesting findAllReferences with a JSDoc parameter tag +// that referenced a destructured parameter. +func TestFindAllRefsJSDocDestructuredParam(t *testing.T) { + t.Parallel() + + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +/** + * @param /*1*/obj - object destructured parameter + */ +function f({ x, y }) {} +` + f := fourslash.NewFourslash(t, nil /*capabilities*/, content) + f.VerifyBaselineFindAllReferences(t, "1") +} diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJSDocArrayDestructuredParam.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJSDocArrayDestructuredParam.baseline.jsonc new file mode 100644 index 0000000000..35e1555c2e --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJSDocArrayDestructuredParam.baseline.jsonc @@ -0,0 +1,7 @@ +// === findAllReferences === +// === /findAllRefsJSDocArrayDestructuredParam.ts === +// /** +// * @param /*FIND ALL REFS*/arr - array destructured parameter +// */ +// function f([x, y]) {} +// \ No newline at end of file diff --git a/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJSDocDestructuredParam.baseline.jsonc b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJSDocDestructuredParam.baseline.jsonc new file mode 100644 index 0000000000..962605e2c1 --- /dev/null +++ b/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJSDocDestructuredParam.baseline.jsonc @@ -0,0 +1,7 @@ +// === findAllReferences === +// === /findAllRefsJSDocDestructuredParam.ts === +// /** +// * @param /*FIND ALL REFS*/obj - object destructured parameter +// */ +// function f({ x, y }) {} +// \ No newline at end of file