Skip to content

Commit

Permalink
Use object.fromentries
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzherdev committed Sep 20, 2018
1 parent ce9ba34 commit b81e19a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/util/defaultProps.js
Expand Up @@ -3,6 +3,7 @@
*/
'use strict';

const fromEntries = require('object.fromentries');
const astUtil = require('./ast');
const propsUtil = require('./props');
const variableUtil = require('./variable');
Expand Down Expand Up @@ -85,10 +86,11 @@ module.exports = function defaultPropsInstructions(context, components, utils) {
}

const defaults = component.defaultProps || {};
const newDefaultProps = defaultProps.reduce((acc, prop) => {
acc[prop.name] = prop;
return acc;
}, Object.assign({}, defaults));
const newDefaultProps = Object.assign(
{},
defaults,
fromEntries(defaultProps.map(prop => [prop.name, prop]))
);

components.set(component.node, {
defaultProps: newDefaultProps
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -28,6 +28,7 @@
"doctrine": "^2.1.0",
"has": "^1.0.3",
"jsx-ast-utils": "^2.0.1",
"object.fromentries": "^2.0.0",
"prop-types": "^15.6.2"
},
"devDependencies": {
Expand Down

0 comments on commit b81e19a

Please sign in to comment.