Skip to content

TypeScript/JavaScript: generator function declarations and expressions get no node, so they vanish from the call graph #1741

Description

@Dshuishui

A generator function declared at top level is not indexed — no node, no edges in or out, no warning.

Repro

src/a.ts, the whole project:

function plain() { return 1; }
function* gen() { return 2; }
async function asyncFn() { return 3; }
async function* asyncGen() { return 4; }

After codegraph index:

nodes:  plain · asyncFn

gen and asyncGen are absent. The same holds in .js, and for the expression
form const g = function* () {}.

Why this looks like an oversight rather than a scope decision

Generators are indexed everywhere else:

Where Example Indexed
Class method *m() {} yes
Class method, async async *m() {} yes
Exported object literal export const o = { *m() {} } yes
Top-level declaration function* g() {} no
Top-level, async async function* g() {} no
Function expression const g = function* () {} no

The non-generator form of each missing row is indexed. The only difference is
the *.

Cause

The generator node types are missing from the TS/JS function-type lists — in
both extraction paths, which is worth noting because the native kernel is the
one that runs by default:

// src/extraction/languages/typescript.ts:42
// src/extraction/languages/javascript.ts:6
functionTypes: ['function_declaration', 'arrow_function', 'function_expression'],
// codegraph-kernel/src/tsjs/mod.rs:63
matches!(kind, "function_declaration" | "arrow_function" | "function_expression")

Neither lists generator_function_declaration or generator_function, so the
walker skips those nodes. The type name is already known to the codebase —
src/graph/branch-guards.ts:1297 uses 'generator_function_declaration'.

Scope

Three of CodeGraph's own functions are invisible to CodeGraph:

src/utils.ts:427                                export async function* readFileInChunks(…)
src/resolution/callback-synthesizer.ts:139      function* methodAndFunctionNodes(…)
src/resolution/frameworks/object-literal.ts:59  export function* topLevelObjects(…)

Beyond that, function* is the core idiom of redux-saga and shows up throughout
Effect-TS codebases and hand-written iterators, so on those projects the loss is
not incidental.

The failure is silent: indexing reports success and the caller lists of the
surrounding functions look complete.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions