[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 | var $concat = GetIntrinsic('%Array.prototype.concat%');
|
---|
| 5 |
|
---|
| 6 | var callBind = require('call-bind');
|
---|
| 7 |
|
---|
| 8 | var callBound = require('call-bind/callBound');
|
---|
| 9 | var $slice = callBound('Array.prototype.slice');
|
---|
| 10 |
|
---|
| 11 | var hasSymbols = require('has-symbols/shams')();
|
---|
| 12 | var isConcatSpreadable = hasSymbols && Symbol.isConcatSpreadable;
|
---|
| 13 |
|
---|
| 14 | /** @type {never[]} */ var empty = [];
|
---|
| 15 | var $concatApply = isConcatSpreadable ? callBind.apply($concat, empty) : null;
|
---|
| 16 |
|
---|
| 17 | // eslint-disable-next-line no-extra-parens
|
---|
| 18 | var isArray = isConcatSpreadable ? /** @type {(value: unknown) => value is unknown[]} */ (require('isarray')) : null;
|
---|
| 19 |
|
---|
| 20 | /** @type {import('.')} */
|
---|
| 21 | module.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);
|
---|