Allow ES Modules to export __esModule#1622
Closed
heypiotr wants to merge 2 commits into
Closed
Conversation
|
@evanw are there concerns preventing this PR from being merged, it helps tremendously in adoption of URL imports and Import Maps (dependencies provided by jspm.io) by allowing folks opting-in for bundling (using esbuild) while keeping the unbundled code valid in the browser. We are actively using this workflow at Framer and find it extremely compelling. I read the whole discussion in the original issue and while the topic is extremely controversial, it doesn't look like the solution proposed by @heypiotr in this PR is hurting any runtime compatibility. WDYT? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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+__markAsModuleto only define__esModuleif it doesn't exist yet.I think this might only be problematic if the author of the script uses the
__esModuleexport "incorrectly" (i.e., as anything other than an ESM marker). Originally, as stated in my comment, I was hoping to have__markAsModuledetect that (__esModuleexists, 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
__exporthappens beforeinit_MRE(), and it'sinit_MREthat 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.