( task: Task, iterable: Iterable<any>, childIndex: number, iterator: Iterator<any>, iteratorFn: () => ?Iterator<any>, )
| 3180 | } |
| 3181 | |
| 3182 | function validateIterable( |
| 3183 | task: Task, |
| 3184 | iterable: Iterable<any>, |
| 3185 | childIndex: number, |
| 3186 | iterator: Iterator<any>, |
| 3187 | iteratorFn: () => ?Iterator<any>, |
| 3188 | ): void { |
| 3189 | if (__DEV__) { |
| 3190 | if (iterator === iterable) { |
| 3191 | // We don't support rendering Generators as props because it's a mutation. |
| 3192 | // See https://github.com/facebook/react/issues/12995 |
| 3193 | // We do support generators if they were created by a GeneratorFunction component |
| 3194 | // as its direct child since we can recreate those by rerendering the component |
| 3195 | // as needed. |
| 3196 | const isGeneratorComponent = |
| 3197 | childIndex === -1 && // Only the root child is valid |
| 3198 | task.componentStack !== null && |
| 3199 | typeof task.componentStack.type === 'function' && // FunctionComponent |
| 3200 | // $FlowFixMe[method-unbinding] |
| 3201 | Object.prototype.toString.call(task.componentStack.type) === |
| 3202 | '[object GeneratorFunction]' && |
| 3203 | // $FlowFixMe[method-unbinding] |
| 3204 | Object.prototype.toString.call(iterator) === '[object Generator]'; |
| 3205 | if (!isGeneratorComponent) { |
| 3206 | if (!didWarnAboutGenerators) { |
| 3207 | console.error( |
| 3208 | 'Using Iterators as children is unsupported and will likely yield ' + |
| 3209 | 'unexpected results because enumerating a generator mutates it. ' + |
| 3210 | 'You may convert it to an array with `Array.from()` or the ' + |
| 3211 | '`[...spread]` operator before rendering. You can also use an ' + |
| 3212 | 'Iterable that can iterate multiple times over the same items.', |
| 3213 | ); |
| 3214 | } |
| 3215 | didWarnAboutGenerators = true; |
| 3216 | } |
| 3217 | } else if ((iterable: any).entries === iteratorFn) { |
| 3218 | // Warn about using Maps as children |
| 3219 | if (!didWarnAboutMaps) { |
| 3220 | console.error( |
| 3221 | 'Using Maps as children is not supported. ' + |
| 3222 | 'Use an array of keyed ReactElements instead.', |
| 3223 | ); |
| 3224 | didWarnAboutMaps = true; |
| 3225 | } |
| 3226 | } |
| 3227 | } |
| 3228 | } |
| 3229 | |
| 3230 | function validateAsyncIterable( |
| 3231 | task: Task, |
no test coverage detected