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
safe hasOwnProperty call #5010
safe hasOwnProperty call #5010
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable, but it is not entirely clear to me what scenario we are guarding against. Most importantly, we would need a test (probably a function
test that runs the generated code) that is broken without that change.
exports
is an object provided by the runtime. Why wouldn't we want to use its hasOwnProperty
method?
// entry.js
export * from 'external'; You will got nothing dynamic re-export: // external (case: non-getter)
export const hasOwnProperty = () => false; or got an error thrown: // external (case: throw)
export const hasOwnProperty = false; even worse with side effects: // external (case: side-effects)
export const hasOwnProperty = () => {
/* do something here */
}; see the generated code, and imagine what will happen in runtime: var external = require('external');
Object.keys(external).forEach(function (k) {
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return external[k]; }
});
}); |
Thanks for clarifying. Then you should add this as a "function" test case, then we do not need to imagine. |
Codecov Report
@@ Coverage Diff @@
## master #5010 +/- ##
=======================================
Coverage 98.96% 98.96%
=======================================
Files 226 226
Lines 8348 8348
Branches 2290 2290
=======================================
Hits 8262 8262
Misses 31 31
Partials 55 55
|
@lukastaegert here ready if I add the test right |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect, thanks so much for following up on this!
This PR has been released as part of rollup@3.26.1. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
There will be a bug when export names include
hasOwnProperty
.I'm not sure how to add test for this case...