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

Make sure uninitialised exports turn up via .hasOwnProperty for non-ES formats #3957

Merged
merged 1 commit into from Feb 12, 2021

Conversation

lukastaegert
Copy link
Member

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:

Description

This will make sure that even uninitialised named exports will create properties on the exports object in CJS/IIFE/AMD/UMD formats so that checking for those properties via .hasOwnProperty or Object.keys works.
This is important for tools that rely on this for e.g. merging and forwarding namespaces.

This was already working properly for constant exports but was broken for exports that were assigned dynamically later, example:

https://rollupjs.org/repl/?version=2.38.5&shareable=JTdCJTIybW9kdWxlcyUyMiUzQSU1QiU3QiUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTJDJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMGxldCUyMGZvbyUzQiU1Q24lNUNuZXhwb3J0JTIwY29uc3QlMjB1cGRhdGVGb28lMjAlM0QlMjAoKSUyMCUzRCUzRSUyMGZvbyUyMCUzRCUyMCd1cGRhdGVkJyUyMiUyQyUyMmlzRW50cnklMjIlM0F0cnVlJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMmZvcm1hdCUyMiUzQSUyMmNqcyUyMiUyQyUyMm5hbWUlMjIlM0ElMjJteUJ1bmRsZSUyMiUyQyUyMmFtZCUyMiUzQSU3QiUyMmlkJTIyJTNBJTIyJTIyJTdEJTJDJTIyZ2xvYmFscyUyMiUzQSU3QiU3RCU3RCUyQyUyMmV4YW1wbGUlMjIlM0FudWxsJTdE

Note that when updateFoo is not run, the property foo will no exist.

@rollup-bot
Copy link
Collaborator

rollup-bot commented Feb 12, 2021

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#uninitialised-exports

or load it into the REPL:
https://rollupjs.org/repl/?circleci=14279

@codecov
Copy link

codecov bot commented Feb 12, 2021

Codecov Report

Merging #3957 (e7a3f36) into master (45d8e5e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3957   +/-   ##
=======================================
  Coverage   97.19%   97.19%           
=======================================
  Files         190      191    +1     
  Lines        6694     6694           
  Branches     1958     1958           
=======================================
  Hits         6506     6506           
  Misses         99       99           
  Partials       89       89           
Impacted Files Coverage Δ
src/ast/nodes/VariableDeclaration.ts 97.87% <100.00%> (-0.13%) ⬇️
src/ast/nodes/VariableDeclarator.ts 100.00% <100.00%> (ø)
src/utils/reassignedExportsMember.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 45d8e5e...e7a3f36. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants