* Accumulates items that must not be null or undefined into the first one. This * is used to conserve memory by avoiding array allocations, and thus sacrifices * API cleanness. Since `current` can be null before being passed in and not * null after this function, make sure to assign it back to `c
(current, next)
| 2331 | */ |
| 2332 | |
| 2333 | function accumulateInto(current, next) { |
| 2334 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 2335 | |
| 2336 | if (current == null) { |
| 2337 | return next; |
| 2338 | } |
| 2339 | |
| 2340 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 2341 | // certain that x is an Array (x could be a string with concat method). |
| 2342 | if (Array.isArray(current)) { |
| 2343 | if (Array.isArray(next)) { |
| 2344 | current.push.apply(current, next); |
| 2345 | return current; |
| 2346 | } |
| 2347 | current.push(next); |
| 2348 | return current; |
| 2349 | } |
| 2350 | |
| 2351 | if (Array.isArray(next)) { |
| 2352 | // A bit too dangerous to mutate `next`. |
| 2353 | return [current].concat(next); |
| 2354 | } |
| 2355 | |
| 2356 | return [current, next]; |
| 2357 | } |
| 2358 | |
| 2359 | /** |
| 2360 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected