-
Notifications
You must be signed in to change notification settings - Fork 13
fix(extractor): recognize inline-new expression as receiver type in extractReceiverName #1415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e22c1ea
ca5065b
3074e93
d8a329d
308cd08
953d815
be501a1
33888dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2676,6 +2676,25 @@ function extractReceiverName(objNode: TreeSitterNode | null): string | undefined | |
| if (!objNode) return undefined; | ||
| const t = objNode.type; | ||
| if (t === 'identifier' || t === 'this' || t === 'super') return objNode.text; | ||
| // `(new Foo(...)).method()` — extract the constructor name so the resolver can | ||
| // look up `Foo.method` directly without relying on a text-based regex heuristic. | ||
| if (t === 'new_expression') { | ||
| const name = extractNewExprTypeName(objNode); | ||
| if (name) return name; | ||
| } | ||
| if (t === 'parenthesized_expression') { | ||
| // Only one level of parentheses is unwrapped here. Doubly-nested parens | ||
| // (e.g. `((new Dog())).bark()`) and cast expressions inside parens | ||
| // (e.g. `(new Dog() as Animal).bark()`) fall through to raw-text handling | ||
| // below and are caught by the regex fallback in call-resolver.ts. | ||
| for (let i = 0; i < objNode.childCount; i++) { | ||
| const child = objNode.child(i); | ||
| if (child?.type === 'new_expression') { | ||
| const name = extractNewExprTypeName(child); | ||
| if (name) return name; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+2679
to
+2697
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The block at Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed — updated the stale comment in |
||
| return objNode.text; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?in outer loop silently truncates the searchdeclarator.child(i)?uses the?operator, so if any child slot returnsNonethe entire function returnsNoneimmediately, abandoning all remaining children. In contrast, the inner loop on line 450 correctly usesif let Some(expr)to continue past missing slots. The TypeScript mirror of this function also uses optional-chaining (child?.type) for the same reason. If tree-sitter ever produces a gap in the child list (which theOptionreturn type explicitly allows), this outer loop would silently stop and return no type for a valid initializer that appears later in the declarator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in d8a329d — replaced
declarator.child(i)?withlet Some(child) = declarator.child(i) else { continue }, matching the inner loop's pattern. Now skips None child slots instead of aborting the entire search.