Skip to content

Commit e22c1ea

Browse files
committed
fix(extractor): recognize inline-new expression as receiver type in extractReceiverName
When the object of a member call is a `new_expression` (e.g. `new Dog().bark()`) or a parenthesized `new_expression` (e.g. `(new Dog('Rex')).bark()`), `extractReceiverName` now returns the constructor name (e.g. `'Dog'`) directly instead of the raw node text (e.g. `'(new Dog(\'Rex\'))')`). This lets the resolver reach the direct qualified method lookup path (`Dog.bark`) without relying on the text-based regex heuristic that was handling these expressions in `call-resolver.ts`. Closes #1396
1 parent 784951d commit e22c1ea

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/extractors/javascript.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,6 +2516,21 @@ function extractReceiverName(objNode: TreeSitterNode | null): string | undefined
25162516
if (!objNode) return undefined;
25172517
const t = objNode.type;
25182518
if (t === 'identifier' || t === 'this' || t === 'super') return objNode.text;
2519+
// `(new Foo(...)).method()` — extract the constructor name so the resolver can
2520+
// look up `Foo.method` directly without relying on a text-based regex heuristic.
2521+
if (t === 'new_expression') {
2522+
const name = extractNewExprTypeName(objNode);
2523+
if (name) return name;
2524+
}
2525+
if (t === 'parenthesized_expression') {
2526+
for (let i = 0; i < objNode.childCount; i++) {
2527+
const child = objNode.child(i);
2528+
if (child?.type === 'new_expression') {
2529+
const name = extractNewExprTypeName(child);
2530+
if (name) return name;
2531+
}
2532+
}
2533+
}
25192534
return objNode.text;
25202535
}
25212536

0 commit comments

Comments
 (0)