55/* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
66
77import define from "./regeneratorDefine.ts" ;
8- import defineIteratorMethods from "./regeneratorDefineIM.ts" ;
9- import values from "./regeneratorValues.ts" ;
108
119const enum GenState {
1210 SuspendedStart ,
13- SuspendedYield ,
11+ SuspendedYieldOrCompleted ,
1412 Executing ,
15- Completed ,
1613}
1714
1815const enum OperatorType {
@@ -59,8 +56,6 @@ type Context = {
5956export default function /* @no -mangle */ _regenerator ( ) {
6057 /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
6158
62- var Op = Object . prototype ;
63- var hasOwn = Op . hasOwnProperty ;
6459 var undefined : undefined ; // More compressible than void 0.
6560 var $Symbol =
6661 typeof Symbol === "function" ? Symbol : ( { } as SymbolConstructor ) ;
@@ -106,24 +101,17 @@ export default function /* @no-mangle */ _regenerator() {
106101 /* @no -mangle */
107102 function GeneratorFunctionPrototype ( ) { }
108103
109- // This is a polyfill for %IteratorPrototype% for environments that
110- // don't natively support it.
111- var IteratorPrototype = { } ;
112- define ( IteratorPrototype , iteratorSymbol , function ( this : unknown ) {
113- return this ;
114- } ) ;
115-
116- var getProto = Object . getPrototypeOf ;
117- var NativeIteratorPrototype = getProto && getProto ( getProto ( values ( [ ] ) ) ) ;
118- if (
119- NativeIteratorPrototype &&
120- NativeIteratorPrototype !== Op &&
121- hasOwn . call ( NativeIteratorPrototype , iteratorSymbol )
122- ) {
123- // This environment has a native %IteratorPrototype%; use it instead
124- // of the polyfill.
125- IteratorPrototype = NativeIteratorPrototype ;
126- }
104+ _ = Object . getPrototypeOf ;
105+ var IteratorPrototype = [ ] [ iteratorSymbol as typeof Symbol . iterator ]
106+ ? // This environment has a native %IteratorPrototype%; use it instead
107+ // of the polyfill.
108+ _ ( _ ( [ ] [ iteratorSymbol as typeof Symbol . iterator ] ( ) ) )
109+ : // This is a polyfill for %IteratorPrototype% for environments that
110+ // don't natively support it.
111+ ( define ( ( _ = { } ) , iteratorSymbol , function ( this : unknown ) {
112+ return this ;
113+ } ) ,
114+ _ ) ;
127115
128116 var Gp =
129117 ( GeneratorFunctionPrototype . prototype =
@@ -137,7 +125,7 @@ export default function /* @no-mangle */ _regenerator() {
137125
138126 // Define Generator.prototype.{next,throw,return} in terms of the
139127 // unified ._invoke helper method.
140- defineIteratorMethods ( Gp ) ;
128+ define ( Gp ) ;
141129
142130 define ( Gp , toStringTagSymbol , "Generator" ) ;
143131
@@ -178,7 +166,7 @@ export default function /* @no-mangle */ _regenerator() {
178166 _method : OperatorType . Next | OperatorType . Throw | OperatorType . Return ,
179167 _arg : any ,
180168 ) {
181- if ( state === GenState . Executing ) {
169+ if ( state > 1 /* Executing */ ) {
182170 throw TypeError ( "Generator is already running" ) ;
183171 } else if ( done ) {
184172 if ( _method === OperatorType . Throw ) {
@@ -189,19 +177,20 @@ export default function /* @no-mangle */ _regenerator() {
189177 method = _method ;
190178 arg = _arg ;
191179
192- while ( ! done || ( _ = undefined ) ) {
180+ while ( ( _ = method < 2 /* Next | Throw */ ? undefined : arg ) || ! done ) {
193181 if ( ! delegateIterator ) {
194- if ( ! method /* Return */ ) {
182+ if ( ! method /* Next */ ) {
195183 ctx . v = arg ;
196184 } else if ( method < 3 /* Throw | Return */ ) {
197185 if ( method > 1 /* Return */ ) ctx . n = ContextNext . End ;
198186 Context_dispatchExceptionOrFinishOrAbrupt ( method , arg ) ;
199187 } else {
200- // Jump
188+ /* Jump */
201189 ctx . n = arg ;
202190 }
203191 }
204192 try {
193+ state = GenState . Executing ;
205194 if ( delegateIterator ) {
206195 // Call delegate.iterator[context.method](context.arg) and handle the result
207196
@@ -255,27 +244,22 @@ export default function /* @no-mangle */ _regenerator() {
255244 // yield* loop.
256245 delegateIterator = undefined ;
257246 } else {
258- state = GenState . Executing ;
259-
260247 if ( ( done = ctx . n < 0 ) /* End */ ) {
261248 _ = arg ;
262249 } else {
263250 _ = innerFn . call ( self , ctx ) ;
264251 }
265252
266- // If an exception is thrown from innerFn, we leave state ===
267- // GenStateExecuting and loop back for another invocation.
268- state = done ? GenState . Completed : GenState . SuspendedYield ;
269-
270253 if ( _ !== ContinueSentinel ) {
271254 break ;
272255 }
273256 }
274257 } catch ( e ) {
275- state = GenState . Completed ;
276258 delegateIterator = undefined ;
277259 method = OperatorType . Throw ;
278260 arg = e ;
261+ } finally {
262+ state = GenState . SuspendedYieldOrCompleted ;
279263 }
280264 }
281265 // Be forgiving, per GeneratorResume behavior specified since ES2015:
@@ -302,13 +286,16 @@ export default function /* @no-mangle */ _regenerator() {
302286
303287 v : undefined ,
304288
289+ // abrupt
305290 a : Context_dispatchExceptionOrFinishOrAbrupt ,
291+ // finish
306292 f : Context_dispatchExceptionOrFinishOrAbrupt . bind (
307293 undefined ,
308294 OperatorType . Finish ,
309295 ) ,
296+ // delegateYield
310297 d : function ( iterable : any , nextLoc : number ) {
311- delegateIterator = values ( iterable ) ;
298+ delegateIterator = iterable ;
312299
313300 // Deliberately forget the last sent value so that we don't
314301 // accidentally pass it on to the delegate.
@@ -328,7 +315,10 @@ export default function /* @no-mangle */ _regenerator() {
328315 arg = _arg ;
329316 for (
330317 _ = 0 ;
331- ! done && state && ! shouldReturn && _ < tryEntries . length ;
318+ ! done &&
319+ state /* state !== SuspendedStart */ &&
320+ ! shouldReturn &&
321+ _ < tryEntries . length ;
332322 _ ++
333323 ) {
334324 var entry = tryEntries [ _ ] ;
0 commit comments