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
Fix: Don't call Object.keys on non-objects (babel#10482) #10683
Conversation
@@ -396,7 +396,7 @@ helpers.objectSpread = helper("7.0.0-beta.0")` | |||
|
|||
export default function _objectSpread(target) { | |||
for (var i = 1; i < arguments.length; i++) { | |||
var source = (arguments[i] != null) ? arguments[i] : {}; | |||
var source = (typeof arguments[i] === 'object' && arguments[i] != null) ? arguments[i] : {}; | |||
var ownKeys = Object.keys(source); |
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.
it would be better to do this:
var ownKeys = Object.keys(source); | |
var ownKeys = Object.keys(Object(source)); |
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.
Thanks for the review! I have made the suggested change @ljharb, can you take another look?
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.
My initial reaction about the issue was "you just need to load a polyfill", but given that the fix is so simple I don't see why we shouldn't include it.
This changes the polyfill for the object spread operator to ensure that the argument to be spread is an Object before calling
Object.keys
. This fixes a JS error in IE11 which implements the old ES5 version ofObject.keys
which does not support non-object arguments.A common pattern that will run into this issue: