Repository navigation
Description
Summary
The JS/TS extractor captures top-level function declarations, top-level const x = () => … arrows, classes, and class-method shorthand — but silently drops several extremely common ways of defining a named function. On expression-style and CommonJS codebases this means the majority of callable symbols never become nodes (and so can never be call-edge endpoints).
Forms that are missed
| Form | Example | Today |
|---|---|---|
| constructor-assigned method | function UserDAO(db){ this.addUser = () => {} } |
❌ |
this.x = function(){} |
inside any function body | ❌ |
| CommonJS export | exports.foo = () => {} / module.exports.bar = fn |
❌ |
| prototype method | Foo.prototype.baz = function(){} |
❌ |
| class arrow field | class C { onClick = (e) => {} } |
❌ |
const f = function(){} |
function expression (non-arrow) | ❌ |
The first one is the big one: the constructor-function-with-this.method = () => {} pattern is pervasive in pre-class JS (DAOs, route handlers, services). For such a file the extractor emits only the outer function node and none of its methods.
Minimal repro
// probe.js
function declTop(a){ return a; } // ✅ captured
const arrowTop = (b) => b; // ✅ captured
const fnExprTop = function(c){ return c; }; // ❌ missed
exports.exportedArrow = (d) => d; // ❌ missed
module.exports.modArrow = (e) => e; // ❌ missed
Foo.prototype.protoFn = function(){}; // ❌ missed
class Foo { methodInClass(f){ return f; } arrowField = (g) => g; } // method ✅, field ❌
function Outer(db){ this.thisMethod = (h) => h; this.thisFnExpr = function(i){ return i; }; } // ❌ both missedfrom graphify.extract import extract_js
from pathlib import Path
print(sorted(n["label"] for n in extract_js(Path("probe.js"))["nodes"]))
# ['.methodInClass()', 'Foo', 'Outer()', 'arrowTop()', 'declTop()', 'probe.js']
# missing: fnExprTop, exportedArrow, modArrow, protoFn, arrowField, thisMethod, thisFnExprRoot cause
_js_extra_walkonly emits arrow declarations from module-levellexical_declaration, and only forarrow_functionvalues (notfunction_expression).assignment_expression(thethis.X =/exports.X =/Foo.prototype.X =forms) is not handled at all.- Class
field_definition/public_field_definitionwith a function value is not emitted as a method. - The function-emission branch appends the body to
function_bodiesfor the call pass and returns, sothis.X = …assignments inside the body are never visited by the node-emitting walk.
Proposed fix
Extend the JS/TS walk to emit these forms, scoped to avoid the phantom-god-node class (#1077):
exports.X/module.exports.X→ file-contained functionFoo.prototype.X→ method owned byFoothis.X = fnin a function/constructor body → method owned by the enclosing class (if any) else the function- class arrow/function fields → method owned by the class
const f = function(){}→ file-contained function
Arbitrary obj.x = fn (object not this/exports/module.exports/<Name>.prototype) is deliberately not captured, to preserve the #1077 guard.
PR with tests to follow.
Activity
feat: extract JS/TS this.X=, exports.X=, prototype, class arrow field…