source: imaps-frontend/node_modules/safe-array-concat/index.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var $concat = GetIntrinsic('%Array.prototype.concat%');
5
6var callBind = require('call-bind');
7
8var callBound = require('call-bind/callBound');
9var $slice = callBound('Array.prototype.slice');
10
11var hasSymbols = require('has-symbols/shams')();
12var isConcatSpreadable = hasSymbols && Symbol.isConcatSpreadable;
13
14/** @type {never[]} */ var empty = [];
15var $concatApply = isConcatSpreadable ? callBind.apply($concat, empty) : null;
16
17// eslint-disable-next-line no-extra-parens
18var isArray = isConcatSpreadable ? /** @type {(value: unknown) => value is unknown[]} */ (require('isarray')) : null;
19
20/** @type {import('.')} */
21module.exports = isConcatSpreadable
22 // eslint-disable-next-line no-unused-vars
23 ? function safeArrayConcat(item) {
24 for (var i = 0; i < arguments.length; i += 1) {
25 /** @type {typeof item} */ var arg = arguments[i];
26 // @ts-expect-error ts(2538) see https://github.com/microsoft/TypeScript/issues/9998#issuecomment-1890787975; works if `const`
27 if (arg && typeof arg === 'object' && typeof arg[isConcatSpreadable] === 'boolean') {
28 // @ts-expect-error ts(7015) TS doesn't yet support Symbol indexing
29 if (!empty[isConcatSpreadable]) {
30 // @ts-expect-error ts(7015) TS doesn't yet support Symbol indexing
31 empty[isConcatSpreadable] = true;
32 }
33 // @ts-expect-error ts(2721) ts(18047) not sure why TS can't figure out this can't be null
34 var arr = isArray(arg) ? $slice(arg) : [arg];
35 // @ts-expect-error ts(7015) TS can't handle expandos on an array
36 arr[isConcatSpreadable] = true; // shadow the property. TODO: use [[Define]]
37 arguments[i] = arr;
38 }
39 }
40 // @ts-expect-error ts(2345) https://github.com/microsoft/TypeScript/issues/57164 TS doesn't understand that apply can take an arguments object
41 return $concatApply(arguments);
42 }
43 : callBind($concat, empty);
Note: See TracBrowser for help on using the repository browser.