Skip to content
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

$imports export can break repeated uses of export * from <module> #2

Open
robertknight opened this issue Apr 7, 2019 · 1 comment

Comments

@robertknight
Copy link
Owner

robertknight commented Apr 7, 2019

This plugin adds an $import export to every module it processes. That can break code which relies on being able to re-export everything from a collection of modules using export * from <module> multiple times. For example:

// index.js
export * from './module-a'
export * from './module-b'

If module-a and module-b are both processed by this plugin, Babel will complain of a duplicate $imports identifier here.

A workaround might be to generate a unique name for the $imports symbol in each file, and then provide a helper function to access it. Alternatively some kind of convention like taking the basename of the file could be used.

I found this while testing the plugin with Gutenberg.

@robertknight
Copy link
Owner Author

Some other ideas:

  1. Rewrite export * from "module" as export { <specifiers> } from "module" where < specifiers > are automatically determined the exports of "module"
  2. Define an alternative, non-export way of exposing a modules $imports object. For example by adding a function call at the end of the file which registers it in some global map that a test can then query.

I think I prefer (2) here because it doesn't require accessing any other files. We would need to find some key to use for the $imports object though, ideally the same as the one that would be used for import or require calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant