Skip to content

JS/TS: object-literal shorthand methods are never extracted, so factory/singleton-style modules yield only a file + const node #2419

Open

Description

@mattwwatson

JS/TS: object-literal shorthand methods are never extracted, so factory/singleton-style modules yield only a file + const node

Version: graphifyy 0.9.30 (installed from the v8 checkout) · macOS 15.6 (darwin 24.6) · Python 3.14.6

Summary

The JavaScript/TypeScript extractor captures method_definition nodes inside a
class body, but never inside an object literal. Any codebase that defines
behaviour on object literals — the factory / singleton / module-object pattern
that is extremely common in Node services — therefore contributes only a file
node and a single const node to the graph, with zero methods and zero call
edges into them.

The failure is silent and, worse, flattering: the surviving const node still
accumulates imports edges from every module that imports it, so it shows up
near the top of graphify god-nodes with a high degree. That degree is entirely
"someone imported this module" — none of it is a call relationship. A user
reading god-nodes has no way to tell the difference.

Reproduction

mkdir -p jstest/src && cd jstest
cat > src/a.js <<'EOF'
export class RealClass {
    classMethod() { return 1; }
}
export const topLevelObj = {
    objMethod() { return 2; },
};
export const Factory = service({
    name: "Factory",
    methods: {
        nestedMethod() { return 3; },
        async nestedAsync() { return 4; },
    },
});
export function plainFn() { return 5; }
EOF
graphify update .

Nodes produced:

   .classMethod()      <-- class method: extracted
   Factory             <-- const: extracted (but no methods)
   RealClass
   a.js
   plainFn()
   topLevelObj         <-- const: extracted (but no methods)

Missing: objMethod(), nestedMethod(), nestedAsync().

Note this is not about nesting depth or about the enclosing call expression:
topLevelObj.objMethod() sits in a plain top-level object literal assigned to an
exported const, and is still missed. The discriminator is purely
object literal vs class body.

Impact

On a real Node service codebase using this pattern, every service module
extracted to exactly 2 nodes regardless of size — including one 734-line module
with 18 methods. Measured across an 11-module service layer: ~1,700 LOC and 59
methods produced 22 nodes and 0 method nodes. Controllers and models in the same
repo, which use plain export function / export const declarations, extracted
normally at 5–8 nodes each.

The practical consequence is that explain / query / affected cannot answer
any question about the module's behaviour — "who calls X.someMethod" returns
nothing, with no indication that the symbol was never indexed in the first place.

Expected

Object-literal shorthand methods (and, ideally, function-valued pair entries
such as { handler: function () {} } and { handler: () => {} }) should be
extracted as function nodes owned by the enclosing const, the same way class
methods are.

Pointers

  • graphify/extract.py:738 and :759 already list method_definition in
    function_types for JS and TS respectively, so the node type is recognised —
    it is the traversal that does not reach object-literal bodies.
  • graphify/extractors/engine.py:4675 has an
    elif ct == "method_definition" and not top: branch, and :4733/:4738
    similarly special-case method_definition; those paths appear to assume a
    class-body parent.

In tree-sitter's JavaScript grammar the shorthand form inside an object literal
parses as method_definition under an object node, so this should be
reachable without a grammar change.

Secondary observation

Because the const node survives with only inbound imports edges, these modules
rank highly in god-nodes while being the least understood parts of the graph.
It may be worth either excluding pure-import degree from the god-nodes ranking
or annotating it, so a high-degree node with no outbound call edges is
distinguishable from a genuine architectural hub.

Activity

  1. aryanbonigala commented on Aug 3, 2026

    @aryanbonigala
    Contributor

    I’m investigating this and plan to submit a focused fix with JS/TS regression tests. I’ll keep the initial scope limited to object-literal shorthand methods and avoid unrelated extractor changes.

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