tsutils
tsutils copied to clipboard
new implementation of Resolver
trafficstars
This new API is going to replace the existing collectVariableUsage.
Main differences:
- fully incremental and cached
- weak cache cleans up if node is no longer referenced
- should even work with updated SourceFiles
- references contain
exportstatements - falls back to TypeChecker if necessary (and available)
- correctly handles merged namespaces and enums, even across files
- returns no result if correctness cannot be guaranteed (missing TypeChecker, crossing
withscope boundary, ...) - several bug fixes
- imports and namespaces are treated with their actual type rather than guessing something
- correct handling of
argumentsin functions - computed method names cannot access type parameters and regular parameters
- (class, method, parameter) decorators cannot access type parameters and parameters
typeofin type parameters cannot access function parameters- return type can access declarations in function body
- resolves uses within a
withblock, but stops at the scope boundary - treats every value use in
withstatement as unknown
- adds an API to find the declaration at a use site
Fixes: #38
TODOs:
- refactor the API to use iterators all the way to the consumer
- this allows aborting analysis if no more information is needed
- API user can decide whether to use potentially shadowed uses
- add tests
- look for possible performance optimizations
- this is optional as the cache already saves quite a bit of redundant work
- but still generators are pretty slow
More things to consider for final API design:
- should be able to modify scopes by adding removing declarations
- should only work on a forked Resolver to not interfere with other users of that Resolver
- should be able to get a Symbol by name (e.g.
arguments)- probably requires direct access to
Scope(would also simplify the previous bullet point)
- probably requires direct access to
- needs a way to distinguish the following cases
- implicitly available identifier (
arguments) - identifier from merged declaration (namespace and enum)
- no declaration found
- implicitly available identifier (
If possible it should also track this and super. These are treated as identifiers without declaration like arguments. That means we also need to look for this and super keywords.
In addition this lives in the type and value domain.