|
4 | 4 | */
|
5 | 5 | 'use strict';
|
6 | 6 |
|
7 |
| -const util = require('util'); |
8 | 7 | const doctrine = require('doctrine');
|
9 | 8 | const arrayIncludes = require('array-includes');
|
10 | 9 |
|
@@ -97,23 +96,25 @@ class Components {
|
97 | 96 | * @param {Object} props Additional properties to add to the component.
|
98 | 97 | */
|
99 | 98 | set(node, props) {
|
100 |
| - while (node && !this._list[getId(node)]) { |
| 99 | + let component = this._list[getId(node)]; |
| 100 | + while (!component) { |
101 | 101 | node = node.parent;
|
| 102 | + if (!node) { |
| 103 | + return; |
| 104 | + } |
| 105 | + component = this._list[getId(node)]; |
102 | 106 | }
|
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 | + ); |
117 | 118 | }
|
118 | 119 |
|
119 | 120 | /**
|
@@ -758,7 +759,7 @@ function componentRule(rule, context) {
|
758 | 759 |
|
759 | 760 | // Update the provided rule instructions to add the component detection
|
760 | 761 | const ruleInstructions = rule(context, components, utils);
|
761 |
| - const updatedRuleInstructions = util._extend({}, ruleInstructions); |
| 762 | + const updatedRuleInstructions = Object.assign({}, ruleInstructions); |
762 | 763 | const propTypesInstructions = propTypesUtil(context, components, utils);
|
763 | 764 | const usedPropTypesInstructions = usedPropTypesUtil(context, components, utils);
|
764 | 765 | const defaultPropsInstructions = defaultPropsUtil(context, components, utils);
|
|
0 commit comments