@@ -13,32 +13,31 @@ declare global {
1313
1414( globalThis as Record < string , unknown > ) . Iterator ??= { } ;
1515
16- ( globalThis as Record < string , unknown > ) . Iterator = {
17- from < T > (
16+ ( ( globalThis as Record < string , unknown > ) . Iterator as { from : unknown } ) . from ??=
17+ function < T > (
1818 object : Iterator < T > | Iterable < T > | { next ( ) : IteratorResult < T > } ,
1919 ) : IterableIterator < T > {
20- if ( typeof ( object as Iterable < T > ) [ Symbol . iterator ] === "function" ) {
21- const iterable = object as Iterable < T > ;
22- const iterator = iterable [ Symbol . iterator ] ( ) ;
23- return iteratorPrototype . toIterable . call ( iterator ) as IterableIterator < T > ;
20+ const toIterable = iteratorPrototype . toIterable as (
21+ this : Iterator < T > ,
22+ ) => IterableIterator < T > ;
23+
24+ const iteratorFactory = ( object as Iterable < T > ) [ Symbol . iterator ] ;
25+ if ( typeof iteratorFactory === "function" ) {
26+ return toIterable . call ( iteratorFactory . call ( object ) ) ;
2427 }
2528
26- if ( Object . prototype . isPrototypeOf . call ( iteratorPrototype , object ) ) {
27- return iteratorPrototype . toIterable . call (
28- object as Iterator < T > ,
29- ) as IterableIterator < T > ;
29+ // eslint-disable-next-line no-prototype-builtins
30+ if ( iteratorPrototype . isPrototypeOf ( object ) ) {
31+ return toIterable . call ( object as Iterator < T > ) ;
3032 }
3133
32- if ( typeof ( object as { next ( ) : IteratorResult < T > } ) . next === "function" ) {
33- return ( function * ( ) : IterableIterator < T > {
34- yield * iteratorPrototype . toIterable . call (
35- object as Iterator < T > ,
36- ) as Iterable < T > ;
34+ if ( typeof ( object as Record < string , unknown > ) . next === "function" ) {
35+ return ( function * ( ) {
36+ yield * toIterable . call ( object as Iterator < T > ) ;
3737 } ) ( ) ;
3838 }
3939
4040 throw new TypeError (
4141 "Object is not an iterator, iterable, or an object with a next method" ,
4242 ) ;
43- } ,
44- } ;
43+ } ;
0 commit comments