Port symbol walker to latest#9847
Conversation
|
Our current janky code for poking around in types is here: One ominous comment from there: However, I can't remember the particular scenario this is avoiding, and I commented it out and attempted to reproduce the mentioned crash and can't seem to find it now. The other thing we've had trouble with is mapping a type back to a qualified name. E.g. the compiler infers |
|
@evmar Interestingly enough, this chunk at the bottom of visitSymbol is for handling a similar scenario (anonymous types don't trip up this walker since it happily visits both symbols and types): forEach(symbol.declarations, d => {
// Type queries are too far resolved when we just visit the symbol's type
// (their type resolved directly to the member deeply referenced)
// So to get the intervening symbols, we need to check if there's a type
// query node on any of the symbol's declarations and get symbols there
if ((d as any).type && (d as any).type.kind === SyntaxKind.TypeQuery) {
const query = (d as any).type as TypeQueryNode;
const entity = leftmostSymbol(query.exprName);
visitSymbol(entity);
}
});The original intent for our declaration emitter was to find all the symbols you care about with this, and filter on |
|
Thanks @weswigham, this seems like it'd help our use case. We could use this to generate a tool that walks all exported symbols in a module, skipping |
|
#17844 replaces this. |
The kind folks over at @angular were wondering if we could port the type/symbol walker we produced for my declaration flattening prototype to our latest codebase and publicly expose it.
This is that.
@evmar @alexeagle
If one of you has a good test corpus for what you want to traverse, I can try to make a test out of it (so we don't break it in the future). You should also verify that it's capable of what you need - otherwise make some suggestions.
@mhegazy
You probably want to verify that we're OK with maintaining this API.
If anyone has any changes you'd like to see, you should probably propose them here.