Summary
Both engines' dynamic-import()/CJS-require() name-collection helpers have a rest_pattern/rest_element branch that reads the identifier from the wrong child index, so it never actually extracts the rest-bound name.
- Rust (
crates/codegraph-core/src/extractors/javascript.rs, extract_rest_identifier, used by collect_array_pattern_names and collect_object_pattern_names): reads rest_node.child(0) and checks .kind() == "identifier".
- WASM/TS (
src/extractors/javascript.ts, extractDynamicImportNames's array_pattern branch): reads child.child(0) || child.childForFieldName('name'), then checks .type === 'identifier'.
Evidence
Direct AST inspection of const [a, ...rest] = fn(); (tree-sitter-javascript grammar):
array_pattern ["[a, ...rest]"]
identifier ["a"]
rest_pattern ["...rest"]
... ["..."] <- child(0)
identifier ["rest"] <- child(1)
child(0) of a rest_pattern is always the ... token itself, not the bound identifier — the identifier is at child(1). So both helpers' identifier check always fails and the rest binding is silently dropped.
The correct pattern already exists elsewhere in the same file and is proven working: extractParameters's own rest_pattern branch (src/extractors/javascript.ts line ~1833) uses child.child(1) || child.childForFieldName('name'), and the Rust parameter-extraction equivalent (crates/codegraph-core/src/extractors/javascript.rs ~line 2295-2307) scans all children for an identifier kind instead of assuming index 0.
Impact
const [a, ...rest] = await import('./mod.js') never registers rest as an imported/destructured name — rest's properties/usages can't be attributed back to the dynamic import.
const { a, ...rest } = require('./mod') (Rust collect_object_pattern_names) has the same issue for CJS require rest bindings.
Suggested fix
Fix extract_rest_identifier (Rust) to scan the rest node's children for the identifier kind (mirroring the working parameter-extraction code), and fix the array_pattern/rest branch in extractDynamicImportNames (TS) to use child.child(1) (mirroring extractParameters's own rest_pattern branch), for both array and object pattern rest bindings, in both engines.
Discovered while investigating #1901 (array-pattern destructuring Definition extraction) — unrelated code path, out of scope there.
Summary
Both engines' dynamic-
import()/CJS-require()name-collection helpers have arest_pattern/rest_elementbranch that reads the identifier from the wrong child index, so it never actually extracts the rest-bound name.crates/codegraph-core/src/extractors/javascript.rs,extract_rest_identifier, used bycollect_array_pattern_namesandcollect_object_pattern_names): readsrest_node.child(0)and checks.kind() == "identifier".src/extractors/javascript.ts,extractDynamicImportNames'sarray_patternbranch): readschild.child(0) || child.childForFieldName('name'), then checks.type === 'identifier'.Evidence
Direct AST inspection of
const [a, ...rest] = fn();(tree-sitter-javascript grammar):child(0)of arest_patternis always the...token itself, not the bound identifier — the identifier is atchild(1). So both helpers' identifier check always fails and the rest binding is silently dropped.The correct pattern already exists elsewhere in the same file and is proven working:
extractParameters's ownrest_patternbranch (src/extractors/javascript.tsline ~1833) useschild.child(1) || child.childForFieldName('name'), and the Rust parameter-extraction equivalent (crates/codegraph-core/src/extractors/javascript.rs~line 2295-2307) scans all children for anidentifierkind instead of assuming index 0.Impact
const [a, ...rest] = await import('./mod.js')never registersrestas an imported/destructured name —rest's properties/usages can't be attributed back to the dynamic import.const { a, ...rest } = require('./mod')(Rustcollect_object_pattern_names) has the same issue for CJS require rest bindings.Suggested fix
Fix
extract_rest_identifier(Rust) to scan the rest node's children for theidentifierkind (mirroring the working parameter-extraction code), and fix thearray_pattern/rest branch inextractDynamicImportNames(TS) to usechild.child(1)(mirroringextractParameters's own rest_pattern branch), for both array and object pattern rest bindings, in both engines.Discovered while investigating #1901 (array-pattern destructuring Definition extraction) — unrelated code path, out of scope there.