* 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)
| 2286 | */ |
| 2287 | |
| 2288 | function accumulateInto(current, next) { |
| 2289 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 2290 | |
| 2291 | if (current == null) { |
| 2292 | return next; |
| 2293 | } |
| 2294 | |
| 2295 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 2296 | // certain that x is an Array (x could be a string with concat method). |
| 2297 | if (Array.isArray(current)) { |
| 2298 | if (Array.isArray(next)) { |
| 2299 | current.push.apply(current, next); |
| 2300 | return current; |
| 2301 | } |
| 2302 | current.push(next); |
| 2303 | return current; |
| 2304 | } |
| 2305 | |
| 2306 | if (Array.isArray(next)) { |
| 2307 | // A bit too dangerous to mutate `next`. |
| 2308 | return [current].concat(next); |
| 2309 | } |
| 2310 | |
| 2311 | return [current, next]; |
| 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected