* 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)
| 1517 | */ |
| 1518 | |
| 1519 | function accumulateInto(current, next) { |
| 1520 | !(next != null) ? invariant(false, 'accumulateInto(...): Accumulated items must not be null or undefined.') : void 0; |
| 1521 | |
| 1522 | if (current == null) { |
| 1523 | return next; |
| 1524 | } |
| 1525 | |
| 1526 | // Both are not empty. Warning: Never call x.concat(y) when you are not |
| 1527 | // certain that x is an Array (x could be a string with concat method). |
| 1528 | if (Array.isArray(current)) { |
| 1529 | if (Array.isArray(next)) { |
| 1530 | current.push.apply(current, next); |
| 1531 | return current; |
| 1532 | } |
| 1533 | current.push(next); |
| 1534 | return current; |
| 1535 | } |
| 1536 | |
| 1537 | if (Array.isArray(next)) { |
| 1538 | // A bit too dangerous to mutate `next`. |
| 1539 | return [current].concat(next); |
| 1540 | } |
| 1541 | |
| 1542 | return [current, next]; |
| 1543 | } |
| 1544 | |
| 1545 | /** |
| 1546 | * @param {array} arr an "accumulation" of items which is either an Array or |
no test coverage detected