JS namespace calls can resolve to exported object values as functions
Summary
On clean upstream v0.9.106, a call through a whole-module CommonJS binding can produce a calls edge to an exported object literal. The exported value is not callable, so the edge gives a misleading call graph.
Reproduction
Run with the dependencies installed from a clean checkout of v0.9.106:
from contextlib import redirect_stdout
from io import StringIO
from pathlib import Path
from tempfile import TemporaryDirectory
from graphify.extract import extract
with TemporaryDirectory() as tmp:
root = Path(tmp)
module = root / "helpers.js"
user = root / "user.js"
module.write_text("const handler = { a: 1 };\nmodule.exports = { handler };\n", encoding="utf-8")
user.write_text("const m = require('./helpers');\nfunction go() { return m.handler(); }\n", encoding="utf-8")
with redirect_stdout(StringIO()):
graph = extract([module, user], root=root, cache_root=root / "cache", parallel=False)
nodes = {node["id"]: node for node in graph["nodes"]}
calls = [(nodes[e["source"]]["label"], nodes[e["target"]]["label"])
for e in graph["edges"] if e["relation"] == "calls"
and e["source"] in nodes and e["target"] in nodes
and nodes[e["source"]]["label"] == "go()"]
print(calls)
Observed: [('go()', 'handler')]. Expected: no call edge to the object literal.
Related
#5114 added resolution of calls through whole-module imports; the new resolution should also distinguish callable exports from object values.
Thanks for opening this issue, @sub4biz. 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.
Fixed by #5157 (db21c4c6), released in graphify 0.9.107. Thanks @sub4biz for the report and @ayushcodes10 for the fix.