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

Babel interopRequireWildcard helper reexports #53

Merged
merged 1 commit into from
Mar 30, 2021

Conversation

guybedford
Copy link
Collaborator

This adds support for reexport patterns based on var _x = _interopRequireWildcard(require('x')).

We specifically detect the "_interopRequireWildcard" identifier, so like TypeScript helper reexports this will not survive minification, but for npm packages the detection goal of supporting transpiled ES modules is still met despite this potential issue.

Fixes #52

/cc @nicolo-ribaudo

@nicolo-ribaudo
Copy link
Contributor

I feel like detecting interopRequireWildcard specifically is fragile, but:

  1. I can't think of a better pattern
  2. Most modules on npm aren't minified anyway

@guybedford guybedford force-pushed the babel-reexport-helper branch from 1a0afcf to 28d70ff Compare March 30, 2021 17:41
@guybedford
Copy link
Collaborator Author

@nicolo-ribaudo how reliable is the _interopRequireWildcard name here (with the _)? I know it's fragile, it would just be nice to get a sense of how fragile. Should we support without the leading _, and possibly with $n?

@nicolo-ribaudo
Copy link
Contributor

nicolo-ribaudo commented Mar 30, 2021

Babel will never inject it without the leading _.

$n could happen when you compile a file which has already been compiled (thus it already contains an _interopRequireWildcard function). When people compile re-compile files it's almost always because they are bundling and compiling their dependencies: in this case Babel's exports wouldn't be the final bundle exports anyway. I don't think we need to worry about it.

@guybedford guybedford merged commit ec1c135 into master Mar 30, 2021
@guybedford guybedford deleted the babel-reexport-helper branch March 30, 2021 18:10
@guybedford
Copy link
Collaborator Author

Thanks for confirming!

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

Successfully merging this pull request may close these issues.

Babel interopRequireWildcard reexports
2 participants