-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Use mutable bindings for default exports #4182
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#improve-default-exports or load it into the REPL: |
5033bb4
to
726ff59
Compare
Codecov Report
@@ Coverage Diff @@
## master #4182 +/- ##
==========================================
- Coverage 98.34% 98.34% -0.01%
==========================================
Files 202 202
Lines 7245 7243 -2
Branches 2123 2123
==========================================
- Hits 7125 7123 -2
Misses 58 58
Partials 62 62
Continue to review full report at Codecov.
|
Nice to see. Note this fixes #2000. |
726ff59
to
2b86eb8
Compare
I decided not to add any special handling for using default export mode with a mutable default export yet as I could not decide how to approach this best. |
Escape "default" when used as named export Create new variable for TDZ default exports
2b86eb8
to
cc4f9b4
Compare
This change breaks njs-typescript-starter (#1) because njs (NGINX JavaScript – an alternative JavaScript interpreter) doesn’t support named exports. It seems that this rollup feature is not configurable, so what am I supposed to do? Input: function hello () { }
export default { hello } Output (2.62.0): function hello() {}
var index = {
hello
};
export { index as default }; Relevant rollup options: output: {
file: 'index.js',
format: 'es',
exports: 'default',
} So after the changes introduced in this MR,
This is not true, this change is a breaking change. |
I am sorry, but Rollup only promises to produce ECMA compatible code which it does. There is no spec that I am aware of where you only have some ES 2015 export features but not others,even though it might be breaking for your non-standard-compliant runtime. |
Yes, that’s true, njs is not fully ECMAScript compliant yet. But I really don’t understand why is Rollup replacing
That’s what I’m trying to do now. However, I was hoping to find a more elegant way than replacing the rendered export using regex. |
you can bug the meanwhile, you can
the reason is to be ecma spec compliant.
it's still a default export. just a different syntax.
|
This changes the compiled files in a minor way. See rollup/rollup#4182.
This changes the compiled files in a minor way. See rollup/rollup#4182.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
#4168
resolves #2000
Description
This aims to improve handling of default exports and solve many issues listed in #4168.
The most important change is that default exports are now always rendered as
instead of
This works much better with how we treat default exports internally (for the most part, not different from named exports) and will potentially allow consumers to avoid creating an additional binding.
Most importantly, this finally allows Rollup to create mutable default exports, something which was not possible before.
Secondly, this detects when we default export a binding in a position where the binding may be in a temporal dead zone and creates an additional variable in these cases so that the error is not swallowed.
Also, an inconsistency is fixed where
.default
was not written as a computed property.What is not solved is the main issue listed in #4168 as detecting circular dependency situations is somewhat tricky.
Update: I decided not to add any special handling for using default export mode with a mutable default export yet as I could not decide how to approach this best.