Skip to content

Commit 093a1e0

Browse files
Copilotjakebailey
andcommitted
Fix panic by checking for binding patterns before calling Text()
The correct fix is to check if a parameter name is a binding pattern before calling Text() on it, rather than making Text() handle binding patterns. This follows the TypeScript reference implementation which checks !isBindingPattern(param.name) before accessing the name's text. Reverted the previous change to ast.go and fixed the caller in checker.go instead. Co-authored-by: jakebailey <[email protected]>
1 parent e16624b commit 093a1e0

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

internal/ast/ast.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,6 @@ func (n *Node) Text() string {
334334
return strings.Join(n.AsJSDocLinkCode().text, "")
335335
case KindJSDocLinkPlain:
336336
return strings.Join(n.AsJSDocLinkPlain().text, "")
337-
case KindObjectBindingPattern, KindArrayBindingPattern:
338-
// Binding patterns don't have a simple text representation
339-
// Return empty string to avoid panics in comparisons
340-
return ""
341337
}
342338
panic(fmt.Sprintf("Unhandled case in Node.Text: %T", n.data))
343339
}

internal/checker/checker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30398,7 +30398,8 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy
3039830398
} else if ast.IsJSDocParameterTag(parent) && parent.Name() == node {
3039930399
if fn := ast.GetNodeAtPosition(ast.GetSourceFileOfNode(node), node.Pos(), false); fn != nil && ast.IsFunctionLike(fn) {
3040030400
for _, param := range fn.Parameters() {
30401-
if param.Name().Text() == node.Text() {
30401+
// Skip binding patterns - they don't have a simple name to compare
30402+
if !ast.IsBindingPattern(param.Name()) && param.Name().Text() == node.Text() {
3040230403
return c.getSymbolOfNode(param)
3040330404
}
3040430405
}

0 commit comments

Comments
 (0)