[JS/TS] Parse Intra-file References - Scope Aware Resolution
Problem to solve
Currently, most common JS/TS intra-file references are resolved, but there is a long tail of use cases we don't support yet, as the scope-aware resolution infrastructure is still being worked on.
Tracked but Not Resolved References
| Reference Type | Example |
|---|---|
| Array/Object Indexing Calls | this.processingQueue[varName]() |
| Member Expression Chains | this.emailService.sendEmail().then() |
| Assignment Tracking | const handler = factory.createHandler(); handler.process() |
| Enum Access | Direction.Up |
| Import Usage | import { api } from './api'; api.call() |
General Limitations
- No scope awareness: Variables with same names in different scopes treated identically
- No variable shadowing: Local declarations don't override outer scope correctly
-
No context awareness:
this.method()calls not resolved based on containing class -
No assignment tracking:
x = new Service(); x.method()doesn't link to Service class - No import resolution: Imported symbols never connected to their usage
- No property resolution: Object property access never resolved to definitions
- Type System Resolution: TypeScript type information, interfaces, and type aliases are not used for reference resolution
Out of scope
The following TypeScript/JavaScript features are currently out of scope for the Knowledge Graph:
-
Module Namespace Resolution:
import * as Utils from './utils'; Utils.helper()namespace access is not resolved -
Prototype Chain Resolution:
MyClass.prototype.method.call()and prototype-based inheritance patterns - Hoisted Function References: Calling functions before their declaration (JavaScript hoisting behavior)
- Control Flow Analysis: Variable assignments within conditional blocks affecting resolution
- Closure Resolution: Inner functions accessing outer scope variables in complex closure scenarios
- Generic Type Resolution: TypeScript generic function and class usage patterns
-
Callback Context Resolution:
array.map(item => item.process())where method resolution depends on callback context - Cross-file Resolution: Resolving references across module boundaries and import/export chains
- Dead Code Detection: Identifying unreachable or unused references
If your code relies heavily on one of the limitations or out of scope features, the Knowledge Graph may not provide a complete representation of symbol relationships.
Proposed solution
Continue integrating the scope-aware infra merged in !193 (merged).
Also investigate switching to SWC for definition, import, and reference resolution - as that will be much more comprehensive than any off the shelf resolver.
References
Edited by Michael Usachenko