Skip to content

Commit b4f119c

Browse files
committed
Revert "Remove redundant initial of isArray (#21163)"
This reverts commit b130a0f.
1 parent c031970 commit b4f119c

28 files changed

+77
-105
lines changed

packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ export default {
145145
componentScope = currentScope;
146146
}
147147

148-
const isArray = Array.isArray;
149-
150148
// Next we'll define a few helpers that helps us
151149
// tell if some values don't have to be declared as deps.
152150

@@ -159,7 +157,7 @@ export default {
159157
// ^^^ true for this reference
160158
// False for everything else.
161159
function isStableKnownHookValue(resolved) {
162-
if (!isArray(resolved.defs)) {
160+
if (!Array.isArray(resolved.defs)) {
163161
return false;
164162
}
165163
const def = resolved.defs[0];
@@ -228,7 +226,7 @@ export default {
228226
if (
229227
id.type === 'ArrayPattern' &&
230228
id.elements.length === 2 &&
231-
isArray(resolved.identifiers)
229+
Array.isArray(resolved.identifiers)
232230
) {
233231
// Is second tuple value the same reference we're checking?
234232
if (id.elements[1] === resolved.identifiers[0]) {
@@ -257,7 +255,7 @@ export default {
257255
} else if (name === 'useTransition') {
258256
if (
259257
id.type === 'ArrayPattern' &&
260-
isArray(resolved.identifiers)
258+
Array.isArray(resolved.identifiers)
261259
) {
262260
// Is first tuple value the same reference we're checking?
263261
if (id.elements[0] === resolved.identifiers[0]) {
@@ -272,7 +270,7 @@ export default {
272270

273271
// Some are just functions that don't reference anything dynamic.
274272
function isFunctionWithoutCapturedValues(resolved) {
275-
if (!isArray(resolved.defs)) {
273+
if (!Array.isArray(resolved.defs)) {
276274
return false;
277275
}
278276
const def = resolved.defs[0];

packages/jest-react/src/JestReact.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import {REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols';
99

1010
import invariant from 'shared/invariant';
11-
import isArray from 'shared/isArray';
1211

1312
function captureAssertion(fn) {
1413
// Trick to use a Jest matcher inside another Jest matcher. `fn` contains an
@@ -43,7 +42,7 @@ export function unstable_toMatchRenderedOutput(root, expectedJSX) {
4342
let actualJSX;
4443
if (actualJSON === null || typeof actualJSON === 'string') {
4544
actualJSX = actualJSON;
46-
} else if (isArray(actualJSON)) {
45+
} else if (Array.isArray(actualJSON)) {
4746
if (actualJSON.length === 0) {
4847
actualJSX = null;
4948
} else if (actualJSON.length === 1) {

packages/react-devtools-shared/src/backend/renderer.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ import type {
105105
ElementType,
106106
} from 'react-devtools-shared/src/types';
107107
import is from 'shared/objectIs';
108-
import isArray from 'shared/isArray';
109108

110109
type getDisplayNameForFiberType = (fiber: Fiber) => string | null;
111110
type getTypeSymbolType = (type: any) => Symbol | number;
@@ -1138,7 +1137,7 @@ export function attach(
11381137
memoizedState.hasOwnProperty('create') &&
11391138
memoizedState.hasOwnProperty('destroy') &&
11401139
memoizedState.hasOwnProperty('deps') &&
1141-
(memoizedState.deps === null || isArray(memoizedState.deps)) &&
1140+
(memoizedState.deps === null || Array.isArray(memoizedState.deps)) &&
11421141
memoizedState.hasOwnProperty('next')
11431142
);
11441143
}

packages/react-devtools-shared/src/backend/utils.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import {copy} from 'clipboard-js';
1111
import {dehydrate} from '../hydration';
12-
import isArray from 'shared/isArray';
1312

1413
import type {DehydratedData} from 'react-devtools-shared/src/devtools/views/Components/types';
1514

@@ -62,9 +61,9 @@ export function copyWithDelete(
6261
index: number = 0,
6362
): Object | Array<any> {
6463
const key = path[index];
65-
const updated = isArray(obj) ? obj.slice() : {...obj};
64+
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
6665
if (index + 1 === path.length) {
67-
if (isArray(updated)) {
66+
if (Array.isArray(updated)) {
6867
updated.splice(((key: any): number), 1);
6968
} else {
7069
delete updated[key];
@@ -85,12 +84,12 @@ export function copyWithRename(
8584
index: number = 0,
8685
): Object | Array<any> {
8786
const oldKey = oldPath[index];
88-
const updated = isArray(obj) ? obj.slice() : {...obj};
87+
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
8988
if (index + 1 === oldPath.length) {
9089
const newKey = newPath[index];
9190
// $FlowFixMe number or string is fine here
9291
updated[newKey] = updated[oldKey];
93-
if (isArray(updated)) {
92+
if (Array.isArray(updated)) {
9493
updated.splice(((oldKey: any): number), 1);
9594
} else {
9695
delete updated[oldKey];
@@ -112,7 +111,7 @@ export function copyWithSet(
112111
return value;
113112
}
114113
const key = path[index];
115-
const updated = isArray(obj) ? obj.slice() : {...obj};
114+
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
116115
// $FlowFixMe number or string is fine here
117116
updated[key] = copyWithSet(obj[key], path, value, index + 1);
118117
return updated;

packages/react-dom/src/client/ReactDOMSelect.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCur
1212

1313
import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes';
1414
import {getToStringValue, toString} from './ToStringValue';
15-
import isArray from 'shared/isArray';
1615

1716
let didWarnValueDefaultValue;
1817

@@ -46,15 +45,15 @@ function checkSelectPropTypes(props) {
4645
if (props[propName] == null) {
4746
continue;
4847
}
49-
const propNameIsArray = isArray(props[propName]);
50-
if (props.multiple && !propNameIsArray) {
48+
const isArray = Array.isArray(props[propName]);
49+
if (props.multiple && !isArray) {
5150
console.error(
5251
'The `%s` prop supplied to <select> must be an array if ' +
5352
'`multiple` is true.%s',
5453
propName,
5554
getDeclarationErrorAddendum(),
5655
);
57-
} else if (!props.multiple && propNameIsArray) {
56+
} else if (!props.multiple && isArray) {
5857
console.error(
5958
'The `%s` prop supplied to <select> must be a scalar ' +
6059
'value if `multiple` is false.%s',

packages/react-dom/src/client/ReactDOMTextarea.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
*/
99

1010
import invariant from 'shared/invariant';
11-
import isArray from 'shared/isArray';
1211

1312
import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes';
1413
import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
1514
import {getToStringValue, toString} from './ToStringValue';
1615
import type {ToStringValue} from './ToStringValue';
16+
1717
import {disableTextareaChildren} from 'shared/ReactFeatureFlags';
1818

1919
let didWarnValDefaultVal = false;
@@ -100,7 +100,7 @@ export function initWrapperState(element: Element, props: Object) {
100100
defaultValue == null,
101101
'If you supply `defaultValue` on a <textarea>, do not pass children.',
102102
);
103-
if (isArray(children)) {
103+
if (Array.isArray(children)) {
104104
invariant(
105105
children.length <= 1,
106106
'<textarea> can only have at most one child.',

packages/react-dom/src/server/ReactDOMServerFormatConfig.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ import hyphenateStyleName from '../shared/hyphenateStyleName';
4646
import invariant from 'shared/invariant';
4747
import hasOwnProperty from 'shared/hasOwnProperty';
4848
import sanitizeURL from '../shared/sanitizeURL';
49-
import isArray from 'shared/isArray';
49+
50+
const isArray = Array.isArray;
5051

5152
// Per response, global state that is not contextual to the rendering subtree.
5253
export type ResponseState = {

packages/react-dom/src/server/ReactPartialRenderer.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {ReactProvider, ReactContext} from 'shared/ReactTypes';
1414

1515
import * as React from 'react';
1616
import invariant from 'shared/invariant';
17-
import isArray from 'shared/isArray';
1817
import getComponentNameFromType from 'shared/getComponentNameFromType';
1918
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
2019
import ReactSharedInternals from 'shared/ReactSharedInternals';
@@ -1439,7 +1438,7 @@ class ReactDOMServerRenderer {
14391438
defaultValue == null,
14401439
'If you supply `defaultValue` on a <textarea>, do not pass children.',
14411440
);
1442-
if (isArray(textareaChildren)) {
1441+
if (Array.isArray(textareaChildren)) {
14431442
invariant(
14441443
textareaChildren.length <= 1,
14451444
'<textarea> can only have at most one child.',
@@ -1468,14 +1467,14 @@ class ReactDOMServerRenderer {
14681467
if (props[propName] == null) {
14691468
continue;
14701469
}
1471-
const propNameIsArray = isArray(props[propName]);
1472-
if (props.multiple && !propNameIsArray) {
1470+
const isArray = Array.isArray(props[propName]);
1471+
if (props.multiple && !isArray) {
14731472
console.error(
14741473
'The `%s` prop supplied to <select> must be an array if ' +
14751474
'`multiple` is true.',
14761475
propName,
14771476
);
1478-
} else if (!props.multiple && propNameIsArray) {
1477+
} else if (!props.multiple && isArray) {
14791478
console.error(
14801479
'The `%s` prop supplied to <select> must be a scalar ' +
14811480
'value if `multiple` is false.',
@@ -1516,7 +1515,7 @@ class ReactDOMServerRenderer {
15161515
value = optionChildren;
15171516
}
15181517
selected = false;
1519-
if (isArray(selectValue)) {
1518+
if (Array.isArray(selectValue)) {
15201519
// multiple
15211520
for (let j = 0; j < selectValue.length; j++) {
15221521
if ('' + selectValue[j] === value) {

packages/react-dom/src/test-utils/ReactTestUtils.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
rethrowCaughtError,
2525
invokeGuardedCallbackAndCatchFirstError,
2626
} from 'shared/ReactErrorUtils';
27-
import isArray from 'shared/isArray';
2827

2928
// Keep in sync with ReactDOM.js, and ReactTestUtilsAct.js:
3029
const EventInternals =
@@ -98,7 +97,7 @@ function validateClassInstance(inst, methodName) {
9897
}
9998
let received;
10099
const stringified = '' + inst;
101-
if (isArray(inst)) {
100+
if (Array.isArray(inst)) {
102101
received = 'an array';
103102
} else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
104103
received = 'a DOM node';
@@ -198,7 +197,7 @@ function scryRenderedDOMComponentsWithClass(root, classNames) {
198197
}
199198
const classList = className.split(/\s+/);
200199

201-
if (!isArray(classNames)) {
200+
if (!Array.isArray(classNames)) {
202201
invariant(
203202
classNames !== undefined,
204203
'TestUtils.scryRenderedDOMComponentsWithClass expects a ' +
@@ -366,7 +365,7 @@ function executeDispatch(event, listener, inst) {
366365
function executeDispatchesInOrder(event) {
367366
const dispatchListeners = event._dispatchListeners;
368367
const dispatchInstances = event._dispatchInstances;
369-
if (isArray(dispatchListeners)) {
368+
if (Array.isArray(dispatchListeners)) {
370369
for (let i = 0; i < dispatchListeners.length; i++) {
371370
if (event.isPropagationStopped()) {
372371
break;

packages/react-native-renderer/src/ReactNativeAttributePayload.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
deepDiffer,
1313
flattenStyle,
1414
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
15-
import isArray from 'shared/isArray';
1615

1716
import type {AttributeConfiguration} from './ReactNativeTypes';
1817

@@ -52,7 +51,7 @@ function restoreDeletedValuesInNestedArray(
5251
node: NestedNode,
5352
validAttributes: AttributeConfiguration,
5453
) {
55-
if (isArray(node)) {
54+
if (Array.isArray(node)) {
5655
let i = node.length;
5756
while (i-- && removedKeyCount > 0) {
5857
restoreDeletedValuesInNestedArray(
@@ -164,12 +163,12 @@ function diffNestedProperty(
164163
return updatePayload;
165164
}
166165

167-
if (!isArray(prevProp) && !isArray(nextProp)) {
166+
if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) {
168167
// Both are leaves, we can diff the leaves.
169168
return diffProperties(updatePayload, prevProp, nextProp, validAttributes);
170169
}
171170

172-
if (isArray(prevProp) && isArray(nextProp)) {
171+
if (Array.isArray(prevProp) && Array.isArray(nextProp)) {
173172
// Both are arrays, we can diff the arrays.
174173
return diffNestedArrayProperty(
175174
updatePayload,
@@ -179,7 +178,7 @@ function diffNestedProperty(
179178
);
180179
}
181180

182-
if (isArray(prevProp)) {
181+
if (Array.isArray(prevProp)) {
183182
return diffProperties(
184183
updatePayload,
185184
// $FlowFixMe - We know that this is always an object when the input is.
@@ -213,7 +212,7 @@ function addNestedProperty(
213212
return updatePayload;
214213
}
215214

216-
if (!isArray(nextProp)) {
215+
if (!Array.isArray(nextProp)) {
217216
// Add each property of the leaf.
218217
return addProperties(updatePayload, nextProp, validAttributes);
219218
}
@@ -243,7 +242,7 @@ function clearNestedProperty(
243242
return updatePayload;
244243
}
245244

246-
if (!isArray(prevProp)) {
245+
if (!Array.isArray(prevProp)) {
247246
// Add each property of the leaf.
248247
return clearProperties(updatePayload, prevProp, validAttributes);
249248
}

packages/react-native-renderer/src/legacy-events/EventPluginUtils.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils';
99
import invariant from 'shared/invariant';
10-
import isArray from 'shared/isArray';
1110

1211
export let getFiberCurrentPropsFromNode = null;
1312
export let getInstanceFromNode = null;
@@ -37,14 +36,14 @@ if (__DEV__) {
3736
const dispatchListeners = event._dispatchListeners;
3837
const dispatchInstances = event._dispatchInstances;
3938

40-
const listenersIsArr = isArray(dispatchListeners);
39+
const listenersIsArr = Array.isArray(dispatchListeners);
4140
const listenersLen = listenersIsArr
4241
? dispatchListeners.length
4342
: dispatchListeners
4443
? 1
4544
: 0;
4645

47-
const instancesIsArr = isArray(dispatchInstances);
46+
const instancesIsArr = Array.isArray(dispatchInstances);
4847
const instancesLen = instancesIsArr
4948
? dispatchInstances.length
5049
: dispatchInstances
@@ -79,7 +78,7 @@ export function executeDispatchesInOrder(event) {
7978
if (__DEV__) {
8079
validateEventDispatches(event);
8180
}
82-
if (isArray(dispatchListeners)) {
81+
if (Array.isArray(dispatchListeners)) {
8382
for (let i = 0; i < dispatchListeners.length; i++) {
8483
if (event.isPropagationStopped()) {
8584
break;
@@ -107,7 +106,7 @@ function executeDispatchesInOrderStopAtTrueImpl(event) {
107106
if (__DEV__) {
108107
validateEventDispatches(event);
109108
}
110-
if (isArray(dispatchListeners)) {
109+
if (Array.isArray(dispatchListeners)) {
111110
for (let i = 0; i < dispatchListeners.length; i++) {
112111
if (event.isPropagationStopped()) {
113112
break;
@@ -151,7 +150,7 @@ export function executeDirectDispatch(event) {
151150
const dispatchListener = event._dispatchListeners;
152151
const dispatchInstance = event._dispatchInstances;
153152
invariant(
154-
!isArray(dispatchListener),
153+
!Array.isArray(dispatchListener),
155154
'executeDirectDispatch(...): Invalid `event`.',
156155
);
157156
event.currentTarget = dispatchListener

packages/react-native-renderer/src/legacy-events/accumulate.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import invariant from 'shared/invariant';
11-
import isArray from 'shared/isArray';
1211

1312
/**
1413
* Accumulates items that must not be null or undefined.
@@ -32,11 +31,11 @@ function accumulate<T>(
3231

3332
// Both are not empty. Warning: Never call x.concat(y) when you are not
3433
// certain that x is an Array (x could be a string with concat method).
35-
if (isArray(current)) {
34+
if (Array.isArray(current)) {
3635
return current.concat(next);
3736
}
3837

39-
if (isArray(next)) {
38+
if (Array.isArray(next)) {
4039
return [current].concat(next);
4140
}
4241

0 commit comments

Comments
 (0)