Fix @typedef/@callback scope (#43682)

JSDoc typedefs don't actually have hosts, because they're not
semantically attached to a declaration. However, the parser still
attaches them to some declaration (or statement), but that declaration
is not related to the typedef.

Previously, delayedBindJSDocTypedefTag used getJSDocHost to walk past
the unrelated declaration, but #41858 correctly started categorising
typedefs as unattached, with no host, so the binder began falling
back to file scope.

The path to skip the unrelated declaration is always the same, though, so this
PR uses `typeAlias.parent.parent` instead of `getJSDocHost(typeAlias)`.
This commit is contained in:
Nathan Shively-Sanders authored and GitHub committed 2021-04-14 16:56:37 -07:00
1 parent 3ab6809e38
commit 3f93d420bf
6 files changed
+130 -3

No files matched your search

+3 -3
View File
@@ -2123,9 +2123,9 @@ namespace ts {
const saveParent = parent;
const saveCurrentFlow = currentFlow;
for (const typeAlias of delayedTypeAliases) {
const host = getJSDocHost(typeAlias);
container = (host && findAncestor(host.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer))) || file;
blockScopeContainer = (host && getEnclosingBlockScopeContainer(host)) || file;
const host = typeAlias.parent.parent;
container = findAncestor(host.parent, n => !!(getContainerFlags(n) & ContainerFlags.IsContainer)) || file;
blockScopeContainer = getEnclosingBlockScopeContainer(host) || file;
currentFlow = initFlowNode({ flags: FlowFlags.Start });
parent = typeAlias;
bind(typeAlias.typeExpression);