Skip to content

[Bug]: JS/TS: member call binds to a same-named function in the file, so delegating wrappers become false self-loops (#4082 still reproduces on 0.9.93) #4598

Closed

Description

@SaschaAndresGrimm

Summary

In JS and TS, a member call receiver.name(...) is resolved to a function called name declared in the same file, ignoring the receiver. Inside a same-named wrapper, this becomes a calls self-loop marked EXTRACTED.

This is the bug in #4082, which was closed by its reporter after they pruned the edges in their own repo. It still reproduces on 0.9.93, in plain .js as well as .ts, including #4082's own window.confirm example.

Repro (0.9.93, AST only)

app.js:

import { createHistory } from "./history.js";
const history = createHistory();

export function appendFrame(entry) {
  return history.appendFrame(entry);   // delegates to the history object
}

export function confirm(message) {
  return window.confirm(message);      // the #4082 case
}

history.js:

export function createHistory() {
  return { appendFrame: (e) => e };
}
from pathlib import Path
from graphify.extract import extract
root = Path("repro").resolve()
r = extract(sorted(root.glob("*")), cache_root=root, root=root)
print([e["source"] for e in r["edges"]
       if e.get("relation") == "calls" and e["source"] == e["target"]])
# 0.9.92 and 0.9.93, .js and .ts alike: ['app_appendframe', 'app_confirm']

The collision is with any function of that name in the file, not only the enclosing one. With function appendFrame declared elsewhere in the file and a wrapper addFrame calling history.appendFrame(), the graph records addFrame -> appendFrame, which is also wrong.

For comparison: if no function of that name exists in the file, the member call produces no edge. Python does not have this problem; history.append_frame() inside def append_frame produces no self-loop.

Impact in a real project

The repo is a JS frontend whose app.js is a composition root: about 220 wrappers of the form function x(...) { return someController.x(...); }. That file alone yields 219 false self-loops, 92% of all self-loops in a 7.7k-node graph, and graphify diagnose cannot tell them from real recursion.

The bigger problem is the lost edge, not the extra one. Each wrapper's real dependency on the controller method disappears. So "who calls the controller's appendFrame?" misses every caller that goes through the wrapper, and BFS from the wrapper never reaches the module that does the work.

Expected

For receiver.name() where receiver is not this/self:

  • Never bind it to a same-file function by bare name. In particular, never to the enclosing function: a member call cannot be direct recursion.
  • If the receiver can be followed, resolve the method there. Here receiver is a module-level const initialised from an imported factory.
  • Otherwise emit no edge, or an INFERRED/AMBIGUOUS one, rather than an EXTRACTED edge to the wrong node.

Related

Activity

  1. github-actions commented on Oct 20, 2026

    @github-actions

    Thanks for opening this issue, @SaschaAndresGrimm. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. safishamsi commented on Oct 22, 2026

    @safishamsi
    Member
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