import { HAS_SET, s } from "../constants.js"; import setup from "./proto.js"; import { isIterable } from "../../../util.js"; import { _classCallCheck } from "../../../../shared.js"; function generateSet(fs: FakeSet, it: Iterable | undefined) { if (it == null) return; if (!isIterable(it)) throw new Error("value:" + String(it) + " is not iterable"); const len = (it as Array).length; for (let i = 0; i < len; i++) { const k = (it as Array)[i]; fs.add(k); } } interface FakeSet { add(value: T): this; clear(): void; delete(value: T): boolean; forEach( callbackfn: (value: T, value2: T, set: FakeSet) => void, thisArg?: any ): void; has(value: T): boolean; readonly size: number; [s]: Array; [Symbol.toStringTag]: string; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[T, T]>; keys(): IterableIterator; values(): IterableIterator; } export interface FakeSetConstructor { new (values?: ReadonlyArray | null): FakeSet; readonly prototype: FakeSet; [Symbol.species]: FakeSetConstructor; } const FakeSet = (function FakeSet( this: FakeSet, iterable?: Iterable, forceUseCustomImplementation?: boolean ) { _classCallCheck(this, FakeSet); if (!forceUseCustomImplementation && HAS_SET) return new Set(iterable); this[s] = []; generateSet(this, iterable); } as any) as FakeSetConstructor; setup(FakeSet); FakeSet[Symbol.species] = FakeSet; export default FakeSet;