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

@lukastaegert lukastaegert commented Feb 12, 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:

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.

@lukastaegert lukastaegert force-pushed the uninitialised-exports branch from 2d6dce7 to 13d4682 Feb 12, 2021
@rollup-bot
Copy link
Collaborator

@rollup-bot 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 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.

@lukastaegert lukastaegert force-pushed the uninitialised-exports branch from 13d4682 to e7a3f36 Feb 12, 2021
@lukastaegert lukastaegert merged commit 3394ae9 into master Feb 12, 2021
9 checks passed
9 checks passed
@github-actions
14 (Windows)
Details
@github-actions
12 (Windows)
Details
@github-actions
10 (Windows)
Details
ci/circleci: analysis Your tests passed on CircleCI!
Details
ci/circleci: node-v10-latest Your tests passed on CircleCI!
Details
ci/circleci: node-v12-latest Your tests passed on CircleCI!
Details
ci/circleci: node-v14-latest Your tests passed on CircleCI!
Details
@codecov
codecov/patch 100.00% of diff hit (target 97.19%)
Details
@codecov
codecov/project 97.19% (+0.00%) compared to 45d8e5e
Details
@lukastaegert lukastaegert deleted the uninitialised-exports branch Feb 12, 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.

None yet

2 participants