-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix #41800 correctly. #41895
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
Fix #41800 correctly. #41895
Conversation
src/compiler/moduleSpecifiers.ts
Outdated
d => isModuleDeclaration(d) | ||
&& d?.parent?.parent?.parent | ||
&& isModuleBlock(d.parent) && isAmbientModule(d.parent.parent) && isSourceFile(d.parent.parent.parent) | ||
&& ((d.parent.parent.symbol.exports?.get("export=" as __String)?.valueDeclaration as ExportAssignment).expression as Identifier).escapedText === getTextOfIdentifierOrLiteral(d.name) |
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.
Hm. The text comparison is a little too specific - for example, what if
declare module m {
namespace a.b {
class c {}
}
export = a.b;
}
? I think we need to do a symbol identity comparison here. In the checker, this'd be easy using some resolveEntityName
or getSymbolOfNode
machinery - in moduleSpecifiers.ts
it's maybe a bit more awkward? There's a getSymbolIfSameReference
function in the checker for seeing if two symbols really refer to the same thing that is what I'd have considered using if it was available. Maybe we need some more context from the checker available? Or just more internals exported from the checker?
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.
Hm. The text comparison is a little too specific - for example, what if
declare module m { namespace a.b { class c {} } export = a.b; }? I think we need to do a symbol identity comparison here. In the checker, this'd be easy using some
resolveEntityName
orgetSymbolOfNode
machinery - inmoduleSpecifiers.ts
it's maybe a bit more awkward? There's agetSymbolIfSameReference
function in the checker for seeing if two symbols really refer to the same thing that is what I'd have considered using if it was available. Maybe we need some more context from the checker available? Or just more internals exported from the checker?
it is a good sugestion, but I am little worried about something
these functions(getsymbolofNode) are in the function createTypeChecker, so they could not be exported directly. What about match namespace directly?
Find the namespace unitil it is not nested namespace -- if module symbol is "b"(it is a nested namespace) and we find its parent "a"(it is namespace and not nested), so the path is "a.b", which matches default export("a.b")
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.
Nah, I'm pretty sure you gotta do symbol resolution and matching - otherwise you'll miss renames like
declare module "m" {
namespace a.b {
class c {}
}
import d = a.b;
export = d;
}
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.
Thanks a lot for the kind suggestion
Now using getSymbolAtLocation and getAliasedSymbol to get the original symbol of the default export , then compare it with moduleSymbol
, is this way OK? Did I miss something again?
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 looks pretty good to me - just two small nits.
Fixes #41816