Skip to content

JS/TS extractor silently drops calls inside anonymous arrow callbacks (addEventListener, forEach, etc.) #1740

Closed

Description

@50auragawd

Bug

walk_calls in graphify/extract.py stops recursion at every function_boundary_types node. For JS/TS that set includes arrow_function, which is required so module-level named arrows (const f = () => {}) — extracted as their own nodes and walked separately via function_bodies — aren't double-attributed to the enclosing scope.

But anonymous arrow callbacks have no node of their own and no separate body walk, so stopping at them silently drops every call expression inside. Nothing is emitted — not attributed to the enclosing function, not to the module node.

Repro

script.js:

function toggleTask(id) { renderTasks(); }
function removeTask(id) { renderTasks(); }
function renderTasks() {
  tasks.forEach((task) => {
    checkbox.addEventListener('change', () => toggleTask(task.id));
    button.addEventListener('click', () => { removeTask(task.id); });
  });
}

Extracted edges before the fix: toggleTask → renderTasks, removeTask → renderTasks only. The renderTasks → toggleTask (L5) and renderTasks → removeTask (L6) edges are missing entirely, inverting the apparent call-graph topology: renderTasks looks like a pure sink when it actually fans out to the mutators it wires up.

This hits any DOM-heavy vanilla JS codebase (every addEventListener + arrow listener) and any callback-style code (forEach, map, promise .then(() => ...) with arrows). Found while dogfooding a vanilla JS app's graph through the Hermes agent integration (#1403 verification): the agent's data-flow trace flagged the listener wiring as absent/inconsistent in the graph.

Fix

Stop at a function boundary only if that exact AST node is separately walked — i.e. its body is registered in function_bodies. Otherwise recurse into the body under the enclosing function's nid:

  • Build registered_body_ids = {id(body) for _, body in function_bodies} after the extraction pass.
  • In walk_calls, on hitting a boundary node, look up its body via _find_body(node, config); if unregistered, walk_calls(body, caller_nid) instead of returning.

Because the check keys off "is this node walked separately" rather than JS specifics, it also repairs the same silent-drop class in other languages sharing the generic walker (Python nested defs, Java anonymous-class methods).

Regression tests: anonymous callbacks two levels deep (expression-body and block-body arrows) now produce edges attributed to the enclosing function; calls inside registered named arrows are still attributed once, to the arrow only.

Note: on undirected graphs the recovered reciprocal pair (A → B and B → A) still collapses to a single edge at merge time — that's #1392 territory, not this bug.

Activity

  1. 50auragawd commented on Jul 9, 2026

    @50auragawd
    Author

    Already fixed upstream by #1630 (shipped in the 0.9.11 refactor, graphify/extractors/engine.py) — verified the repro extracts all edges correctly on current v8 HEAD. Filed against a stale fork state; apologies for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions