Skip to content

feat(resolver): resolve class instance method calls via constructor-assigned receiver type (JS) #1316

@carlos-alm

Description

@carlos-alm

Source

Jelly micro-test benchmark (PR #1304). classes scores 9% recall (3/32 edges), classes2 0% (0/18). Most misses are instance method calls on new-constructed objects.

Pattern

class C1 {
    constructor() { f1(); }
    f7(y) { return y(); }
    f8 = () => { return f1; }
}
let t2 = new C1;
t2.f7(f2);    // ← missed: t2 is C1, should resolve C1.f7
let t222 = t2.f8();  // ← missed: field accessor, resolves C1.f8

Also includes static class members:

class C6 {
    static staticMethod() { return f1(); }  // ← f1->C6.staticMethod missed
    static { f1(); }                        // ← static block call missed
}
C6.staticMethod();  // ← missed

Root cause

Codegraph tracks new ClassName() constructors but doesn't associate the resulting instance variable's type with the class. So t2.f7() is unresolved because codegraph doesn't know t2: C1.

The same gap affects class field arrows (f8 = () => ...) and static member access (C6.staticMethod).

What's needed

  1. new-assignment type tracking: when const x = new Foo(), record x: Foo as a type annotation
  2. Static member resolution: ClassName.method() calls should resolve directly to the class's static method without needing instance tracking
  3. Static block calls: calls inside static { ... } blocks should be attributed to the class

Impact

Fixture

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