Allow ES Modules to export __esModule #1622
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is my stab at fixing #1591, as described in #1591 (comment):
This PR removes the "__esModule is reserved" check, and updates
__export
+__markAsModule
to only define__esModule
if it doesn't exist yet.I think this might only be problematic if the author of the script uses the
__esModule
export "incorrectly" (i.e., as anything other than an ESM marker). Originally, as stated in my comment, I was hoping to have__markAsModule
detect that (__esModule
exists, but evaluated to anything buttrue
) and throw a runtime error... But turns out at the time of__export
, we don't yet know the value of__esModule
:You can see
__export
happens beforeinit_MRE()
, and it'sinit_MRE
that actually sets the value of__esModule
.So no runtime error for now, and if we still want it, I could use a hint/ideas on how to approach that.