( children: ?ReactNodeList, array: Array<React$Node>, escapedPrefix: string, nameSoFar: string, callback: (?React$Node) => ?ReactNodeList, )
| 144 | } |
| 145 | |
| 146 | function mapIntoArray( |
| 147 | children: ?ReactNodeList, |
| 148 | array: Array<React$Node>, |
| 149 | escapedPrefix: string, |
| 150 | nameSoFar: string, |
| 151 | callback: (?React$Node) => ?ReactNodeList, |
| 152 | ): number { |
| 153 | const type = typeof children; |
| 154 | |
| 155 | if (type === class="st">'undefined' || type === class="st">'boolean') { |
| 156 | class="cm">// All of the above are perceived as null. |
| 157 | children = null; |
| 158 | } |
| 159 | |
| 160 | let invokeCallback = false; |
| 161 | |
| 162 | if (children === null) { |
| 163 | invokeCallback = true; |
| 164 | } else { |
| 165 | switch (type) { |
| 166 | case class="st">'bigint': |
| 167 | case class="st">'string': |
| 168 | case class="st">'number': |
| 169 | invokeCallback = true; |
| 170 | break; |
| 171 | case class="st">'object': |
| 172 | switch ((children: any).$$typeof) { |
| 173 | case REACT_ELEMENT_TYPE: |
| 174 | case REACT_PORTAL_TYPE: |
| 175 | invokeCallback = true; |
| 176 | break; |
| 177 | case REACT_LAZY_TYPE: |
| 178 | const payload = (children: any)._payload; |
| 179 | const init = (children: any)._init; |
| 180 | return mapIntoArray( |
| 181 | init(payload), |
| 182 | array, |
| 183 | escapedPrefix, |
| 184 | nameSoFar, |
| 185 | callback, |
| 186 | ); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | if (invokeCallback) { |
| 192 | const child = children; |
| 193 | let mappedChild = callback(child); |
| 194 | class="cm">// If it's the only child, treat the name as if it was wrapped in an array |
| 195 | class="cm">// so that it's consistent if the number of children grows: |
| 196 | const childKey = |
| 197 | nameSoFar === class="st">'' ? SEPARATOR + getElementKey(child, 0) : nameSoFar; |
| 198 | if (isArray(mappedChild)) { |
| 199 | let escapedChildKey = class="st">''; |
| 200 | if (childKey != null) { |
| 201 | escapedChildKey = escapeUserProvidedKey(childKey) + class="st">'/'; |
| 202 | } |
| 203 | mapIntoArray(mappedChild, array, escapedChildKey, class="st">'', c => c); |
no test coverage detected