Skip to content
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

[Refactor]: replace util._extend with Object.assign #2265

Merged
merged 1 commit into from May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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