-
Notifications
You must be signed in to change notification settings - Fork 30
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 duplicate default exports #53
Conversation
Moving back to draft as the issue isn't quite solved. It is possible the wrong default gets exported. In the case of |
8bee24b
to
dd5d07b
Compare
b5df7bb
to
449dd2b
Compare
449dd2b
to
edff49d
Compare
if (matches === null) return | ||
return `_['${matches[1]}'] = ${matches[2]}.default` | ||
}) | ||
.filter(s => s) |
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.
We'll probably want to eventually rework this for performance, but for now, can you can you add a double-exclamation to make it clear that it's filtering on truthiness, and therefore eliminating undefined
holes?
.filter(s => s) | |
.filter(s => !!s) |
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.
In my opinion, the !!
construct is very difficult to read. Would a comment suffice?
- Fixes node 20 reexports nodejs/import-in-the-middle#30 - Fixes duplicate default exports nodejs/import-in-the-middle#53
) - Fixes node 20 reexports nodejs/import-in-the-middle#30 - Fixes duplicate default exports nodejs/import-in-the-middle#53
Ref: newrelic/node-newrelic#1920
👋 my last "fix" (#43) broke in a new way thanks to the helpful ESM allowance of exportingdefault
multiple times. This PR resolves the issue. I suspect there could be further problems with the exports since I have no idea how exportingdefault
multiple times is meant to be interpreted, but I suspect any such issues will be an extreme edge case.The only other thing I can think of to do here is to somehow track that we already have adefault
export and munge the names of any subsequent ones.I have since learned that ESM doesn't actually allow exporting
default
multiple times. Transitivedefault
exports get mapped to some other name for the module that has imported them, and only the directly importeddefault
gets exported. Still, we have to handle figuring out whichdefault
is the right one and construct our shim namespace accordingly.2023-01-03: this can only be supported on Node versions where we parse the modules with an AST parser and interpret the code manually. So I have updated the test suite for this feature to only run on such versions.