Repository navigation
feat: resolve this.field.method() and variable.field.method() in the TypeScript/JavaScript plugin - #24
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #20.
Constructor-injected dependencies -
constructor(private svc: Service) {}, thenthis.svc.run()- are the standard pattern in Angular and NestJS codebases, and were previously invisible to the graph since the resolver never learnedthis.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, orconst x = new Foo()) plus those field types.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/withrepository.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.analyzerbefore/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 newCatalog.lookup → Repository.findedge; nothing else changed.Background
/code-review mediumpass: no findings.backend.mainstill imports cleanly.