Skip to content

Commit fce69eb

Browse files
golopotljharb
authored andcommitted
[Refactor]: replace util._extend with Object.assign
1 parent d1e79b9 commit fce69eb

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

lib/rules/sort-comp.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
'use strict';
66

77
const has = require('has');
8-
const util = require('util');
98

109
const Components = require('../util/Components');
1110
const arrayIncludes = require('array-includes');
@@ -58,7 +57,7 @@ const defaultConfig = {
5857
function getMethodsOrder(userConfig) {
5958
userConfig = userConfig || {};
6059

61-
const groups = util._extend(defaultConfig.groups, userConfig.groups);
60+
const groups = Object.assign({}, defaultConfig.groups, userConfig.groups);
6261
const order = userConfig.order || defaultConfig.order;
6362

6463
let config = [];

lib/util/Components.js

+18-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
'use strict';
66

7-
const util = require('util');
87
const doctrine = require('doctrine');
98
const arrayIncludes = require('array-includes');
109

@@ -97,23 +96,25 @@ class Components {
9796
* @param {Object} props Additional properties to add to the component.
9897
*/
9998
set(node, props) {
100-
while (node && !this._list[getId(node)]) {
99+
let component = this._list[getId(node)];
100+
while (!component) {
101101
node = node.parent;
102+
if (!node) {
103+
return;
104+
}
105+
component = this._list[getId(node)];
102106
}
103-
if (!node) {
104-
return;
105-
}
106-
const id = getId(node);
107-
let copyUsedPropTypes;
108-
if (this._list[id]) {
109-
// usedPropTypes is an array. _extend replaces existing array with a new one which caused issue #1309.
110-
// preserving original array so it can be merged later on.
111-
copyUsedPropTypes = this._list[id].usedPropTypes && this._list[id].usedPropTypes.slice();
112-
}
113-
this._list[id] = util._extend(this._list[id], props);
114-
if (this._list[id] && props.usedPropTypes) {
115-
this._list[id].usedPropTypes = mergeUsedPropTypes(copyUsedPropTypes || [], props.usedPropTypes);
116-
}
107+
108+
Object.assign(
109+
component,
110+
props,
111+
{
112+
usedPropTypes: mergeUsedPropTypes(
113+
component.usedPropTypes || [],
114+
props.usedPropTypes || []
115+
)
116+
}
117+
);
117118
}
118119

119120
/**
@@ -758,7 +759,7 @@ function componentRule(rule, context) {
758759

759760
// Update the provided rule instructions to add the component detection
760761
const ruleInstructions = rule(context, components, utils);
761-
const updatedRuleInstructions = util._extend({}, ruleInstructions);
762+
const updatedRuleInstructions = Object.assign({}, ruleInstructions);
762763
const propTypesInstructions = propTypesUtil(context, components, utils);
763764
const usedPropTypesInstructions = usedPropTypesUtil(context, components, utils);
764765
const defaultPropsInstructions = defaultPropsUtil(context, components, utils);

0 commit comments

Comments
 (0)