Skip to content

feat: resolve this.field.method() and variable.field.method() in the TypeScript/JavaScript plugin - #24

Merged
MCR-3 merged 1 commit into
mainfrom
20-field-method-chains
Sep 22, 2026
Merged

MCR-3 merged 1 commit into
mainfrom
20-field-method-chains

Conversation

@MCR-3

@MCR-3 MCR-3 commented Sep 22, 2026

Copy link
Copy Markdown
Member

Closes #20.

Constructor-injected dependencies - constructor(private svc: Service) {}, then this.svc.run() - are the standard pattern in Angular and NestJS codebases, and were previously invisible to the graph since the resolver never learned this.svc's type. This tracks each class's field types - constructor parameter properties and typed field declarations - and extends the resolver to unwrap one more hop through them.

  • this.field.method() resolves using the enclosing class's field types.
  • variable.field.method() resolves using the variable's own type (existing local-type tracking: a parameter annotation, const x: Foo, or const x = new Foo()) plus those field types.
  • The field's type name is resolved against the module that declared the field, not the caller's - that's where its import actually lives, so a caller that only imports the field's owner (not the field's own type) still resolves correctly.
  • Getter-backed properties, static field chains (Class.field.method()), and three-or-more-hop chains (this.a.b.c()) all stay unresolved - each falls out of the lookup finding nothing, rather than needing a special case.

Extended sample_typescript_project/ with repository.ts / catalog.ts: a constructor-injected dependency resolved through a parameter property, matching the issue's motivating example.

Verification

Hand-built resolver tests covering every acceptance-criteria case: constructor parameter property, typed field declaration, getter exclusion, three-hop exclusion, static-chain exclusion, parameter-typed and const-typed locals, and cross-module field-type resolution (caller imports only the field's owner class, not the field's own type - resolution still finds the right file via the owner's own imports).

python -m backend.analyzer before/after on all three sample projects:

  • sample_project: 16 functions / 17 edges, byte-identical.
  • sample_rust_project: 8 functions / 6 edges, byte-identical.
  • sample_typescript_project: 18→21 functions, 17→18 edges - exactly the three new fixture functions and the one new Catalog.lookup → Repository.find edge; nothing else changed.

Background /code-review medium pass: no findings. backend.main still imports cleanly.

…TypeScript/JavaScript plugin

Tracks each class's field types - constructor parameter properties
(constructor(private x: Type)) and typed field declarations (x: Type;) -
and extends the resolver to unwrap one more hop through them:
this.field.method() using the enclosing class's field types, and
variable.field.method() using the variable's own type plus those field
types. The field's type name is resolved against the module that declared
the field, not the caller's, since that's where its import actually lives.

Getter-backed properties and static field chains (Class.field.method())
stay unresolved, as does anything three or more hops deep - all
out of scope per the issue, and each just falls out of the lookup finding
nothing rather than needing a special case.

Closes #20
@MCR-3
MCR-3 merged commit 0a3921d into main Sep 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve this.field.method() and variable.field.method() in the TypeScript/JavaScript plugin

1 participant