Skip to content

Improvements to find-all-references for import types #23998

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
3 commits merged into from
May 10, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented May 9, 2018

Fixes #23879
Sequel to #23881

  • In addition to getting module references, if the module is export = we should get references to the exported thing too. So at const x: import("[|foo|]") we'll also get a reference to import [|T|] = require("foo");.
  • Also do the opposite: starting at export = [|T|] in module "foo", get `import("[|foo|]") references.
  • Fix a bug where we forgot to match the name of an import type, so import("foo").[|T|] no longer matches export type [|U|] = string;.
  • Don't rename module specifiers. (We do have the ability to rename files in a separate service, but that's not hooked up to the rename command, so better to do nothing.)

@ghost ghost requested review from weswigham and sheetalkamat May 9, 2018 20:22
@ghost ghost changed the title Find all refs export equals Improvements to find-all-references for import types May 9, 2018
@ghost ghost force-pushed the findAllRefsExportEquals branch from 317917f to 926d8f5 Compare May 9, 2018 20:23
@ghost ghost force-pushed the findAllRefsExportEquals branch from 926d8f5 to c26c986 Compare May 9, 2018 20:30
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.

I think I get most of it; just a few small comments.

if (reference.kind === "import") {
const parent = reference.literal.parent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhhhh, isn't reference.literal.parent just reference?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference isn't a node, it's a ModuleReference.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhhh, ok

return getReferencedSymbolsForModule(program, symbol, sourceFiles, sourceFilesSet);
let moduleReferences: SymbolAndEntries[] = emptyArray;
if (isModuleSymbol(symbol)) {
const exportEquals = symbol.exports.get(InternalSymbolName.ExportEquals);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth mentioning that JS is crazy and, I believe, can have both an export= and non-export= exports, via a file like

module.exports = class Foo {}
module.exports.a = "yes"

and I have no idea how that should behave with respect to find-all-refs. @sandersn knows our current behavior here, it's a bit in flux.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #24025 (and #24024)

@ghost ghost merged commit fd17f77 into master May 10, 2018
@ghost ghost deleted the findAllRefsExportEquals branch May 10, 2018 22:31
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant