Skip to content

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

Merged
merged 9 commits into from
Dec 17, 2020
Merged

Conversation

ShuiRuTian
Copy link
Contributor

Fixes #41816

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)
Copy link
Member

@weswigham weswigham Dec 9, 2020

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?

Copy link
Contributor Author

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?

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")

Copy link
Member

@weswigham weswigham Dec 10, 2020

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;
}

Copy link
Contributor Author

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?

@ShuiRuTian ShuiRuTian requested a review from weswigham December 14, 2020 03:24
Copy link
Member

@weswigham weswigham left a 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.

@ShuiRuTian ShuiRuTian requested a review from weswigham December 17, 2020 02:20
@weswigham weswigham merged commit 8cbc576 into microsoft:master Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants