From b4f119cdf1defe2437e00022f670c6ef818cd43f Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Thu, 1 Apr 2021 15:19:00 -0400 Subject: [PATCH] Revert "Remove redundant initial of isArray (#21163)" This reverts commit b130a0f5cd4f29a1c3147f66e10914c42847678a. --- .../eslint-plugin-react-hooks/src/ExhaustiveDeps.js | 10 ++++------ packages/jest-react/src/JestReact.js | 3 +-- .../react-devtools-shared/src/backend/renderer.js | 3 +-- packages/react-devtools-shared/src/backend/utils.js | 11 +++++------ packages/react-dom/src/client/ReactDOMSelect.js | 7 +++---- packages/react-dom/src/client/ReactDOMTextarea.js | 4 ++-- .../src/server/ReactDOMServerFormatConfig.js | 3 ++- .../react-dom/src/server/ReactPartialRenderer.js | 11 +++++------ packages/react-dom/src/test-utils/ReactTestUtils.js | 7 +++---- .../src/ReactNativeAttributePayload.js | 13 ++++++------- .../src/legacy-events/EventPluginUtils.js | 11 +++++------ .../src/legacy-events/accumulate.js | 5 ++--- .../src/legacy-events/accumulateInto.js | 7 +++---- packages/react-noop-renderer/src/createReactNoop.js | 9 ++++----- .../react-reconciler/src/ReactChildFiber.new.js | 3 ++- .../react-reconciler/src/ReactChildFiber.old.js | 3 ++- .../src/ReactFiberClassComponent.new.js | 2 +- .../src/ReactFiberClassComponent.old.js | 2 +- .../src/ReactFiberReconciler.new.js | 11 +++++------ .../src/ReactFiberReconciler.old.js | 11 +++++------ .../src/ReactFlightDOMRelayServerHostConfig.js | 3 +-- .../src/ReactFlightNativeRelayServerHostConfig.js | 4 ++-- packages/react-server/src/ReactFizzServer.js | 3 +-- packages/react-server/src/ReactFlightServer.js | 3 ++- packages/react/src/ReactChildren.js | 5 ++--- packages/react/src/ReactElementValidator.js | 9 ++++----- packages/react/src/jsx/ReactJSXElementValidator.js | 7 +++---- packages/shared/isArray.js | 12 ------------ 28 files changed, 77 insertions(+), 105 deletions(-) delete mode 100644 packages/shared/isArray.js diff --git a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js index 268b6873bd589..2c76ca5991f76 100644 --- a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js +++ b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js @@ -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]; diff --git a/packages/jest-react/src/JestReact.js b/packages/jest-react/src/JestReact.js index 1f26cbee3a328..57790797b966d 100644 --- a/packages/jest-react/src/JestReact.js +++ b/packages/jest-react/src/JestReact.js @@ -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) { diff --git a/packages/react-devtools-shared/src/backend/renderer.js b/packages/react-devtools-shared/src/backend/renderer.js index c61edb45daa65..050a4e709ab32 100644 --- a/packages/react-devtools-shared/src/backend/renderer.js +++ b/packages/react-devtools-shared/src/backend/renderer.js @@ -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') ); } diff --git a/packages/react-devtools-shared/src/backend/utils.js b/packages/react-devtools-shared/src/backend/utils.js index 593459d78f646..7a4ff6295ab99 100644 --- a/packages/react-devtools-shared/src/backend/utils.js +++ b/packages/react-devtools-shared/src/backend/utils.js @@ -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 { 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 { 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; diff --git a/packages/react-dom/src/client/ReactDOMSelect.js b/packages/react-dom/src/client/ReactDOMSelect.js index df336d4b92254..1efca61905b4a 100644 --- a/packages/react-dom/src/client/ReactDOMSelect.js +++ b/packages/react-dom/src/client/ReactDOMSelect.js @@ -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 must be a scalar ' + 'value if `multiple` is false.%s', diff --git a/packages/react-dom/src/client/ReactDOMTextarea.js b/packages/react-dom/src/client/ReactDOMTextarea.js index 6e8aed5cc43cd..24fb591fcd8af 100644 --- a/packages/react-dom/src/client/ReactDOMTextarea.js +++ b/packages/react-dom/src/client/ReactDOMTextarea.js @@ -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