fix(typescript_indexer): improve handling of anonymous functions #5795
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.
This PR improves function that returns TS Symbol for Node. Previously it handled only named Nodes such as functions with names. Now we can get Symbols of anonymous functions as well. This fixes certain aspects of anonymous functions such as adds missing
childof
edges. And additionally it brings close handling of named and anonymous entities.Unfortunately it relies on using private Node.symbol property. I considered alternative options such as:
Support two different branches: named nodes with Symbol and anonymous nodes without Symbols. That would require re-implementing a SymbolVNameStore cache to deduplicate vnames for anonymous nodes. Keeping both in sync would be challenging and confusing.
For anonymous nodes, where we can't get Symbols using public API, create our own Symbol instance. Symbol is public interface so we can create objects that implement it. Would also need to introduce Node=>FakeSymbol cache.
Both approaches seem more complicated. So I decided to use private
Node.symbol
API. If future TS versions remove it - we'll have to switch to one of the alternative approaches.