Skip to content

feat(resolver): track yielded values from generator functions (JS) #1319

@carlos-alm

Description

@carlos-alm

Source

Jelly micro-test benchmark (PR #1304). generators scores 0% recall (0/10 named edges).

Pattern

function* gen() {
    yield () => { console.log("1") };  // yields a function
    yield* gen2();                     // delegates to another generator
}
const x = gen();
const v1 = x.next();
v1.value();  // calls the yielded function — edge: gen.value -> <anon>

function* gen4() {
    const q = yield;  // receives value from .next(val)
    q();              // calls the injected value
}
const y = gen4();
y.next();
y.next(() => { console.log("foo") });  // injects the callback

Named edges missed:

  • gen9 → gen8 (generator delegation via yield*)
  • gen3 → gen9 (calling a generator)
  • Named generator functions calling each other

What's needed

  1. Track yield expr — the expression becomes available as .next().value at the call site
  2. Track yield* — delegates the generator, so edges from the delegate apply to the caller too
  3. Track values passed via .next(val) — the value becomes the result of the yield expression

Generators are a challenging dataflow problem, but a simpler first step:
resolve named generator function calls (e.g., gen9 → gen8 when one generator yield*s another named generator).

Impact

  • 10 named edges in generators fixture
  • Generator-based code (async iterators, Redux sagas, koa middleware) is common

Fixture

tests/benchmarks/resolution/fixtures/jelly-micro/generators/generators.js

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions