Skip to content

Commit

Permalink
[Refactor]: replace util._extend with Object.assign
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot authored and ljharb committed May 8, 2019
1 parent d1e79b9 commit fce69eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
3 changes: 1 addition & 2 deletions lib/rules/sort-comp.js
Expand Up @@ -5,7 +5,6 @@
'use strict';

const has = require('has');
const util = require('util');

const Components = require('../util/Components');
const arrayIncludes = require('array-includes');
Expand Down Expand Up @@ -58,7 +57,7 @@ const defaultConfig = {
function getMethodsOrder(userConfig) {
userConfig = userConfig || {};

const groups = util._extend(defaultConfig.groups, userConfig.groups);
const groups = Object.assign({}, defaultConfig.groups, userConfig.groups);
const order = userConfig.order || defaultConfig.order;

let config = [];
Expand Down
35 changes: 18 additions & 17 deletions lib/util/Components.js
Expand Up @@ -4,7 +4,6 @@
*/
'use strict';

const util = require('util');
const doctrine = require('doctrine');
const arrayIncludes = require('array-includes');

Expand Down Expand Up @@ -97,23 +96,25 @@ class Components {
* @param {Object} props Additional properties to add to the component.
*/
set(node, props) {
while (node && !this._list[getId(node)]) {
let component = this._list[getId(node)];
while (!component) {
node = node.parent;
if (!node) {
return;
}
component = this._list[getId(node)];
}
if (!node) {
return;
}
const id = getId(node);
let copyUsedPropTypes;
if (this._list[id]) {
// usedPropTypes is an array. _extend replaces existing array with a new one which caused issue #1309.
// preserving original array so it can be merged later on.
copyUsedPropTypes = this._list[id].usedPropTypes && this._list[id].usedPropTypes.slice();
}
this._list[id] = util._extend(this._list[id], props);
if (this._list[id] && props.usedPropTypes) {
this._list[id].usedPropTypes = mergeUsedPropTypes(copyUsedPropTypes || [], props.usedPropTypes);
}

Object.assign(
component,
props,
{
usedPropTypes: mergeUsedPropTypes(
component.usedPropTypes || [],
props.usedPropTypes || []
)
}
);
}

/**
Expand Down Expand Up @@ -758,7 +759,7 @@ function componentRule(rule, context) {

// Update the provided rule instructions to add the component detection
const ruleInstructions = rule(context, components, utils);
const updatedRuleInstructions = util._extend({}, ruleInstructions);
const updatedRuleInstructions = Object.assign({}, ruleInstructions);
const propTypesInstructions = propTypesUtil(context, components, utils);
const usedPropTypesInstructions = usedPropTypesUtil(context, components, utils);
const defaultPropsInstructions = defaultPropsUtil(context, components, utils);
Expand Down

0 comments on commit fce69eb

Please sign in to comment.