Skip to content
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

Merged
merged 1 commit into from Jul 28, 2021
Merged

Conversation

@lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented Jul 18, 2021

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

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

export {binding as default};

instead of

export default binding;

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.

@lukastaegert lukastaegert marked this pull request as draft Jul 18, 2021
@github-actions
Copy link

@github-actions github-actions bot commented Jul 18, 2021

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:
https://rollupjs.org/repl/?pr=4182

@lukastaegert lukastaegert force-pushed the improve-default-exports branch from 5033bb4 to 726ff59 Jul 18, 2021
@codecov
Copy link

@codecov codecov bot commented Jul 18, 2021

Codecov Report

Merging #4182 (cc4f9b4) into master (824c53f) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/Chunk.ts 100.00% <100.00%> (ø)
src/ast/nodes/Identifier.ts 100.00% <100.00%> (ø)
src/ast/variables/ExportDefaultVariable.ts 100.00% <100.00%> (ø)
src/finalisers/es.ts 100.00% <100.00%> (ø)
src/finalisers/shared/getExportBlock.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 824c53f...cc4f9b4. Read the comment docs.

@guybedford
Copy link
Contributor

@guybedford guybedford commented Jul 18, 2021

Nice to see. Note this fixes #2000.

@lukastaegert lukastaegert force-pushed the improve-default-exports branch from 726ff59 to 2b86eb8 Jul 28, 2021
@lukastaegert lukastaegert marked this pull request as ready for review Jul 28, 2021
@lukastaegert
Copy link
Member Author

@lukastaegert lukastaegert commented Jul 28, 2021

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
@lukastaegert lukastaegert force-pushed the improve-default-exports branch from 2b86eb8 to cc4f9b4 Jul 28, 2021
@lukastaegert lukastaegert changed the title [WIP] Use mutable bindings for default exports Use mutable bindings for default exports Jul 28, 2021
@lukastaegert lukastaegert merged commit 9a23190 into master Jul 28, 2021
8 of 9 checks passed
@lukastaegert lukastaegert deleted the improve-default-exports branch Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants