Skip to content

feat(resolver): resolve this-dispatch on function-as-object property methods (JS) #1334

@carlos-alm

Description

@carlos-alm

Pattern

When a function is used as a namespace-like object with methods assigned as properties, and one of those methods calls `this.other()`, codegraph does not resolve the callee.

Failing example (from Jelly micro-test `this.js`)

```js
function f() {}
f.g = function() { console.log("2"); }
f.h = function() {
this.g(); // this === f when called as f.h()
}
f.h();
```

Expected edge: `f.h → f.g` — not resolved.

Also from the same test, `this.bar()` inside an arrow function returned from an object method:

```js
const o = {
foo() { return () => this.bar(); },
bar() { console.log("3"); },
};
```

Why it's hard

Existing this-dispatch logic is scoped to class bodies. For function-property objects (`fn.method = function() { this.other(); }`), the receiver at call-site `fn.method()` is `fn` itself — not a class instance. Resolving requires:

  1. Detecting the call form `fn.method()` at the call site → receiver is `fn`
  2. Looking up `fn.other` as the callee for `this.other()` inside `method`

Benchmark evidence

Jelly micro-test corpus (tests/benchmarks/resolution/fixtures/jelly-micro/this/):

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