-
Notifications
You must be signed in to change notification settings - Fork 591
Fix typedef binding with CJS exports=
#826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6f540b2
b8bc147
5d2d999
8021e94
689d0e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13618,7 +13618,7 @@ func (c *Checker) getTargetOfImportEqualsDeclaration(node *ast.Node, dontResolve | |
moduleReference = getExternalModuleImportEqualsDeclarationExpression(node) | ||
} | ||
immediate := c.resolveExternalModuleName(node, moduleReference, false /*ignoreErrors*/) | ||
resolved := c.resolveExternalModuleSymbol(immediate, false /*dontResolveAlias*/) | ||
resolved := c.resolveExternalModuleSymbol(immediate, dontResolveAlias) | ||
c.markSymbolOfAliasDeclarationIfTypeOnly(node, immediate, resolved, false /*overwriteEmpty*/, nil, "") | ||
return resolved | ||
} | ||
|
@@ -14545,9 +14545,24 @@ func (c *Checker) resolveEntityName(name *ast.Node, meaning ast.SymbolFlags, ign | |
} | ||
|
||
func (c *Checker) resolveQualifiedName(name *ast.Node, left *ast.Node, right *ast.Node, meaning ast.SymbolFlags, ignoreErrors bool, dontResolveAlias bool, location *ast.Node) *ast.Symbol { | ||
namespace := c.resolveEntityName(left, ast.SymbolFlagsNamespace, ignoreErrors, false /*dontResolveAlias*/, location) | ||
namespace := c.resolveEntityName(left, ast.SymbolFlagsNamespace, true /*ignoreErrors*/, false /*dontResolveAlias*/, location) | ||
if namespace == nil || ast.NodeIsMissing(right) { | ||
return nil | ||
var immediate *ast.Symbol | ||
alias := c.resolveEntityName(left, ast.SymbolFlagsAlias, true /*ignoreErrors*/, true /*dontResolveAlias*/, location) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. So if the resolution of the LHS of a qualified name fails, we try to look it up with only one level of aliasing? This seems... weird? While this might work in some scenarios, if
as export * from name // even though this isn't a thing in ESM (yet)
export type Foo = number I think if we want to handle this in a non-jank way, we need to bind a I'm also honestly a lil unsure what a syntactically driven declaration emit for this is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we just add support for parsing/checking |
||
if alias != nil { | ||
immediate = c.getImmediateAliasedSymbol(alias) | ||
if immediate != nil && !core.Some(immediate.Declarations, func(d *ast.Node) bool { return d.Kind == ast.KindJSExportAssignment }) { | ||
immediate = nil | ||
} | ||
} | ||
if immediate == nil { | ||
if !ignoreErrors { | ||
c.resolveEntityName(left, ast.SymbolFlagsNamespace, ignoreErrors, false /*dontResolveAlias*/, location) | ||
} | ||
return nil | ||
} else { | ||
namespace = immediate | ||
} | ||
} | ||
if namespace == c.unknownSymbol { | ||
return namespace | ||
|
@@ -22830,9 +22845,20 @@ func (c *Checker) getTypeFromImportTypeNode(node *ast.Node) *Type { | |
} | ||
next := core.OrElse(symbolFromModule, symbolFromVariable) | ||
if next == nil { | ||
c.error(current, diagnostics.Namespace_0_has_no_exported_member_1, c.getFullyQualifiedName(currentNamespace, nil), scanner.DeclarationNameToString(current)) | ||
links.resolvedType = c.errorType | ||
return links.resolvedType | ||
var symbolFromImmediateModule *ast.Symbol | ||
if currentNamespace == moduleSymbol { | ||
immediateModuleSymbol := c.resolveExternalModuleSymbol(innerModuleSymbol, true /*dontResolveAlias*/) | ||
if immediateModuleSymbol != nil && core.Some(immediateModuleSymbol.Declarations, func(d *ast.Node) bool { return d.Kind == ast.KindJSExportAssignment }) { | ||
symbolFromImmediateModule = c.getSymbol(c.getExportsOfSymbol(immediateModuleSymbol), current.Text(), meaning) | ||
} | ||
} | ||
if symbolFromImmediateModule != nil { | ||
next = symbolFromImmediateModule | ||
} else { | ||
c.error(current, diagnostics.Namespace_0_has_no_exported_member_1, c.getFullyQualifiedName(currentNamespace, nil), scanner.DeclarationNameToString(current)) | ||
links.resolvedType = c.errorType | ||
return links.resolvedType | ||
} | ||
} | ||
c.symbolNodeLinks.Get(current).resolvedSymbol = next | ||
c.symbolNodeLinks.Get(current.Parent).resolvedSymbol = next | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for one level of indirection to a local namespace-y thing, but what about an aliased namespacey thing? Eg
or, abusing a ts construct to do it locally,
mod
's symbol will be an alias, and this will just patch the typedefs onto the alias symbol, and not the alias symbol's ultimate target, which, dollars to donuts, means it's going to effectively go missing without extra lookup logic in the checker, similar to what we used to have. 🥹There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even simpler, this also reproduces the problem.