Skip to content

Commit 6e87234

Browse files
committed
fix(extractor): resolve arrow-function rest-param bindings via enclosing variable_declarator (#1331)
extractObjectRestParamBindingsWalk checked childForFieldName('name') on every function node, but arrow_function and function_expression nodes have no name field in the tree-sitter grammar — so const f = ({ ...rest }) => {} always produced an undefined funcName and silently skipped the entire parameter scan. Fix: when childForFieldName('name') returns null and the parent node is a variable_declarator, fall back to the declarator's own name field. This mirrors the same pattern used in extractSpreadForOfWalk for arrow functions. Closes the gap reported in the Greptile review (comment 3367102930).
1 parent d387644 commit 6e87234

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/extractors/javascript.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,14 @@ function extractObjectRestParamBindingsWalk(
20702070
if (depth >= MAX_WALK_DEPTH) return;
20712071
const t = node.type;
20722072
if (t === 'function_declaration' || t === 'function_expression' || t === 'arrow_function') {
2073-
const nameNode = node.childForFieldName('name');
2073+
// `function_declaration` has a `name` field; `arrow_function` and
2074+
// `function_expression` do not — get the name from the enclosing
2075+
// `variable_declarator` instead (e.g. `const f3 = ({ ...rest }) => {}`).
2076+
const nameNode =
2077+
node.childForFieldName('name') ??
2078+
(node.parent?.type === 'variable_declarator'
2079+
? node.parent.childForFieldName('name')
2080+
: null);
20742081
const funcName = nameNode?.text;
20752082
if (funcName) {
20762083
const paramsNode =

0 commit comments

Comments
 (0)