Skip to content

JS extractor misses call-expression exports (exports.x = onCall(...)) — HOF-wrapped entry points invisible #3035

Closed

Description

@yongchivo

Version: graphifyy 0.9.49 (uv tool install), Python 3.14.4, macOS (arm64)

Summary

Following on from #2524 (which fixed property-assigned function expressions), the JS extractor still misses function-valued exports whose right-hand side is a call expression rather than a function or arrow. The higher-order-function export idiom — exports.name = wrapper(opts, handler) — produces no node, so the exported symbol is invisible to query, path, and explain.

This matters more than the node count suggests, because in frameworks that use this idiom the wrapped exports are usually the module's only externally reachable entry points. Everything the graph does capture is internal helpers.

Repro

const wrap = (f) => f;

function plainFn() {}                                  // captured
const arrowConst = () => {};                           // captured
const asyncArrow = async () => {};                     // captured
exports.assignedArrow = async (x) => x;                // captured (fixed by #2524)
exports.assignedFn = function namedExpr() {};          // captured (fixed by #2524)
module.exports.viaModule = () => {};                   // captured (fixed by #2524)
export function esmFn() {}                             // captured

exports.assignedCall = wrap(async (x) => x);           // NOT captured
module.exports = { objectKey: () => {} };              // NOT captured
from pathlib import Path
from graphify.extract import extract
r = extract([Path('probe.js')], cache_root=Path('/tmp/probe-cache'))
for n in r['nodes']:
    print(n.get('label'), n.get('source_location'))

Output — 9 nodes, with assignedCall and objectKey absent:

probe.js        L1
wrap()          L1
plainFn()       L2
arrowConst()    L3
asyncArrow()    L4
assignedArrow() L6
assignedFn()    L7
viaModule()     L8
esmFn()         L10

Likely cause

A query matching assignment_expression where the RHS is function_expression / arrow_function will not match when the RHS is a call_expression, even though a function literal appears as one of its arguments.

Why it matters

This is the standard shape of several very common frameworks:

// Firebase Functions v2 — every callable in a functions/index.js
exports.myCallable = onCall({ secrets: [KEY] }, async (request) => { ... });

// Express-style middleware wrappers
exports.handler = asyncHandler(async (req, res) => { ... });

// React
export const Card = React.memo((props) => { ... });
export default connect(mapState)(Component);

In a Firebase Functions entry module, the effect is that the deployed callables are the only symbols not in the graph — the requires, secret bindings, and private helpers are all captured, but the exported endpoints are not. A client calling one of them by name (e.g. httpsCallable('myCallable')) then has no node to resolve against, so the client and backend appear as disconnected components and cross-boundary path queries return nothing. The graph is not wrong about anything it contains; the entry points are simply missing.

Expected

exports.name = someWrapper(..., fn) and module.exports = { name: fn } captured as nodes under name, consistent with the ids already produced for the #2524 forms. Unwrapping only needs to be one level deep to cover the common cases; the binding name on the left is what callers reference, so the node can be keyed on it without analyzing the wrapper.

Happy to test a branch against a Firebase Functions module and report node counts.

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