GeezerVison is showing github.com — Reland Remove redundant initial of isArray (#21188) · react/react@172e89b
File treeExpand file treeCollapse file tree Open diff view settings eslint-plugin-react-hooks/src react-devtools-shared/src/backend react-native-renderer/src react-server-dom-relay/src react-server-dom-webpack/src react-server-native-relay/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js +6-7Lines changed: 6 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -145,6 +145,8 @@ export default { | 145 | 145 | componentScope = currentScope; | 146 | 146 | } | 147 | 147 |
| | 148 | + const isArray = Array.isArray; | | 149 | + | 148 | 150 | // Next we'll define a few helpers that helps us | 149 | 151 | // tell if some values don't have to be declared as deps. | 150 | 152 |
| @@ -157,7 +159,7 @@ export default { | 157 | 159 | // ^^^ true for this reference | 158 | 160 | // False for everything else. | 159 | 161 | function isStableKnownHookValue(resolved) { | 160 | | - if (!Array.isArray(resolved.defs)) { | | 162 | + if (!isArray(resolved.defs)) { | 161 | 163 | return false; | 162 | 164 | } | 163 | 165 | const def = resolved.defs[0]; | @@ -226,7 +228,7 @@ export default { | 226 | 228 | if ( | 227 | 229 | id.type === 'ArrayPattern' && | 228 | 230 | id.elements.length === 2 && | 229 | | - Array.isArray(resolved.identifiers) | | 231 | + isArray(resolved.identifiers) | 230 | 232 | ) { | 231 | 233 | // Is second tuple value the same reference we're checking? | 232 | 234 | if (id.elements[1] === resolved.identifiers[0]) { | @@ -253,10 +255,7 @@ export default { | 253 | 255 | } | 254 | 256 | } | 255 | 257 | } else if (name === 'useTransition') { | 256 | | - if ( | 257 | | - id.type === 'ArrayPattern' && | 258 | | - Array.isArray(resolved.identifiers) | 259 | | - ) { | | 258 | + if (id.type === 'ArrayPattern' && isArray(resolved.identifiers)) { | 260 | 259 | // Is first tuple value the same reference we're checking? | 261 | 260 | if (id.elements[0] === resolved.identifiers[0]) { | 262 | 261 | // Setter is stable. | @@ -270,7 +269,7 @@ export default { | 270 | 269 |
| 271 | 270 | // Some are just functions that don't reference anything dynamic. | 272 | 271 | function isFunctionWithoutCapturedValues(resolved) { | 273 | | - if (!Array.isArray(resolved.defs)) { | | 272 | + if (!isArray(resolved.defs)) { | 274 | 273 | return false; | 275 | 274 | } | 276 | 275 | const def = resolved.defs[0]; | |
Collapse file Copy file name to clipboardExpand all lines: packages/jest-react/src/JestReact.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | import {REACT_ELEMENT_TYPE, REACT_FRAGMENT_TYPE} from 'shared/ReactSymbols'; | 9 | 9 |
| 10 | 10 | import invariant from 'shared/invariant'; | | 11 | +import isArray from 'shared/isArray'; | 11 | 12 |
| 12 | 13 | function captureAssertion(fn) { | 13 | 14 | // Trick to use a Jest matcher inside another Jest matcher. `fn` contains an | @@ -42,7 +43,7 @@ export function unstable_toMatchRenderedOutput(root, expectedJSX) { | 42 | 43 | let actualJSX; | 43 | 44 | if (actualJSON === null || typeof actualJSON === 'string') { | 44 | 45 | actualJSX = actualJSON; | 45 | | - } else if (Array.isArray(actualJSON)) { | | 46 | + } else if (isArray(actualJSON)) { | 46 | 47 | if (actualJSON.length === 0) { | 47 | 48 | actualJSX = null; | 48 | 49 | } else if (actualJSON.length === 1) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/backend/renderer.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -105,6 +105,7 @@ import type { | 105 | 105 | ElementType, | 106 | 106 | } from 'react-devtools-shared/src/types'; | 107 | 107 | import is from 'shared/objectIs'; | | 108 | +import isArray from 'shared/isArray'; | 108 | 109 |
| 109 | 110 | type getDisplayNameForFiberType = (fiber: Fiber) => string | null; | 110 | 111 | type getTypeSymbolType = (type: any) => Symbol | number; | @@ -1137,7 +1138,7 @@ export function attach( | 1137 | 1138 | memoizedState.hasOwnProperty('create') && | 1138 | 1139 | memoizedState.hasOwnProperty('destroy') && | 1139 | 1140 | memoizedState.hasOwnProperty('deps') && | 1140 | | - (memoizedState.deps === null || Array.isArray(memoizedState.deps)) && | | 1141 | + (memoizedState.deps === null || isArray(memoizedState.deps)) && | 1141 | 1142 | memoizedState.hasOwnProperty('next') | 1142 | 1143 | ); | 1143 | 1144 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/backend/utils.js +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 9 | 9 |
| 10 | 10 | import {copy} from 'clipboard-js'; | 11 | 11 | import {dehydrate} from '../hydration'; | | 12 | +import isArray from 'shared/isArray'; | 12 | 13 |
| 13 | 14 | import type {DehydratedData} from 'react-devtools-shared/src/devtools/views/Components/types'; | 14 | 15 |
| @@ -61,9 +62,9 @@ export function copyWithDelete( | 61 | 62 | index: number = 0, | 62 | 63 | ): Object | Array<any> { | 63 | 64 | const key = path[index]; | 64 | | - const updated = Array.isArray(obj) ? obj.slice() : {...obj}; | | 65 | + const updated = isArray(obj) ? obj.slice() : {...obj}; | 65 | 66 | if (index + 1 === path.length) { | 66 | | - if (Array.isArray(updated)) { | | 67 | + if (isArray(updated)) { | 67 | 68 | updated.splice(((key: any): number), 1); | 68 | 69 | } else { | 69 | 70 | delete updated[key]; | @@ -84,12 +85,12 @@ export function copyWithRename( | 84 | 85 | index: number = 0, | 85 | 86 | ): Object | Array<any> { | 86 | 87 | const oldKey = oldPath[index]; | 87 | | - const updated = Array.isArray(obj) ? obj.slice() : {...obj}; | | 88 | + const updated = isArray(obj) ? obj.slice() : {...obj}; | 88 | 89 | if (index + 1 === oldPath.length) { | 89 | 90 | const newKey = newPath[index]; | 90 | 91 | // $FlowFixMe number or string is fine here | 91 | 92 | updated[newKey] = updated[oldKey]; | 92 | | - if (Array.isArray(updated)) { | | 93 | + if (isArray(updated)) { | 93 | 94 | updated.splice(((oldKey: any): number), 1); | 94 | 95 | } else { | 95 | 96 | delete updated[oldKey]; | @@ -111,7 +112,7 @@ export function copyWithSet( | 111 | 112 | return value; | 112 | 113 | } | 113 | 114 | const key = path[index]; | 114 | | - const updated = Array.isArray(obj) ? obj.slice() : {...obj}; | | 115 | + const updated = isArray(obj) ? obj.slice() : {...obj}; | 115 | 116 | // $FlowFixMe number or string is fine here | 116 | 117 | updated[key] = copyWithSet(obj[key], path, value, index + 1); | 117 | 118 | return updated; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMSelect.js +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCur | 12 | 12 |
| 13 | 13 | import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes'; | 14 | 14 | import {getToStringValue, toString} from './ToStringValue'; | | 15 | +import isArray from 'shared/isArray'; | 15 | 16 |
| 16 | 17 | let didWarnValueDefaultValue; | 17 | 18 |
| @@ -45,15 +46,15 @@ function checkSelectPropTypes(props) { | 45 | 46 | if (props[propName] == null) { | 46 | 47 | continue; | 47 | 48 | } | 48 | | - const isArray = Array.isArray(props[propName]); | 49 | | - if (props.multiple && !isArray) { | | 49 | + const propNameIsArray = isArray(props[propName]); | | 50 | + if (props.multiple && !propNameIsArray) { | 50 | 51 | console.error( | 51 | 52 | 'The `%s` prop supplied to <select> must be an array if ' + | 52 | 53 | '`multiple` is true.%s', | 53 | 54 | propName, | 54 | 55 | getDeclarationErrorAddendum(), | 55 | 56 | ); | 56 | | - } else if (!props.multiple && isArray) { | | 57 | + } else if (!props.multiple && propNameIsArray) { | 57 | 58 | console.error( | 58 | 59 | 'The `%s` prop supplied to <select> must be a scalar ' + | 59 | 60 | 'value if `multiple` is false.%s', | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/client/ReactDOMTextarea.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | */ | 9 | 9 |
| 10 | 10 | import invariant from 'shared/invariant'; | | 11 | +import isArray from 'shared/isArray'; | 11 | 12 |
| 12 | 13 | import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes'; | 13 | 14 | import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCurrentFiber'; | 14 | 15 | import {getToStringValue, toString} from './ToStringValue'; | 15 | 16 | import type {ToStringValue} from './ToStringValue'; | 16 | | - | 17 | 17 | import {disableTextareaChildren} from 'shared/ReactFeatureFlags'; | 18 | 18 |
| 19 | 19 | let didWarnValDefaultVal = false; | @@ -100,7 +100,7 @@ export function initWrapperState(element: Element, props: Object) { | 100 | 100 | defaultValue == null, | 101 | 101 | 'If you supply `defaultValue` on a <textarea>, do not pass children.', | 102 | 102 | ); | 103 | | - if (Array.isArray(children)) { | | 103 | + if (isArray(children)) { | 104 | 104 | invariant( | 105 | 105 | children.length <= 1, | 106 | 106 | '<textarea> can only have at most one child.', | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactDOMServerFormatConfig.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,8 +46,7 @@ import hyphenateStyleName from '../shared/hyphenateStyleName'; | 46 | 46 | import invariant from 'shared/invariant'; | 47 | 47 | import hasOwnProperty from 'shared/hasOwnProperty'; | 48 | 48 | import sanitizeURL from '../shared/sanitizeURL'; | 49 | | - | 50 | | -const isArray = Array.isArray; | | 49 | +import isArray from 'shared/isArray'; | 51 | 50 |
| 52 | 51 | // Per response, global state that is not contextual to the rendering subtree. | 53 | 52 | export type ResponseState = { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactPartialRenderer.js +6-5Lines changed: 6 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,6 +14,7 @@ import type {ReactProvider, ReactContext} from 'shared/ReactTypes'; | 14 | 14 |
| 15 | 15 | import * as React from 'react'; | 16 | 16 | import invariant from 'shared/invariant'; | | 17 | +import isArray from 'shared/isArray'; | 17 | 18 | import getComponentNameFromType from 'shared/getComponentNameFromType'; | 18 | 19 | import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame'; | 19 | 20 | import ReactSharedInternals from 'shared/ReactSharedInternals'; | @@ -1438,7 +1439,7 @@ class ReactDOMServerRenderer { | 1438 | 1439 | defaultValue == null, | 1439 | 1440 | 'If you supply `defaultValue` on a <textarea>, do not pass children.', | 1440 | 1441 | ); | 1441 | | - if (Array.isArray(textareaChildren)) { | | 1442 | + if (isArray(textareaChildren)) { | 1442 | 1443 | invariant( | 1443 | 1444 | textareaChildren.length <= 1, | 1444 | 1445 | '<textarea> can only have at most one child.', | @@ -1467,14 +1468,14 @@ class ReactDOMServerRenderer { | 1467 | 1468 | if (props[propName] == null) { | 1468 | 1469 | continue; | 1469 | 1470 | } | 1470 | | - const isArray = Array.isArray(props[propName]); | 1471 | | - if (props.multiple && !isArray) { | | 1471 | + const propNameIsArray = isArray(props[propName]); | | 1472 | + if (props.multiple && !propNameIsArray) { | 1472 | 1473 | console.error( | 1473 | 1474 | 'The `%s` prop supplied to <select> must be an array if ' + | 1474 | 1475 | '`multiple` is true.', | 1475 | 1476 | propName, | 1476 | 1477 | ); | 1477 | | - } else if (!props.multiple && isArray) { | | 1478 | + } else if (!props.multiple && propNameIsArray) { | 1478 | 1479 | console.error( | 1479 | 1480 | 'The `%s` prop supplied to <select> must be a scalar ' + | 1480 | 1481 | 'value if `multiple` is false.', | @@ -1515,7 +1516,7 @@ class ReactDOMServerRenderer { | 1515 | 1516 | value = optionChildren; | 1516 | 1517 | } | 1517 | 1518 | selected = false; | 1518 | | - if (Array.isArray(selectValue)) { | | 1519 | + if (isArray(selectValue)) { | 1519 | 1520 | // multiple | 1520 | 1521 | for (let j = 0; j < selectValue.length; j++) { | 1521 | 1522 | if ('' + selectValue[j] === value) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/test-utils/ReactTestUtils.js +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,6 +24,7 @@ import { | 24 | 24 | rethrowCaughtError, | 25 | 25 | invokeGuardedCallbackAndCatchFirstError, | 26 | 26 | } from 'shared/ReactErrorUtils'; | | 27 | +import isArray from 'shared/isArray'; | 27 | 28 |
| 28 | 29 | // Keep in sync with ReactDOM.js, and ReactTestUtilsAct.js: | 29 | 30 | const EventInternals = | @@ -97,7 +98,7 @@ function validateClassInstance(inst, methodName) { | 97 | 98 | } | 98 | 99 | let received; | 99 | 100 | const stringified = '' + inst; | 100 | | - if (Array.isArray(inst)) { | | 101 | + if (isArray(inst)) { | 101 | 102 | received = 'an array'; | 102 | 103 | } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) { | 103 | 104 | received = 'a DOM node'; | @@ -197,7 +198,7 @@ function scryRenderedDOMComponentsWithClass(root, classNames) { | 197 | 198 | } | 198 | 199 | const classList = className.split(/\s+/); | 199 | 200 |
| 200 | | - if (!Array.isArray(classNames)) { | | 201 | + if (!isArray(classNames)) { | 201 | 202 | invariant( | 202 | 203 | classNames !== undefined, | 203 | 204 | 'TestUtils.scryRenderedDOMComponentsWithClass expects a ' + | @@ -365,7 +366,7 @@ function executeDispatch(event, listener, inst) { | 365 | 366 | function executeDispatchesInOrder(event) { | 366 | 367 | const dispatchListeners = event._dispatchListeners; | 367 | 368 | const dispatchInstances = event._dispatchInstances; | 368 | | - if (Array.isArray(dispatchListeners)) { | | 369 | + if (isArray(dispatchListeners)) { | 369 | 370 | for (let i = 0; i < dispatchListeners.length; i++) { | 370 | 371 | if (event.isPropagationStopped()) { | 371 | 372 | break; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeAttributePayload.js +7-6Lines changed: 7 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import { | 12 | 12 | deepDiffer, | 13 | 13 | flattenStyle, | 14 | 14 | } from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; | | 15 | +import isArray from 'shared/isArray'; | 15 | 16 |
| 16 | 17 | import type {AttributeConfiguration} from './ReactNativeTypes'; | 17 | 18 |
| @@ -51,7 +52,7 @@ function restoreDeletedValuesInNestedArray( | 51 | 52 | node: NestedNode, | 52 | 53 | validAttributes: AttributeConfiguration, | 53 | 54 | ) { | 54 | | - if (Array.isArray(node)) { | | 55 | + if (isArray(node)) { | 55 | 56 | let i = node.length; | 56 | 57 | while (i-- && removedKeyCount > 0) { | 57 | 58 | restoreDeletedValuesInNestedArray( | @@ -163,12 +164,12 @@ function diffNestedProperty( | 163 | 164 | return updatePayload; | 164 | 165 | } | 165 | 166 |
| 166 | | - if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) { | | 167 | + if (!isArray(prevProp) && !isArray(nextProp)) { | 167 | 168 | // Both are leaves, we can diff the leaves. | 168 | 169 | return diffProperties(updatePayload, prevProp, nextProp, validAttributes); | 169 | 170 | } | 170 | 171 |
| 171 | | - if (Array.isArray(prevProp) && Array.isArray(nextProp)) { | | 172 | + if (isArray(prevProp) && isArray(nextProp)) { | 172 | 173 | // Both are arrays, we can diff the arrays. | 173 | 174 | return diffNestedArrayProperty( | 174 | 175 | updatePayload, | @@ -178,7 +179,7 @@ function diffNestedProperty( | 178 | 179 | ); | 179 | 180 | } | 180 | 181 |
| 181 | | - if (Array.isArray(prevProp)) { | | 182 | + if (isArray(prevProp)) { | 182 | 183 | return diffProperties( | 183 | 184 | updatePayload, | 184 | 185 | // $FlowFixMe - We know that this is always an object when the input is. | @@ -212,7 +213,7 @@ function addNestedProperty( | 212 | 213 | return updatePayload; | 213 | 214 | } | 214 | 215 |
| 215 | | - if (!Array.isArray(nextProp)) { | | 216 | + if (!isArray(nextProp)) { | 216 | 217 | // Add each property of the leaf. | 217 | 218 | return addProperties(updatePayload, nextProp, validAttributes); | 218 | 219 | } | @@ -242,7 +243,7 @@ function clearNestedProperty( | 242 | 243 | return updatePayload; | 243 | 244 | } | 244 | 245 |
| 245 | | - if (!Array.isArray(prevProp)) { | | 246 | + if (!isArray(prevProp)) { | 246 | 247 | // Add each property of the leaf. | 247 | 248 | return clearProperties(updatePayload, prevProp, validAttributes); | 248 | 249 | } | |
|