Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

TypeScript: this.m() links to an imported function m instead of the class's own m

未关闭
#2,954 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
devtools

调研方向

Start from the import-binding path that answers a call edge, since the issue notes the this. receiver is lost before the bare refName reaches it; trace how this.groupDefinitions(...) at src/mcp/tools.ts line 3250 resolves into src/graph/symbol-lookup.ts. Compare with the same-class member ranking mentioned in 25776014, and inspect src/graph/named-symbol-flow.ts for the findAllSymbols case. Done means this.m() and super.m() edges point at the class member, not the file import; reproduce with CODEGRAPH_KERNEL=0 and check the cited repo edges.

由索引模型根据 Issue 内容生成。

描述

this.m() inside a class links to a function m that the file imports, not to the class's own m. This is the common case of a class wrapping a helper of the same name.

// lib.ts
export function findAll(q: string): string[] { return [q]; }
export const getFactor = (w: number): number => w;

// tools.ts
import { findAll, getFactor } from './lib';
export class Tools {
  run(q: string) { return this.findAll(q); }                               // line 3
  private findAll(q: string): string[] { return findAll(q).concat('own'); } // line 4
  size(w: number) { return this.getFactor(w); }                            // line 5
  private getFactor = (w: number): number => getFactor(w) * 2;             // line 6
}
call edge on main expected
line 3 this.findAll(q) lib.ts findAll (resolvedBy: import) ✗ Tools.findAll (line 4)
line 4 findAll(q) lib.ts findAll ✓ same
line 5 this.getFactor(w) lib.ts getFactor (resolvedBy: import) ✗ Tools.getFactor (line 6)
line 6 getFactor(w) lib.ts getFactor ✓ same

The class's own findAll and getFactor get no callers from run/size, and the import gets callers that never call it directly. The edge's refName is the bare name (findAll), so the this. receiver is already lost by the time the import binding answers.

Reproduced on main at 25776014 with CODEGRAPH_KERNEL=0. Linux/WSL2, Node 22.23.2. 25776014 ("a call on the caller's own class reaches that class's member") doesn't change this: that path ranks same-named methods, and here the import answers first.

In this repo. ToolHandler in src/mcp/tools.ts imports groupDefinitions from ../graph/symbol-lookup and also has a private groupDefinitions(...) (line 3220). this.groupDefinitions(allMatches.nodes, fileFilter) at line 3250 links to src/graph/symbol-lookup.ts. this.findAllSymbols(cg, symbol) at lines 3245 and 3328 does the same with src/graph/named-symbol-flow.ts, ignoring the class's own findAllSymbols (line 8675). I counted 7 such edges in the index of this repo, and 1 in excalidraw (this.getFormFactor(…) in App.tsx → packages/common/src/editorInterface.ts, ignoring App's private getFormFactor = …). Found by checking every TS calls edge against the TypeScript checker.

Expected. A call with a this. (or super.) receiver should never resolve through the file's import bindings. It names a member, not a binding in scope.

Related: 25776014 / #1952 (own-class members for this. calls), #2953 (x.m() resolved through the import of x).

主要语言
C
星标
73.2k
派生
4.7k
平均合并
3 小时 31 分钟
30 天内合并 PR
546

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

colbymchenry/codegraph 的其他 Issue

查看 colbymchenry/codegraph 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。