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

JS: the EventEmitter pass pairs emit/on by event name only and picks the handler by name project-wide

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript, node.js, typescript
领域
tooling

调研方向

Start in src/resolution/callback-synthesizer.ts around lines 385-386, where ctx.getNodesByName(handlerName) takes the first match project-wide, and in the handler map that is keyed only by the event string. Reproduce with the two-module example (src/a_cart.js, src/b_profile.js) using CODEGRAPH_KERNEL=0, then check how the pass knows the registering file and receiver binding. Done means saveProfile links to b_profile's handleSave, no cross links appear, and synthesized edges carry a line.

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

描述

The EventEmitter synthesis pass pairs emitters and handlers by event name alone, and looks up a registered handler by name anywhere in the project. Two modules that each use their own emitter with the same event name and a same-named handler cross-link.

// src/a_cart.js
const EventEmitter = require('events')
const cart = new EventEmitter()
function handleSave () { return 'cart' }
cart.on('save', handleSave)
function saveCart () { cart.emit('save') }

// src/b_profile.js
const EventEmitter = require('events')
const profile = new EventEmitter()
function handleSave () { return 'profile' }
profile.on('save', handleSave)
function saveProfile () { profile.emit('save') }
edge on main (synthesized) expected
saveCart → handleSave (a_cart.js:3) ✓ same
saveProfile → handleSave (a_cart.js:3) ✗ handleSave in b_profile.js

b_profile.js's own handleSave gets no synthesized caller. With distinct handler names (onCartSaved / onProfileSaved), each emitter links to both handlers, so all four cross pairs appear (from an audit run; not re-run here). The synthesized edges also carry no line (line: null).

Cause. callback-synthesizer.ts#L385-L386: ctx.getNodesByName(handlerName).find(...) takes the first function of that name anywhere, not the one in the registering file. The handler map is keyed only by event string, so the receiver (cart vs profile) is never compared.

Reproduced on main at 77ee3484 with CODEGRAPH_KERNEL=0. Linux/WSL2, Node 22.23.2.

Expected. Resolve the handler name in the registering file's scope first (as a bare call there would), and pair emit with on only when the receivers can be the same object (same binding or import), not on the event string alone. Generic names (save, change, error, data) are exactly the ones that collide.

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

环境准备

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

从这里开始

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

colbymchenry/codegraph 的其他 Issue

查看 colbymchenry/codegraph 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

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