Fix: Don't call Object.keys on non-objects (babel#10482)#10683
Merged
existentialism merged 1 commit intobabel:masterfrom Nov 9, 2019
Merged
Fix: Don't call Object.keys on non-objects (babel#10482)#10683existentialism merged 1 commit intobabel:masterfrom
existentialism merged 1 commit intobabel:masterfrom
Conversation
ljharb
reviewed
Nov 8, 2019
| 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); |
Member
There was a problem hiding this comment.
it would be better to do this:
Suggested change
| var ownKeys = Object.keys(source); | |
| var ownKeys = Object.keys(Object(source)); |
Contributor
Author
There was a problem hiding this comment.
Thanks for the review! I have made the suggested change @ljharb, can you take another look?
nicolo-ribaudo
approved these changes
Nov 8, 2019
Member
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
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.
jridgewell
approved these changes
Nov 8, 2019
ljharb
approved these changes
Nov 8, 2019
This was referenced Dec 12, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.keyswhich does not support non-object arguments.A common pattern that will run into this issue: