Skip to content

feat(resolver): track constructor-assigned property types for receiver-typed resolution (JS/TS) #1306

@carlos-alm

Description

@carlos-alm

Context

The Jelly comparison in #1304 showed that codegraph misses 3 JavaScript receiver-typed edges where the receiver type is assigned through a constructor property write:

class UserService {
  constructor() {
    this.logger = new Logger('UserService');  // property write
  }
  createUser(data) {
    this.logger.error('...');  // ← codegraph misses this (FN)
    this.logger.info('...');   // ← codegraph misses this (FN)
  }
  deleteUser(id) {
    this.logger.warn('...');   // ← codegraph misses this (FN)
  }
}

Jelly resolves all three correctly because its whole-program points-to analysis tracks property writes (this.logger = new Logger()) and reads them back when resolving this.logger.method().

Codegraph resolves return-type–based receiver-typed edges (e.g. svc = buildService()UserServicesvc.createUser()) but not property-write–based receiver-typed edges.

What's needed

In the import resolver / points-to analysis layer:

  1. During graph building, record this.prop = new ClassName() assignments alongside the function/method they appear in
  2. When resolving a call this.prop.method(), look up the recorded type for this.prop in the enclosing class
  3. Use the resolved class type to find the target method (same mechanism as the existing this.method() receiver-typed resolution)

This is an extension of the existing property-write tracking introduced in Phase 8.3d (feat(resolver): phase 8.3d — object property write tracking in points-to analysis).

Expected impact

+3 edges on the JS fixture (Logger.error, Logger.info, Logger.warn as targets of this.logger.* calls in UserService). Likely helps broadly across all OOP-heavy JS/TS codebases.

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