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
Inline interopDefault in config loading #2782
Conversation
There sure is no problem in merging this but I really do not get what this change should accomplish as this only affects the code Rollup uses when loading config files and does not change any code Rollup will generate? If you actually want to change the code generated by Rollup, note that I am thinking about reworking Rollup's interop handling as the current approach does not allow to easily forward dynamic bindings of default exports (basically this approach—a very recent addition: My goal would be to take some inspiration from babel here and use a normalization similar to theirs: function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } so that when an object containing a default key is imported, we do not accidentally destroy the live-binding by extracting the default once. Maybe this has some bearing on what you have in mind? Otherwise if this is really only about Rollup's code itself, I can sure merge it. |
Yes exactly, this is an esoteric case of supporting Rollup itself through jspm. Would be much appreciated to support it. This is only about dynamic imports - which are supported fine for generated code using the same convention - https://rollupjs.org/repl?version=1.7.4&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmV4cG9ydHMuZ2V0RHluYW1pYyUyMCUzRCUyMGZ1bmN0aW9uJTIwKCklMjAlN0IlNUNuJTVDdHJldHVybiUyMGltcG9ydCgnZHluYW1pYycpJTNCJTVDbiU3RCUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmNqcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE It would be great to keep this property for similar reasons as it means generated CJS code can be converted to ESM with dynamic import support. Note also that now that node --experimental-modules is stable we should also start to move towards stricter interop that only permits a default export from CommonJS, as that is all Node will do now, which will effectively dictate the running ES Modules conventions going forward. But yes, this is just about Rollup itself. |
I have been thinking a lot about interop lately and my goal for future versions of Rollup currently is:
Adding another "strict" interop mode that does not allow for named exports at all is definitely an option but I do not see this being on by default, not as long as there are many code-bases out there that depend on Babel transformed code. |
This inlines the interopDefault handling.
Note that we don't need to explicitly handle the null case (the rare chance of
module.exports = undefined
), because that would fail anyway in subsequent code paths.The benefit of this approach is that as discussed previously I'm working on supporting Rollup itself in a transformation that can convert CJS packages to ESM packages, and we can support dynamic require fine when it is detected as
Promise.resolve(require(x))
, but theinteropDefault
wrapper stops this from working out.Would be amazing to merge this to support the dynamic import conversion for full Rollup support in this work here.