* @param {?*} children Children tree container. * @param {!string} nameSoFar Name of the key path so far. * @param {!function} callback Callback to invoke with each child found. * @param {?*} traverseContext Used to pass information throughout the traversal * process. * @ret
(children, nameSoFar, callback, traverseContext)
| 2015 | * @return {!number} The number of children in this subtree. |
| 2016 | */ |
| 2017 | function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) { |
| 2018 | var type = typeof children === 'undefined' ? 'undefined' : _typeof(children); |
| 2019 | |
| 2020 | if (type === 'undefined' || type === 'boolean') { |
| 2021 | // All of the above are perceived as null. |
| 2022 | children = null; |
| 2023 | } |
| 2024 | |
| 2025 | if (children === null || type === 'string' || type === 'number' || |
| 2026 | // The following is inlined from ReactElement. This means we can optimize |
| 2027 | // some checks. React Fiber also inlines this logic for similar purposes. |
| 2028 | type === 'object' && children.$$typeof === REACT_ELEMENT_TYPE) { |
| 2029 | callback(traverseContext, children, |
| 2030 | // If it's the only child, treat the name as if it was wrapped in an array |
| 2031 | // so that it's consistent if the number of children grows. |
| 2032 | nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar); |
| 2033 | return 1; |
| 2034 | } |
| 2035 | |
| 2036 | var child; |
| 2037 | var nextName; |
| 2038 | var subtreeCount = 0; // Count of children found in the current subtree. |
| 2039 | var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR; |
| 2040 | |
| 2041 | if (Array.isArray(children)) { |
| 2042 | for (var i = 0; i < children.length; i++) { |
| 2043 | child = children[i]; |
| 2044 | nextName = nextNamePrefix + getComponentKey(child, i); |
| 2045 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext); |
| 2046 | } |
| 2047 | } else { |
| 2048 | var iteratorFn = ITERATOR_SYMBOL && children[ITERATOR_SYMBOL] || children[FAUX_ITERATOR_SYMBOL]; |
| 2049 | if (typeof iteratorFn === 'function') { |
| 2050 | { |
| 2051 | // Warn about using Maps as children |
| 2052 | if (iteratorFn === children.entries) { |
| 2053 | warning$1(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', getStackAddendum()); |
| 2054 | didWarnAboutMaps = true; |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | var iterator = iteratorFn.call(children); |
| 2059 | var step; |
| 2060 | var ii = 0; |
| 2061 | while (!(step = iterator.next()).done) { |
| 2062 | child = step.value; |
| 2063 | nextName = nextNamePrefix + getComponentKey(child, ii++); |
| 2064 | subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext); |
| 2065 | } |
| 2066 | } else if (type === 'object') { |
| 2067 | var addendum = ''; |
| 2068 | { |
| 2069 | addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + getStackAddendum(); |
| 2070 | } |
| 2071 | var childrenString = '' + children; |
| 2072 | invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum); |
| 2073 | } |
| 2074 | } |
no test coverage detected