Skip to content

feat(resolver): track array spread and Array.from/concat/flat callbacks (JS) #1321

@carlos-alm

Description

@carlos-alm

Source

Jelly micro-test benchmark (PR #1304). spread scores 0% (0/4 named edges), more1 scores 0% (0/17 named edges).

Patterns

Spread operator in function arguments

// spread.js
function f(a1, a2, a3) { a1(); a2(); a3(); }
const xs = [() => {}, () => {}];
f(...xs, () => {});
// ← xs[0] and xs[1] are a1, a2; should resolve f's calls to their values

Array.from with mapping callback

// more1.js
const a1 = [() => {}];
Array.from(a1, function(element) {
    element();  // ← element is each item from a1
    this.f();   // ← this = context object
});

Array.concat combining arrays of functions

const a6 = [[() => {}], ...];
const a8 = a6.concat(a7, () => {});
a8[0][0]();  // ← should resolve nested array access

Set/Map iteration

const a1 = [() => {}];
const s1 = new Set(a1);
for (const f of s1) f();  // ← f is each item from a1

What's needed

These are all variations of array element tracking — knowing what values end up in specific array indices or iterable positions:

  1. ...arr in call: elements of arr become the spread arguments
  2. Array.from(arr, fn): fn receives elements of arr
  3. arr.concat(...): merges arrays; index-based access resolves elements
  4. for (x of iterable): x takes each value from the iterable

These require lightweight array-contents tracking — a form of points-to analysis for array elements.

Impact

  • 4 edges in spread, 17 edges in more1 (21 total)
  • Common in functional JS patterns, utility libraries, test frameworks

Fixture

tests/benchmarks/resolution/fixtures/jelly-micro/spread/spread.js
tests/benchmarks/resolution/fixtures/jelly-micro/more1/more1.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