TS/JS: a call in a parameter's default value (`f(x = build())`) gets no calls edge
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, typescript, wasm
- Domain
- devtools
Research direction
Start with the repro in the issue: a TypeScript file whose function has a parameter default containing a call, indexed with the WASM extractor. The two places named are extractFunction and extractMethod in src/extraction/tree-sitter.ts, which push the function node and walk only its body. Done means the calls edge from renderWithNote, the arrow function, K.m and destr to buildNote appears, and the existing in-body call edges still pass.
Written by the indexing model from the issue text.
Description
Summary
A call written in a parameter default — function renderWithNote(note = buildNote()) — is not extracted at all: no calls edge and no unresolved reference. The same holds for arrow functions, class methods and destructured parameters with a default. buildNote therefore shows no caller from renderWithNote, and an impact query on buildNote misses it.
Reproduction (verified)
On main at 8fe31569, built from source, Linux (WSL2), Node 22.23.2, WASM extractor (CODEGRAPH_KERNEL=0).
src/f.ts
export function buildNote() { return { id: 1 }; }
export function renderWithNote(note = buildNote()) {
return note.id;
}
codegraph init -i, then every edge that is not contains / imports / exports, and the unresolved refs:
-- edges
(none)
-- unresolved refs
(none)
The same empty result for:
export const arrow = (note = buildNote()) => note.id;
export class K { m(note = buildNote()) { return note.id; } }
export function destr({ n } = buildNote() as any) { return n; }
Control, same file: export function inBody() { const note = buildNote(); return note.id; } gets inBody -[calls L5]-> buildNote, so the call is only lost when it sits in a default.
Observed: no edge from renderWithNote (or arrow, K.m, destr) to buildNote.
Expected: renderWithNote -[calls]-> buildNote. A default is evaluated on every call that omits the argument, inside the function's own scope.
Likely cause (inferred from reading the code)
The grammar does put the call under the parameter ((required_parameter pattern: (identifier) value: (call_expression ...))), but the extractor pushes the function node and walks only its body:
- https://github.com/colbymchenry/codegraph/blob/8fe31569926680af6e5e7d616bf178a6fee053c7/src/extraction/tree-sitter.ts#L2023-L2029 (
extractFunction) - https://github.com/colbymchenry/codegraph/blob/8fe31569926680af6e5e7d616bf178a6fee053c7/src/extraction/tree-sitter.ts#L2289-L2296 (
extractMethod)
I did not find any other place that visits the value of a required_parameter / optional_parameter / assignment_pattern for calls, which matches the empty unresolved_refs above (the call is never seen, rather than seen and left unresolved). Visiting each parameter's default value while the function node is still on nodeStack would attribute the call to the function.
Related
None found.
Not checked
- The Rust kernel path (default,
CODEGRAPH_KERNELunset). Only the WASM extractor was run. - Other languages with default argument expressions (Python's
def f(x=build())is evaluated at definition time, so the right caller there is the enclosing scope rather than the function; Kotlin, Swift, C#, PHP and Ruby evaluate per call like JS). newexpressions andreferences(e.g.x = DEFAULT_CONST) in default values, which are probably missed the same way.
- Dominant language
- C
- Stars
- 73.2k
- Forks
- 4.7k
- Avg merge
- 2h 16m
- Merged PRs (30d)
- 423
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from colbymchenry/codegraph
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
colbymchenry/codegraph#2634 ·
Maintainers usually reply within 1 day
-
Windows: bundled Node v24.16.0 can abort at exit (nodejs/node#56645); please bundle Node >= 24.20.0Possibly taken @Ancienttwo claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
colbymchenry/codegraph#2617 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Under an hour Newbie friendliness 72/100
colbymchenry/codegraph#2482 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
colbymchenry/codegraph#1900 · 2 comments · 5 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
colbymchenry/codegraph#1700 ·
Maintainers usually reply within 1 day
All issues in colbymchenry/codegraph
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
FujiNetWIFI/fujinet-firmware#2079 ·
Maintainers usually reply within 1 day
-
bug Official Image release/25.12 Supported Device target/kirkwood
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
area/archive bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
DarkFlippers/qUnleashed#374 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 84/100
VirusTotal/yara#2255 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100