* 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)
| 2193 | */ |
| 2194 | |
| 2195 | function accumulateInto(current, next) { |
| 2196 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 2197 | |
| 2198 | if (current == null) { |
| 2199 | return next; |
| 2200 | } |
| 2201 | |
| 2202 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 2203 | // certain that x is an Array (x could be a string with concat method). |
| 2204 | if (Array.isArray(current)) { |
| 2205 | if (Array.isArray(next)) { |
| 2206 | current.push.apply(current, next); |
| 2207 | return current; |
| 2208 | } |
| 2209 | current.push(next); |
| 2210 | return current; |
| 2211 | } |
| 2212 | |
| 2213 | if (Array.isArray(next)) { |
| 2214 | // A bit too dangerous to mutate `next`. |
| 2215 | return [current].concat(next); |
| 2216 | } |
| 2217 | |
| 2218 | return [current, next]; |
| 2219 | } |
| 2220 | |
| 2221 | /** |
| 2222 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected