TS/JS: a call in a parameter's default value (`f(x = build())`) gets no calls edge
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 65/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, typescript, wasm
- 领域
- devtools
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- C
- 星标
- 73.2k
- 派生
- 4.7k
- 平均合并
- 3 小时 39 分钟
- 30 天内合并 PR
- 528
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
colbymchenry/codegraph 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
colbymchenry/codegraph#3223 ·
维护者通常 1 天内回复
-
A `../` entry in package.json `workspaces` makes a folder outside the project count as a workspace package, and a call gets linked to the wrong function可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
colbymchenry/codegraph#3093 ·
维护者通常 1 天内回复
-
Windows: npm-shim spawnSync missing windowsHide flashes a console window on every MCP server launch未关闭
难度 2/5 1-3 小时 新手友好度 86/100
colbymchenry/codegraph#3054 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
colbymchenry/codegraph#2974 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
colbymchenry/codegraph#2959 · 3 条评论 ·
维护者通常 1 天内回复
查看 colbymchenry/codegraph 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
ai-driven-fuzzing bug claude Minor
难度 2/5 1-3 小时 新手友好度 78/100
linagora/open-bastion#425 ·
维护者通常 1 天内回复
-
question
难度 1/5 1 小时以内 新手友好度 68/100
-
follow-up Prio 📌
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
moonbitlang/async#713 ·
维护者通常 1 天内回复