massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / flatten-into-array.js
1 'use strict';
2 var global = require('../internals/global');
3 var isArray = require('../internals/is-array');
4 var lengthOfArrayLike = require('../internals/length-of-array-like');
5 var bind = require('../internals/function-bind-context');
6
7 var TypeError = global.TypeError;
8
9 // `FlattenIntoArray` abstract operation
10 // https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
11 var flattenIntoArray = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
12   var targetIndex = start;
13   var sourceIndex = 0;
14   var mapFn = mapper ? bind(mapper, thisArg) : false;
15   var element, elementLen;
16
17   while (sourceIndex < sourceLen) {
18     if (sourceIndex in source) {
19       element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
20
21       if (depth > 0 && isArray(element)) {
22         elementLen = lengthOfArrayLike(element);
23         targetIndex = flattenIntoArray(target, original, element, elementLen, targetIndex, depth - 1) - 1;
24       } else {
25         if (targetIndex >= 0x1FFFFFFFFFFFFF) throw TypeError('Exceed the acceptable array length');
26         target[targetIndex] = element;
27       }
28
29       targetIndex++;
30     }
31     sourceIndex++;
32   }
33   return targetIndex;
34 };
35
36 module.exports = flattenIntoArray;