mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Revert "Remove redundant initial of isArray (#21163)"
This reverts commit b130a0f5cd.
This commit is contained in:
@@ -145,8 +145,6 @@ export default {
|
||||
componentScope = currentScope;
|
||||
}
|
||||
|
||||
const isArray = Array.isArray;
|
||||
|
||||
// Next we'll define a few helpers that helps us
|
||||
// tell if some values don't have to be declared as deps.
|
||||
|
||||
@@ -159,7 +157,7 @@ export default {
|
||||
// ^^^ true for this reference
|
||||
// False for everything else.
|
||||
function isStableKnownHookValue(resolved) {
|
||||
if (!isArray(resolved.defs)) {
|
||||
if (!Array.isArray(resolved.defs)) {
|
||||
return false;
|
||||
}
|
||||
const def = resolved.defs[0];
|
||||
@@ -228,7 +226,7 @@ export default {
|
||||
if (
|
||||
id.type === 'ArrayPattern' &&
|
||||
id.elements.length === 2 &&
|
||||
isArray(resolved.identifiers)
|
||||
Array.isArray(resolved.identifiers)
|
||||
) {
|
||||
// Is second tuple value the same reference we're checking?
|
||||
if (id.elements[1] === resolved.identifiers[0]) {
|
||||
@@ -257,7 +255,7 @@ export default {
|
||||
} else if (name === 'useTransition') {
|
||||
if (
|
||||
id.type === 'ArrayPattern' &&
|
||||
isArray(resolved.identifiers)
|
||||
Array.isArray(resolved.identifiers)
|
||||
) {
|
||||
// Is first tuple value the same reference we're checking?
|
||||
if (id.elements[0] === resolved.identifiers[0]) {
|
||||
@@ -272,7 +270,7 @@ export default {
|
||||
|
||||
// Some are just functions that don't reference anything dynamic.
|
||||
function isFunctionWithoutCapturedValues(resolved) {
|
||||
if (!isArray(resolved.defs)) {
|
||||
if (!Array.isArray(resolved.defs)) {
|
||||
return false;
|
||||
}
|
||||
const def = resolved.defs[0];
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import {REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols';
|
||||
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
function captureAssertion(fn) {
|
||||
// Trick to use a Jest matcher inside another Jest matcher. `fn` contains an
|
||||
@@ -43,7 +42,7 @@ export function unstable_toMatchRenderedOutput(root, expectedJSX) {
|
||||
let actualJSX;
|
||||
if (actualJSON === null || typeof actualJSON === 'string') {
|
||||
actualJSX = actualJSON;
|
||||
} else if (isArray(actualJSON)) {
|
||||
} else if (Array.isArray(actualJSON)) {
|
||||
if (actualJSON.length === 0) {
|
||||
actualJSX = null;
|
||||
} else if (actualJSON.length === 1) {
|
||||
|
||||
+1
-2
@@ -105,7 +105,6 @@ import type {
|
||||
ElementType,
|
||||
} from 'react-devtools-shared/src/types';
|
||||
import is from 'shared/objectIs';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
type getDisplayNameForFiberType = (fiber: Fiber) => string | null;
|
||||
type getTypeSymbolType = (type: any) => Symbol | number;
|
||||
@@ -1138,7 +1137,7 @@ export function attach(
|
||||
memoizedState.hasOwnProperty('create') &&
|
||||
memoizedState.hasOwnProperty('destroy') &&
|
||||
memoizedState.hasOwnProperty('deps') &&
|
||||
(memoizedState.deps === null || isArray(memoizedState.deps)) &&
|
||||
(memoizedState.deps === null || Array.isArray(memoizedState.deps)) &&
|
||||
memoizedState.hasOwnProperty('next')
|
||||
);
|
||||
}
|
||||
|
||||
+5
-6
@@ -9,7 +9,6 @@
|
||||
|
||||
import {copy} from 'clipboard-js';
|
||||
import {dehydrate} from '../hydration';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
import type {DehydratedData} from 'react-devtools-shared/src/devtools/views/Components/types';
|
||||
|
||||
@@ -62,9 +61,9 @@ export function copyWithDelete(
|
||||
index: number = 0,
|
||||
): Object | Array<any> {
|
||||
const key = path[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
if (index + 1 === path.length) {
|
||||
if (isArray(updated)) {
|
||||
if (Array.isArray(updated)) {
|
||||
updated.splice(((key: any): number), 1);
|
||||
} else {
|
||||
delete updated[key];
|
||||
@@ -85,12 +84,12 @@ export function copyWithRename(
|
||||
index: number = 0,
|
||||
): Object | Array<any> {
|
||||
const oldKey = oldPath[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
if (index + 1 === oldPath.length) {
|
||||
const newKey = newPath[index];
|
||||
// $FlowFixMe number or string is fine here
|
||||
updated[newKey] = updated[oldKey];
|
||||
if (isArray(updated)) {
|
||||
if (Array.isArray(updated)) {
|
||||
updated.splice(((oldKey: any): number), 1);
|
||||
} else {
|
||||
delete updated[oldKey];
|
||||
@@ -112,7 +111,7 @@ export function copyWithSet(
|
||||
return value;
|
||||
}
|
||||
const key = path[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
// $FlowFixMe number or string is fine here
|
||||
updated[key] = copyWithSet(obj[key], path, value, index + 1);
|
||||
return updated;
|
||||
|
||||
+3
-4
@@ -12,7 +12,6 @@ import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCur
|
||||
|
||||
import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes';
|
||||
import {getToStringValue, toString} from './ToStringValue';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
let didWarnValueDefaultValue;
|
||||
|
||||
@@ -46,15 +45,15 @@ function checkSelectPropTypes(props) {
|
||||
if (props[propName] == null) {
|
||||
continue;
|
||||
}
|
||||
const propNameIsArray = isArray(props[propName]);
|
||||
if (props.multiple && !propNameIsArray) {
|
||||
const isArray = Array.isArray(props[propName]);
|
||||
if (props.multiple && !isArray) {
|
||||
console.error(
|
||||
'The `%s` prop supplied to <select> must be an array if ' +
|
||||
'`multiple` is true.%s',
|
||||
propName,
|
||||
getDeclarationErrorAddendum(),
|
||||
);
|
||||
} else if (!props.multiple && propNameIsArray) {
|
||||
} else if (!props.multiple && isArray) {
|
||||
console.error(
|
||||
'The `%s` prop supplied to <select> must be a scalar ' +
|
||||
'value if `multiple` is false.%s',
|
||||
|
||||
+2
-2
@@ -8,12 +8,12 @@
|
||||
*/
|
||||
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes';
|
||||
import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber';
|
||||
import {getToStringValue, toString} from './ToStringValue';
|
||||
import type {ToStringValue} from './ToStringValue';
|
||||
|
||||
import {disableTextareaChildren} from 'shared/ReactFeatureFlags';
|
||||
|
||||
let didWarnValDefaultVal = false;
|
||||
@@ -100,7 +100,7 @@ export function initWrapperState(element: Element, props: Object) {
|
||||
defaultValue == null,
|
||||
'If you supply `defaultValue` on a <textarea>, do not pass children.',
|
||||
);
|
||||
if (isArray(children)) {
|
||||
if (Array.isArray(children)) {
|
||||
invariant(
|
||||
children.length <= 1,
|
||||
'<textarea> can only have at most one child.',
|
||||
|
||||
@@ -46,7 +46,8 @@ import hyphenateStyleName from '../shared/hyphenateStyleName';
|
||||
import invariant from 'shared/invariant';
|
||||
import hasOwnProperty from 'shared/hasOwnProperty';
|
||||
import sanitizeURL from '../shared/sanitizeURL';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
const isArray = Array.isArray;
|
||||
|
||||
// Per response, global state that is not contextual to the rendering subtree.
|
||||
export type ResponseState = {
|
||||
|
||||
+5
-6
@@ -14,7 +14,6 @@ import type {ReactProvider, ReactContext} from 'shared/ReactTypes';
|
||||
|
||||
import * as React from 'react';
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
import getComponentNameFromType from 'shared/getComponentNameFromType';
|
||||
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
|
||||
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
||||
@@ -1439,7 +1438,7 @@ class ReactDOMServerRenderer {
|
||||
defaultValue == null,
|
||||
'If you supply `defaultValue` on a <textarea>, do not pass children.',
|
||||
);
|
||||
if (isArray(textareaChildren)) {
|
||||
if (Array.isArray(textareaChildren)) {
|
||||
invariant(
|
||||
textareaChildren.length <= 1,
|
||||
'<textarea> can only have at most one child.',
|
||||
@@ -1468,14 +1467,14 @@ class ReactDOMServerRenderer {
|
||||
if (props[propName] == null) {
|
||||
continue;
|
||||
}
|
||||
const propNameIsArray = isArray(props[propName]);
|
||||
if (props.multiple && !propNameIsArray) {
|
||||
const isArray = Array.isArray(props[propName]);
|
||||
if (props.multiple && !isArray) {
|
||||
console.error(
|
||||
'The `%s` prop supplied to <select> must be an array if ' +
|
||||
'`multiple` is true.',
|
||||
propName,
|
||||
);
|
||||
} else if (!props.multiple && propNameIsArray) {
|
||||
} else if (!props.multiple && isArray) {
|
||||
console.error(
|
||||
'The `%s` prop supplied to <select> must be a scalar ' +
|
||||
'value if `multiple` is false.',
|
||||
@@ -1516,7 +1515,7 @@ class ReactDOMServerRenderer {
|
||||
value = optionChildren;
|
||||
}
|
||||
selected = false;
|
||||
if (isArray(selectValue)) {
|
||||
if (Array.isArray(selectValue)) {
|
||||
// multiple
|
||||
for (let j = 0; j < selectValue.length; j++) {
|
||||
if ('' + selectValue[j] === value) {
|
||||
|
||||
+3
-4
@@ -24,7 +24,6 @@ import {
|
||||
rethrowCaughtError,
|
||||
invokeGuardedCallbackAndCatchFirstError,
|
||||
} from 'shared/ReactErrorUtils';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
// Keep in sync with ReactDOM.js, and ReactTestUtilsAct.js:
|
||||
const EventInternals =
|
||||
@@ -98,7 +97,7 @@ function validateClassInstance(inst, methodName) {
|
||||
}
|
||||
let received;
|
||||
const stringified = '' + inst;
|
||||
if (isArray(inst)) {
|
||||
if (Array.isArray(inst)) {
|
||||
received = 'an array';
|
||||
} else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
|
||||
received = 'a DOM node';
|
||||
@@ -198,7 +197,7 @@ function scryRenderedDOMComponentsWithClass(root, classNames) {
|
||||
}
|
||||
const classList = className.split(/\s+/);
|
||||
|
||||
if (!isArray(classNames)) {
|
||||
if (!Array.isArray(classNames)) {
|
||||
invariant(
|
||||
classNames !== undefined,
|
||||
'TestUtils.scryRenderedDOMComponentsWithClass expects a ' +
|
||||
@@ -366,7 +365,7 @@ function executeDispatch(event, listener, inst) {
|
||||
function executeDispatchesInOrder(event) {
|
||||
const dispatchListeners = event._dispatchListeners;
|
||||
const dispatchInstances = event._dispatchInstances;
|
||||
if (isArray(dispatchListeners)) {
|
||||
if (Array.isArray(dispatchListeners)) {
|
||||
for (let i = 0; i < dispatchListeners.length; i++) {
|
||||
if (event.isPropagationStopped()) {
|
||||
break;
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
deepDiffer,
|
||||
flattenStyle,
|
||||
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
import type {AttributeConfiguration} from './ReactNativeTypes';
|
||||
|
||||
@@ -52,7 +51,7 @@ function restoreDeletedValuesInNestedArray(
|
||||
node: NestedNode,
|
||||
validAttributes: AttributeConfiguration,
|
||||
) {
|
||||
if (isArray(node)) {
|
||||
if (Array.isArray(node)) {
|
||||
let i = node.length;
|
||||
while (i-- && removedKeyCount > 0) {
|
||||
restoreDeletedValuesInNestedArray(
|
||||
@@ -164,12 +163,12 @@ function diffNestedProperty(
|
||||
return updatePayload;
|
||||
}
|
||||
|
||||
if (!isArray(prevProp) && !isArray(nextProp)) {
|
||||
if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) {
|
||||
// Both are leaves, we can diff the leaves.
|
||||
return diffProperties(updatePayload, prevProp, nextProp, validAttributes);
|
||||
}
|
||||
|
||||
if (isArray(prevProp) && isArray(nextProp)) {
|
||||
if (Array.isArray(prevProp) && Array.isArray(nextProp)) {
|
||||
// Both are arrays, we can diff the arrays.
|
||||
return diffNestedArrayProperty(
|
||||
updatePayload,
|
||||
@@ -179,7 +178,7 @@ function diffNestedProperty(
|
||||
);
|
||||
}
|
||||
|
||||
if (isArray(prevProp)) {
|
||||
if (Array.isArray(prevProp)) {
|
||||
return diffProperties(
|
||||
updatePayload,
|
||||
// $FlowFixMe - We know that this is always an object when the input is.
|
||||
@@ -213,7 +212,7 @@ function addNestedProperty(
|
||||
return updatePayload;
|
||||
}
|
||||
|
||||
if (!isArray(nextProp)) {
|
||||
if (!Array.isArray(nextProp)) {
|
||||
// Add each property of the leaf.
|
||||
return addProperties(updatePayload, nextProp, validAttributes);
|
||||
}
|
||||
@@ -243,7 +242,7 @@ function clearNestedProperty(
|
||||
return updatePayload;
|
||||
}
|
||||
|
||||
if (!isArray(prevProp)) {
|
||||
if (!Array.isArray(prevProp)) {
|
||||
// Add each property of the leaf.
|
||||
return clearProperties(updatePayload, prevProp, validAttributes);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
import {invokeGuardedCallbackAndCatchFirstError} from 'shared/ReactErrorUtils';
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
export let getFiberCurrentPropsFromNode = null;
|
||||
export let getInstanceFromNode = null;
|
||||
@@ -37,14 +36,14 @@ if (__DEV__) {
|
||||
const dispatchListeners = event._dispatchListeners;
|
||||
const dispatchInstances = event._dispatchInstances;
|
||||
|
||||
const listenersIsArr = isArray(dispatchListeners);
|
||||
const listenersIsArr = Array.isArray(dispatchListeners);
|
||||
const listenersLen = listenersIsArr
|
||||
? dispatchListeners.length
|
||||
: dispatchListeners
|
||||
? 1
|
||||
: 0;
|
||||
|
||||
const instancesIsArr = isArray(dispatchInstances);
|
||||
const instancesIsArr = Array.isArray(dispatchInstances);
|
||||
const instancesLen = instancesIsArr
|
||||
? dispatchInstances.length
|
||||
: dispatchInstances
|
||||
@@ -79,7 +78,7 @@ export function executeDispatchesInOrder(event) {
|
||||
if (__DEV__) {
|
||||
validateEventDispatches(event);
|
||||
}
|
||||
if (isArray(dispatchListeners)) {
|
||||
if (Array.isArray(dispatchListeners)) {
|
||||
for (let i = 0; i < dispatchListeners.length; i++) {
|
||||
if (event.isPropagationStopped()) {
|
||||
break;
|
||||
@@ -107,7 +106,7 @@ function executeDispatchesInOrderStopAtTrueImpl(event) {
|
||||
if (__DEV__) {
|
||||
validateEventDispatches(event);
|
||||
}
|
||||
if (isArray(dispatchListeners)) {
|
||||
if (Array.isArray(dispatchListeners)) {
|
||||
for (let i = 0; i < dispatchListeners.length; i++) {
|
||||
if (event.isPropagationStopped()) {
|
||||
break;
|
||||
@@ -151,7 +150,7 @@ export function executeDirectDispatch(event) {
|
||||
const dispatchListener = event._dispatchListeners;
|
||||
const dispatchInstance = event._dispatchInstances;
|
||||
invariant(
|
||||
!isArray(dispatchListener),
|
||||
!Array.isArray(dispatchListener),
|
||||
'executeDirectDispatch(...): Invalid `event`.',
|
||||
);
|
||||
event.currentTarget = dispatchListener
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
/**
|
||||
* Accumulates items that must not be null or undefined.
|
||||
@@ -32,11 +31,11 @@ function accumulate<T>(
|
||||
|
||||
// Both are not empty. Warning: Never call x.concat(y) when you are not
|
||||
// certain that x is an Array (x could be a string with concat method).
|
||||
if (isArray(current)) {
|
||||
if (Array.isArray(current)) {
|
||||
return current.concat(next);
|
||||
}
|
||||
|
||||
if (isArray(next)) {
|
||||
if (Array.isArray(next)) {
|
||||
return [current].concat(next);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
/**
|
||||
* Accumulates items that must not be null or undefined into the first one. This
|
||||
@@ -38,8 +37,8 @@ function accumulateInto<T>(
|
||||
|
||||
// Both are not empty. Warning: Never call x.concat(y) when you are not
|
||||
// certain that x is an Array (x could be a string with concat method).
|
||||
if (isArray(current)) {
|
||||
if (isArray(next)) {
|
||||
if (Array.isArray(current)) {
|
||||
if (Array.isArray(next)) {
|
||||
current.push.apply(current, next);
|
||||
return current;
|
||||
}
|
||||
@@ -47,7 +46,7 @@ function accumulateInto<T>(
|
||||
return current;
|
||||
}
|
||||
|
||||
if (isArray(next)) {
|
||||
if (Array.isArray(next)) {
|
||||
// A bit too dangerous to mutate `next`.
|
||||
return [current].concat(next);
|
||||
}
|
||||
|
||||
+4
-5
@@ -21,7 +21,6 @@ import type {RootTag} from 'react-reconciler/src/ReactRootTags';
|
||||
|
||||
import * as Scheduler from 'scheduler/unstable_mock';
|
||||
import {REACT_FRAGMENT_TYPE, REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
|
||||
import isArray from 'shared/isArray';
|
||||
import {
|
||||
DefaultEventPriority,
|
||||
IdleEventPriority,
|
||||
@@ -605,7 +604,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
if (typeof child === 'string') {
|
||||
return child;
|
||||
}
|
||||
if (isArray(child)) {
|
||||
if (Array.isArray(child)) {
|
||||
if (child.length === 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -619,7 +618,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
}
|
||||
return children;
|
||||
}
|
||||
if (isArray(child.children)) {
|
||||
if (Array.isArray(child.children)) {
|
||||
// This is an instance.
|
||||
const instance: Instance = (child: any);
|
||||
const children = childToJSX(instance.children, instance.text);
|
||||
@@ -669,7 +668,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
if (children === null) {
|
||||
return null;
|
||||
}
|
||||
if (isArray(children)) {
|
||||
if (Array.isArray(children)) {
|
||||
return {
|
||||
$$typeof: REACT_ELEMENT_TYPE,
|
||||
type: REACT_FRAGMENT_TYPE,
|
||||
@@ -688,7 +687,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
|
||||
if (children === null) {
|
||||
return null;
|
||||
}
|
||||
if (isArray(children)) {
|
||||
if (Array.isArray(children)) {
|
||||
return {
|
||||
$$typeof: REACT_ELEMENT_TYPE,
|
||||
type: REACT_FRAGMENT_TYPE,
|
||||
|
||||
@@ -31,7 +31,6 @@ import {
|
||||
SimpleMemoComponent,
|
||||
} from './ReactWorkTags';
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
import {
|
||||
warnAboutStringRefs,
|
||||
enableLazyElements,
|
||||
@@ -98,6 +97,8 @@ if (__DEV__) {
|
||||
};
|
||||
}
|
||||
|
||||
const isArray = Array.isArray;
|
||||
|
||||
function coerceRef(
|
||||
returnFiber: Fiber,
|
||||
current: Fiber | null,
|
||||
|
||||
@@ -11,7 +11,6 @@ import type {ReactElement} from 'shared/ReactElementType';
|
||||
import type {ReactPortal} from 'shared/ReactTypes';
|
||||
import type {Fiber} from './ReactInternalTypes';
|
||||
import type {Lanes} from './ReactFiberLane.old';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
|
||||
import {Placement, ChildDeletion} from './ReactFiberFlags';
|
||||
@@ -98,6 +97,8 @@ if (__DEV__) {
|
||||
};
|
||||
}
|
||||
|
||||
const isArray = Array.isArray;
|
||||
|
||||
function coerceRef(
|
||||
returnFiber: Fiber,
|
||||
current: Fiber | null,
|
||||
|
||||
@@ -29,7 +29,6 @@ import shallowEqual from 'shared/shallowEqual';
|
||||
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
|
||||
import getComponentNameFromType from 'shared/getComponentNameFromType';
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols';
|
||||
|
||||
import {resolveDefaultProps} from './ReactFiberLazyComponent.new';
|
||||
@@ -75,6 +74,7 @@ import {
|
||||
} from './SchedulingProfiler';
|
||||
|
||||
const fakeInternalInstance = {};
|
||||
const isArray = Array.isArray;
|
||||
|
||||
// React.Component uses a shared frozen object by default.
|
||||
// We'll use it to determine whether we need to initialize legacy refs.
|
||||
|
||||
@@ -29,7 +29,6 @@ import shallowEqual from 'shared/shallowEqual';
|
||||
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
|
||||
import getComponentNameFromType from 'shared/getComponentNameFromType';
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols';
|
||||
|
||||
import {resolveDefaultProps} from './ReactFiberLazyComponent.old';
|
||||
@@ -75,6 +74,7 @@ import {
|
||||
} from './SchedulingProfiler';
|
||||
|
||||
const fakeInternalInstance = {};
|
||||
const isArray = Array.isArray;
|
||||
|
||||
// React.Component uses a shared frozen object by default.
|
||||
// We'll use it to determine whether we need to initialize legacy refs.
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
} from './ReactWorkTags';
|
||||
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
|
||||
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
||||
import {getPublicInstance} from './ReactFiberHostConfig';
|
||||
@@ -483,9 +482,9 @@ if (__DEV__) {
|
||||
index: number,
|
||||
) => {
|
||||
const key = path[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
if (index + 1 === path.length) {
|
||||
if (isArray(updated)) {
|
||||
if (Array.isArray(updated)) {
|
||||
updated.splice(((key: any): number), 1);
|
||||
} else {
|
||||
delete updated[key];
|
||||
@@ -511,12 +510,12 @@ if (__DEV__) {
|
||||
index: number,
|
||||
) => {
|
||||
const oldKey = oldPath[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
if (index + 1 === oldPath.length) {
|
||||
const newKey = newPath[index];
|
||||
// $FlowFixMe number or string is fine here
|
||||
updated[newKey] = updated[oldKey];
|
||||
if (isArray(updated)) {
|
||||
if (Array.isArray(updated)) {
|
||||
updated.splice(((oldKey: any): number), 1);
|
||||
} else {
|
||||
delete updated[oldKey];
|
||||
@@ -565,7 +564,7 @@ if (__DEV__) {
|
||||
return value;
|
||||
}
|
||||
const key = path[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
// $FlowFixMe number or string is fine here
|
||||
updated[key] = copyWithSetImpl(obj[key], path, index + 1, value);
|
||||
return updated;
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
} from './ReactWorkTags';
|
||||
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
|
||||
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
||||
import {getPublicInstance} from './ReactFiberHostConfig';
|
||||
@@ -483,9 +482,9 @@ if (__DEV__) {
|
||||
index: number,
|
||||
) => {
|
||||
const key = path[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
if (index + 1 === path.length) {
|
||||
if (isArray(updated)) {
|
||||
if (Array.isArray(updated)) {
|
||||
updated.splice(((key: any): number), 1);
|
||||
} else {
|
||||
delete updated[key];
|
||||
@@ -511,12 +510,12 @@ if (__DEV__) {
|
||||
index: number,
|
||||
) => {
|
||||
const oldKey = oldPath[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
if (index + 1 === oldPath.length) {
|
||||
const newKey = newPath[index];
|
||||
// $FlowFixMe number or string is fine here
|
||||
updated[newKey] = updated[oldKey];
|
||||
if (isArray(updated)) {
|
||||
if (Array.isArray(updated)) {
|
||||
updated.splice(((oldKey: any): number), 1);
|
||||
} else {
|
||||
delete updated[oldKey];
|
||||
@@ -565,7 +564,7 @@ if (__DEV__) {
|
||||
return value;
|
||||
}
|
||||
const key = path[index];
|
||||
const updated = isArray(obj) ? obj.slice() : {...obj};
|
||||
const updated = Array.isArray(obj) ? obj.slice() : {...obj};
|
||||
// $FlowFixMe number or string is fine here
|
||||
updated[key] = copyWithSetImpl(obj[key], path, index + 1, value);
|
||||
return updated;
|
||||
|
||||
@@ -14,7 +14,6 @@ import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';
|
||||
import JSResourceReference from 'JSResourceReference';
|
||||
|
||||
import hasOwnProperty from 'shared/hasOwnProperty';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
export type ModuleReference<T> = JSResourceReference<T>;
|
||||
|
||||
@@ -83,7 +82,7 @@ function convertModelToJSON(
|
||||
): JSONValue {
|
||||
const json = resolveModelToJSON(request, parent, key, model);
|
||||
if (typeof json === 'object' && json !== null) {
|
||||
if (isArray(json)) {
|
||||
if (Array.isArray(json)) {
|
||||
const jsonArray: Array<JSONValue> = [];
|
||||
for (let i = 0; i < json.length; i++) {
|
||||
jsonArray[i] = convertModelToJSON(request, json, '' + i, json[i]);
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@
|
||||
*/
|
||||
|
||||
import type {RowEncoding, JSONValue} from './ReactFlightNativeRelayProtocol';
|
||||
|
||||
import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';
|
||||
import hasOwnProperty from 'shared/hasOwnProperty';
|
||||
import isArray from 'shared/isArray';
|
||||
import JSResourceReferenceImpl from 'JSResourceReferenceImpl';
|
||||
|
||||
export type ModuleReference<T> = JSResourceReferenceImpl<T>;
|
||||
@@ -80,7 +80,7 @@ function convertModelToJSON(
|
||||
): JSONValue {
|
||||
const json = resolveModelToJSON(request, parent, key, model);
|
||||
if (typeof json === 'object' && json !== null) {
|
||||
if (isArray(json)) {
|
||||
if (Array.isArray(json)) {
|
||||
const jsonArray: Array<JSONValue> = [];
|
||||
for (let i = 0; i < json.length; i++) {
|
||||
jsonArray[i] = convertModelToJSON(request, json, '' + i, json[i]);
|
||||
|
||||
+1
-2
@@ -51,7 +51,6 @@ import {REACT_ELEMENT_TYPE, REACT_SUSPENSE_TYPE} from 'shared/ReactSymbols';
|
||||
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
||||
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
|
||||
|
||||
@@ -288,7 +287,7 @@ function renderNode(request: Request, task: Task, node: ReactNodeList): void {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isArray(node)) {
|
||||
if (Array.isArray(node)) {
|
||||
if (node.length > 0) {
|
||||
for (let i = 0; i < node.length; i++) {
|
||||
renderNode(request, task, node[i]);
|
||||
|
||||
+2
-1
@@ -44,7 +44,8 @@ import {
|
||||
|
||||
import ReactSharedInternals from 'shared/ReactSharedInternals';
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
const isArray = Array.isArray;
|
||||
|
||||
type ReactJSONValue =
|
||||
| string
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
import type {ReactNodeList} from 'shared/ReactTypes';
|
||||
|
||||
import invariant from 'shared/invariant';
|
||||
import isArray from 'shared/isArray';
|
||||
import {
|
||||
getIteratorFn,
|
||||
REACT_ELEMENT_TYPE,
|
||||
@@ -111,7 +110,7 @@ function mapIntoArray(
|
||||
// so that it's consistent if the number of children grows:
|
||||
const childKey =
|
||||
nameSoFar === '' ? SEPARATOR + getElementKey(child, 0) : nameSoFar;
|
||||
if (isArray(mappedChild)) {
|
||||
if (Array.isArray(mappedChild)) {
|
||||
let escapedChildKey = '';
|
||||
if (childKey != null) {
|
||||
escapedChildKey = escapeUserProvidedKey(childKey) + '/';
|
||||
@@ -143,7 +142,7 @@ function mapIntoArray(
|
||||
const nextNamePrefix =
|
||||
nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
|
||||
|
||||
if (isArray(children)) {
|
||||
if (Array.isArray(children)) {
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
child = children[i];
|
||||
nextName = nextNamePrefix + getElementKey(child, i);
|
||||
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
} from 'shared/ReactSymbols';
|
||||
import {warnAboutSpreadingKeyToJSX} from 'shared/ReactFeatureFlags';
|
||||
import checkPropTypes from 'shared/checkPropTypes';
|
||||
import isArray from 'shared/isArray';
|
||||
|
||||
import ReactCurrentOwner from './ReactCurrentOwner';
|
||||
import {
|
||||
@@ -169,7 +168,7 @@ function validateChildKeys(node, parentType) {
|
||||
if (typeof node !== 'object') {
|
||||
return;
|
||||
}
|
||||
if (isArray(node)) {
|
||||
if (Array.isArray(node)) {
|
||||
for (let i = 0; i < node.length; i++) {
|
||||
const child = node[i];
|
||||
if (isValidElement(child)) {
|
||||
@@ -314,7 +313,7 @@ export function jsxWithValidation(
|
||||
let typeString;
|
||||
if (type === null) {
|
||||
typeString = 'null';
|
||||
} else if (isArray(type)) {
|
||||
} else if (Array.isArray(type)) {
|
||||
typeString = 'array';
|
||||
} else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
|
||||
typeString = `<${getComponentNameFromType(type.type) || 'Unknown'} />`;
|
||||
@@ -353,7 +352,7 @@ export function jsxWithValidation(
|
||||
const children = props.children;
|
||||
if (children !== undefined) {
|
||||
if (isStaticChildren) {
|
||||
if (isArray(children)) {
|
||||
if (Array.isArray(children)) {
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
validateChildKeys(children[i], type);
|
||||
}
|
||||
@@ -438,7 +437,7 @@ export function createElementWithValidation(type, props, children) {
|
||||
let typeString;
|
||||
if (type === null) {
|
||||
typeString = 'null';
|
||||
} else if (isArray(type)) {
|
||||
} else if (Array.isArray(type)) {
|
||||
typeString = 'array';
|
||||
} else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
|
||||
typeString = `<${getComponentNameFromType(type.type) || 'Unknown'} />`;
|
||||
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
} from 'shared/ReactSymbols';
|
||||
import {warnAboutSpreadingKeyToJSX} from 'shared/ReactFeatureFlags';
|
||||
import hasOwnProperty from 'shared/hasOwnProperty';
|
||||
import isArray from 'shared/isArray';
|
||||
import {jsxDEV} from './ReactJSXElement';
|
||||
|
||||
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
|
||||
@@ -183,7 +182,7 @@ function validateChildKeys(node, parentType) {
|
||||
if (typeof node !== 'object') {
|
||||
return;
|
||||
}
|
||||
if (isArray(node)) {
|
||||
if (Array.isArray(node)) {
|
||||
for (let i = 0; i < node.length; i++) {
|
||||
const child = node[i];
|
||||
if (isValidElement(child)) {
|
||||
@@ -330,7 +329,7 @@ export function jsxWithValidation(
|
||||
let typeString;
|
||||
if (type === null) {
|
||||
typeString = 'null';
|
||||
} else if (isArray(type)) {
|
||||
} else if (Array.isArray(type)) {
|
||||
typeString = 'array';
|
||||
} else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
|
||||
typeString = `<${getComponentNameFromType(type.type) || 'Unknown'} />`;
|
||||
@@ -367,7 +366,7 @@ export function jsxWithValidation(
|
||||
const children = props.children;
|
||||
if (children !== undefined) {
|
||||
if (isStaticChildren) {
|
||||
if (isArray(children)) {
|
||||
if (Array.isArray(children)) {
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
validateChildKeys(children[i], type);
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
*/
|
||||
|
||||
const isArray = Array.isArray;
|
||||
|
||||
export default isArray;
|
||||
Reference in New Issue
Block a user