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
Copy getters and setters correctly in interopWildcard #6850
Conversation
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.
maybe we should add an additional loose
helper without that logic later?
Does this also influence e.g. import * as foo from "./foo";
assert.throws(() => foo.bar); // foo.js
module.exports = {
get bar() { throw {} }
}; |
Good idea, I added it. |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5915/ |
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = Object.getOwnPropertyDescriptor(obj, key); | ||
if (desc.get || desc.set) { | ||
Object.defineProperty(newObj, key, desc); |
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.
I think if we're going to do this, we should check for the existence of Object.defineProperty
, or we should finally expose a flag for modules to opt in or out of Object.defineProperty
usage. Otherwise this is going to make things unusable for people targeting old environments.
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.
I will add a check for Object.defineProperty
, which I think should be enough here, because when Object.defineProperty
is not there then getters and setters are also not supported.
It is basically supported in all environments besides IE8 and older. But IE8 is also over 10years old now. 🕵️♀️
What if we change in babel 7 and state that generated code from babel needs at least ES5, like react does now (they even require Map and Set). Would be nice to have statistics to see what environments people support, but I guess that does not really exist. Or did we have already complains about this?
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.
And core-js also has a polyfill for it, so we could also link people there. And from my experience if you support IE8 or older, then you need polyfills anyway.
This ensures that getters and setters are copied correctly in the
interopRequireWildcard
helper.