Debian Codegraph @

packages/babel-helpers/src/helpers/regeneratorRuntime.js

raw symbols SCIP
1 /* @minVersion 7.18.0 */
2 /*
3 * This file is auto-generated! Do not modify it directly.
4 * To re-generate, update the regenerator-runtime dependency of
5 * @babel/helpers and run 'yarn gulp generate-runtime-helpers'.
6 */
7
8 /* eslint-disable */
9 export default function _regeneratorRuntime() {
10 "use strict";
11
12 /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
13 _regeneratorRuntime = function () {
14 return exports;
15 };
16 var exports = {};
17 var Op = Object.prototype;
18 var hasOwn = Op.hasOwnProperty;
19 var defineProperty =
20 Object.defineProperty ||
21 function (obj, key, desc) {
22 obj[key] = desc.value;
23 };
24 var undefined; // More compressible than void 0.
25 var $Symbol = typeof Symbol === "function" ? Symbol : {};
26 var iteratorSymbol = $Symbol.iterator || "@@iterator";
27 var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
28 var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
29 function define(obj, key, value) {
30 Object.defineProperty(obj, key, {
31 value: value,
32 enumerable: true,
33 configurable: true,
34 writable: true,
35 });
36 return obj[key];
37 }
38 try {
39 // IE 8 has a broken Object.defineProperty that only works on DOM objects.
40 define({}, "");
41 } catch (err) {
42 define = function (obj, key, value) {
43 return (obj[key] = value);
44 };
45 }
46 function wrap(innerFn, outerFn, self, tryLocsList) {
47 // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
48 var protoGenerator =
49 outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
50 var generator = Object.create(protoGenerator.prototype);
51 var context = new Context(tryLocsList || []);
52
53 // The ._invoke method unifies the implementations of the .next,
54 // .throw, and .return methods.
55 defineProperty(generator, "_invoke", {
56 value: makeInvokeMethod(innerFn, self, context),
57 });
58 return generator;
59 }
60 exports.wrap = wrap;
61
62 // Try/catch helper to minimize deoptimizations. Returns a completion
63 // record like context.tryEntries[i].completion. This interface could
64 // have been (and was previously) designed to take a closure to be
65 // invoked without arguments, but in all the cases we care about we
66 // already have an existing method we want to call, so there's no need
67 // to create a new function object. We can even get away with assuming
68 // the method takes exactly one argument, since that happens to be true
69 // in every case, so we don't have to touch the arguments object. The
70 // only additional allocation required is the completion record, which
71 // has a stable shape and so hopefully should be cheap to allocate.
72 function tryCatch(fn, obj, arg) {
73 try {
74 return {
75 type: "normal",
76 arg: fn.call(obj, arg),
77 };
78 } catch (err) {
79 return {
80 type: "throw",
81 arg: err,
82 };
83 }
84 }
85 var GenStateSuspendedStart = "suspendedStart";
86 var GenStateSuspendedYield = "suspendedYield";
87 var GenStateExecuting = "executing";
88 var GenStateCompleted = "completed";
89
90 // Returning this object from the innerFn has the same effect as
91 // breaking out of the dispatch switch statement.
92 var ContinueSentinel = {};
93
94 // Dummy constructor functions that we use as the .constructor and
95 // .constructor.prototype properties for functions that return Generator
96 // objects. For full spec compliance, you may wish to configure your
97 // minifier not to mangle the names of these two functions.
98 function Generator() {}
99 function GeneratorFunction() {}
100 function GeneratorFunctionPrototype() {}
101
102 // This is a polyfill for %IteratorPrototype% for environments that
103 // don't natively support it.
104 var IteratorPrototype = {};
105 define(IteratorPrototype, iteratorSymbol, function () {
106 return this;
107 });
108 var getProto = Object.getPrototypeOf;
109 var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
110 if (
111 NativeIteratorPrototype &&
112 NativeIteratorPrototype !== Op &&
113 hasOwn.call(NativeIteratorPrototype, iteratorSymbol)
114 ) {
115 // This environment has a native %IteratorPrototype%; use it instead
116 // of the polyfill.
117 IteratorPrototype = NativeIteratorPrototype;
118 }
119 var Gp =
120 (GeneratorFunctionPrototype.prototype =
121 Generator.prototype =
122 Object.create(IteratorPrototype));
123 GeneratorFunction.prototype = GeneratorFunctionPrototype;
124 defineProperty(Gp, "constructor", {
125 value: GeneratorFunctionPrototype,
126 configurable: true,
127 });
128 defineProperty(GeneratorFunctionPrototype, "constructor", {
129 value: GeneratorFunction,
130 configurable: true,
131 });
132 GeneratorFunction.displayName = define(
133 GeneratorFunctionPrototype,
134 toStringTagSymbol,
135 "GeneratorFunction",
136 );
137
138 // Helper for defining the .next, .throw, and .return methods of the
139 // Iterator interface in terms of a single ._invoke method.
140 function defineIteratorMethods(prototype) {
141 ["next", "throw", "return"].forEach(function (method) {
142 define(prototype, method, function (arg) {
143 return this._invoke(method, arg);
144 });
145 });
146 }
147 exports.isGeneratorFunction = function (genFun) {
148 var ctor = typeof genFun === "function" && genFun.constructor;
149 return ctor
150 ? ctor === GeneratorFunction ||
151 // For the native GeneratorFunction constructor, the best we can
152 // do is to check its .name property.
153 (ctor.displayName || ctor.name) === "GeneratorFunction"
154 : false;
155 };
156 exports.mark = function (genFun) {
157 if (Object.setPrototypeOf) {
158 Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
159 } else {
160 genFun.__proto__ = GeneratorFunctionPrototype;
161 define(genFun, toStringTagSymbol, "GeneratorFunction");
162 }
163 genFun.prototype = Object.create(Gp);
164 return genFun;
165 };
166
167 // Within the body of any async function, `await x` is transformed to
168 // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
169 // `hasOwn.call(value, "__await")` to determine if the yielded value is
170 // meant to be awaited.
171 exports.awrap = function (arg) {
172 return {
173 __await: arg,
174 };
175 };
176 function AsyncIterator(generator, PromiseImpl) {
177 function invoke(method, arg, resolve, reject) {
178 var record = tryCatch(generator[method], generator, arg);
179 if (record.type === "throw") {
180 reject(record.arg);
181 } else {
182 var result = record.arg;
183 var value = result.value;
184 if (
185 value &&
186 typeof value === "object" &&
187 hasOwn.call(value, "__await")
188 ) {
189 return PromiseImpl.resolve(value.__await).then(
190 function (value) {
191 invoke("next", value, resolve, reject);
192 },
193 function (err) {
194 invoke("throw", err, resolve, reject);
195 },
196 );
197 }
198 return PromiseImpl.resolve(value).then(
199 function (unwrapped) {
200 // When a yielded Promise is resolved, its final value becomes
201 // the .value of the Promise<{value,done}> result for the
202 // current iteration.
203 result.value = unwrapped;
204 resolve(result);
205 },
206 function (error) {
207 // If a rejected Promise was yielded, throw the rejection back
208 // into the async generator function so it can be handled there.
209 return invoke("throw", error, resolve, reject);
210 },
211 );
212 }
213 }
214 var previousPromise;
215 function enqueue(method, arg) {
216 function callInvokeWithMethodAndArg() {
217 return new PromiseImpl(function (resolve, reject) {
218 invoke(method, arg, resolve, reject);
219 });
220 }
221 return (previousPromise =
222 // If enqueue has been called before, then we want to wait until
223 // all previous Promises have been resolved before calling invoke,
224 // so that results are always delivered in the correct order. If
225 // enqueue has not been called before, then it is important to
226 // call invoke immediately, without waiting on a callback to fire,
227 // so that the async generator function has the opportunity to do
228 // any necessary setup in a predictable way. This predictability
229 // is why the Promise constructor synchronously invokes its
230 // executor callback, and why async functions synchronously
231 // execute code before the first await. Since we implement simple
232 // async functions in terms of async generators, it is especially
233 // important to get this right, even though it requires care.
234 previousPromise
235 ? previousPromise.then(
236 callInvokeWithMethodAndArg,
237 // Avoid propagating failures to Promises returned by later
238 // invocations of the iterator.
239 callInvokeWithMethodAndArg,
240 )
241 : callInvokeWithMethodAndArg());
242 }
243
244 // Define the unified helper method that is used to implement .next,
245 // .throw, and .return (see defineIteratorMethods).
246 defineProperty(this, "_invoke", {
247 value: enqueue,
248 });
249 }
250 defineIteratorMethods(AsyncIterator.prototype);
251 define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
252 return this;
253 });
254 exports.AsyncIterator = AsyncIterator;
255
256 // Note that simple async functions are implemented on top of
257 // AsyncIterator objects; they just return a Promise for the value of
258 // the final result produced by the iterator.
259 exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
260 if (PromiseImpl === void 0) PromiseImpl = Promise;
261 var iter = new AsyncIterator(
262 wrap(innerFn, outerFn, self, tryLocsList),
263 PromiseImpl,
264 );
265 return exports.isGeneratorFunction(outerFn)
266 ? iter // If outerFn is a generator, return the full iterator.
267 : iter.next().then(function (result) {
268 return result.done ? result.value : iter.next();
269 });
270 };
271 function makeInvokeMethod(innerFn, self, context) {
272 var state = GenStateSuspendedStart;
273 return function invoke(method, arg) {
274 if (state === GenStateExecuting) {
275 throw new Error("Generator is already running");
276 }
277 if (state === GenStateCompleted) {
278 if (method === "throw") {
279 throw arg;
280 }
281
282 // Be forgiving, per 25.3.3.3.3 of the spec:
283 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
284 return doneResult();
285 }
286 context.method = method;
287 context.arg = arg;
288 while (true) {
289 var delegate = context.delegate;
290 if (delegate) {
291 var delegateResult = maybeInvokeDelegate(delegate, context);
292 if (delegateResult) {
293 if (delegateResult === ContinueSentinel) continue;
294 return delegateResult;
295 }
296 }
297 if (context.method === "next") {
298 // Setting context._sent for legacy support of Babel's
299 // function.sent implementation.
300 context.sent = context._sent = context.arg;
301 } else if (context.method === "throw") {
302 if (state === GenStateSuspendedStart) {
303 state = GenStateCompleted;
304 throw context.arg;
305 }
306 context.dispatchException(context.arg);
307 } else if (context.method === "return") {
308 context.abrupt("return", context.arg);
309 }
310 state = GenStateExecuting;
311 var record = tryCatch(innerFn, self, context);
312 if (record.type === "normal") {
313 // If an exception is thrown from innerFn, we leave state ===
314 // GenStateExecuting and loop back for another invocation.
315 state = context.done ? GenStateCompleted : GenStateSuspendedYield;
316 if (record.arg === ContinueSentinel) {
317 continue;
318 }
319 return {
320 value: record.arg,
321 done: context.done,
322 };
323 } else if (record.type === "throw") {
324 state = GenStateCompleted;
325 // Dispatch the exception by looping back around to the
326 // context.dispatchException(context.arg) call above.
327 context.method = "throw";
328 context.arg = record.arg;
329 }
330 }
331 };
332 }
333
334 // Call delegate.iterator[context.method](context.arg) and handle the
335 // result, either by returning a { value, done } result from the
336 // delegate iterator, or by modifying context.method and context.arg,
337 // setting context.delegate to null, and returning the ContinueSentinel.
338 function maybeInvokeDelegate(delegate, context) {
339 var methodName = context.method;
340 var method = delegate.iterator[methodName];
341 if (method === undefined) {
342 // A .throw or .return when the delegate iterator has no .throw
343 // method, or a missing .next mehtod, always terminate the
344 // yield* loop.
345 context.delegate = null;
346
347 // Note: ["return"] must be used for ES3 parsing compatibility.
348 if (methodName === "throw" && delegate.iterator["return"]) {
349 // If the delegate iterator has a return method, give it a
350 // chance to clean up.
351 context.method = "return";
352 context.arg = undefined;
353 maybeInvokeDelegate(delegate, context);
354 if (context.method === "throw") {
355 // If maybeInvokeDelegate(context) changed context.method from
356 // "return" to "throw", let that override the TypeError below.
357 return ContinueSentinel;
358 }
359 }
360 if (methodName !== "return") {
361 context.method = "throw";
362 context.arg = new TypeError(
363 "The iterator does not provide a '" + methodName + "' method",
364 );
365 }
366 return ContinueSentinel;
367 }
368 var record = tryCatch(method, delegate.iterator, context.arg);
369 if (record.type === "throw") {
370 context.method = "throw";
371 context.arg = record.arg;
372 context.delegate = null;
373 return ContinueSentinel;
374 }
375 var info = record.arg;
376 if (!info) {
377 context.method = "throw";
378 context.arg = new TypeError("iterator result is not an object");
379 context.delegate = null;
380 return ContinueSentinel;
381 }
382 if (info.done) {
383 // Assign the result of the finished delegate to the temporary
384 // variable specified by delegate.resultName (see delegateYield).
385 context[delegate.resultName] = info.value;
386
387 // Resume execution at the desired location (see delegateYield).
388 context.next = delegate.nextLoc;
389
390 // If context.method was "throw" but the delegate handled the
391 // exception, let the outer generator proceed normally. If
392 // context.method was "next", forget context.arg since it has been
393 // "consumed" by the delegate iterator. If context.method was
394 // "return", allow the original .return call to continue in the
395 // outer generator.
396 if (context.method !== "return") {
397 context.method = "next";
398 context.arg = undefined;
399 }
400 } else {
401 // Re-yield the result returned by the delegate method.
402 return info;
403 }
404
405 // The delegate iterator is finished, so forget it and continue with
406 // the outer generator.
407 context.delegate = null;
408 return ContinueSentinel;
409 }
410
411 // Define Generator.prototype.{next,throw,return} in terms of the
412 // unified ._invoke helper method.
413 defineIteratorMethods(Gp);
414 define(Gp, toStringTagSymbol, "Generator");
415
416 // A Generator should always return itself as the iterator object when the
417 // @@iterator function is called on it. Some browsers' implementations of the
418 // iterator prototype chain incorrectly implement this, causing the Generator
419 // object to not be returned from this call. This ensures that doesn't happen.
420 // See https://github.com/facebook/regenerator/issues/274 for more details.
421 define(Gp, iteratorSymbol, function () {
422 return this;
423 });
424 define(Gp, "toString", function () {
425 return "[object Generator]";
426 });
427 function pushTryEntry(locs) {
428 var entry = {
429 tryLoc: locs[0],
430 };
431 if (1 in locs) {
432 entry.catchLoc = locs[1];
433 }
434 if (2 in locs) {
435 entry.finallyLoc = locs[2];
436 entry.afterLoc = locs[3];
437 }
438 this.tryEntries.push(entry);
439 }
440 function resetTryEntry(entry) {
441 var record = entry.completion || {};
442 record.type = "normal";
443 delete record.arg;
444 entry.completion = record;
445 }
446 function Context(tryLocsList) {
447 // The root entry object (effectively a try statement without a catch
448 // or a finally block) gives us a place to store values thrown from
449 // locations where there is no enclosing try statement.
450 this.tryEntries = [
451 {
452 tryLoc: "root",
453 },
454 ];
455 tryLocsList.forEach(pushTryEntry, this);
456 this.reset(true);
457 }
458 exports.keys = function (val) {
459 var object = Object(val);
460 var keys = [];
461 for (var key in object) {
462 keys.push(key);
463 }
464 keys.reverse();
465
466 // Rather than returning an object with a next method, we keep
467 // things simple and return the next function itself.
468 return function next() {
469 while (keys.length) {
470 var key = keys.pop();
471 if (key in object) {
472 next.value = key;
473 next.done = false;
474 return next;
475 }
476 }
477
478 // To avoid creating an additional object, we just hang the .value
479 // and .done properties off the next function object itself. This
480 // also ensures that the minifier will not anonymize the function.
481 next.done = true;
482 return next;
483 };
484 };
485 function values(iterable) {
486 if (iterable) {
487 var iteratorMethod = iterable[iteratorSymbol];
488 if (iteratorMethod) {
489 return iteratorMethod.call(iterable);
490 }
491 if (typeof iterable.next === "function") {
492 return iterable;
493 }
494 if (!isNaN(iterable.length)) {
495 var i = -1,
496 next = function next() {
497 while (++i < iterable.length) {
498 if (hasOwn.call(iterable, i)) {
499 next.value = iterable[i];
500 next.done = false;
501 return next;
502 }
503 }
504 next.value = undefined;
505 next.done = true;
506 return next;
507 };
508 return (next.next = next);
509 }
510 }
511
512 // Return an iterator with no values.
513 return {
514 next: doneResult,
515 };
516 }
517 exports.values = values;
518 function doneResult() {
519 return {
520 value: undefined,
521 done: true,
522 };
523 }
524 Context.prototype = {
525 constructor: Context,
526 reset: function (skipTempReset) {
527 this.prev = 0;
528 this.next = 0;
529 // Resetting context._sent for legacy support of Babel's
530 // function.sent implementation.
531 this.sent = this._sent = undefined;
532 this.done = false;
533 this.delegate = null;
534 this.method = "next";
535 this.arg = undefined;
536 this.tryEntries.forEach(resetTryEntry);
537 if (!skipTempReset) {
538 for (var name in this) {
539 // Not sure about the optimal order of these conditions:
540 if (
541 name.charAt(0) === "t" &&
542 hasOwn.call(this, name) &&
543 !isNaN(+name.slice(1))
544 ) {
545 this[name] = undefined;
546 }
547 }
548 }
549 },
550 stop: function () {
551 this.done = true;
552 var rootEntry = this.tryEntries[0];
553 var rootRecord = rootEntry.completion;
554 if (rootRecord.type === "throw") {
555 throw rootRecord.arg;
556 }
557 return this.rval;
558 },
559 dispatchException: function (exception) {
560 if (this.done) {
561 throw exception;
562 }
563 var context = this;
564 function handle(loc, caught) {
565 record.type = "throw";
566 record.arg = exception;
567 context.next = loc;
568 if (caught) {
569 // If the dispatched exception was caught by a catch block,
570 // then let that catch block handle the exception normally.
571 context.method = "next";
572 context.arg = undefined;
573 }
574 return !!caught;
575 }
576 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
577 var entry = this.tryEntries[i];
578 var record = entry.completion;
579 if (entry.tryLoc === "root") {
580 // Exception thrown outside of any try block that could handle
581 // it, so set the completion value of the entire function to
582 // throw the exception.
583 return handle("end");
584 }
585 if (entry.tryLoc <= this.prev) {
586 var hasCatch = hasOwn.call(entry, "catchLoc");
587 var hasFinally = hasOwn.call(entry, "finallyLoc");
588 if (hasCatch && hasFinally) {
589 if (this.prev < entry.catchLoc) {
590 return handle(entry.catchLoc, true);
591 } else if (this.prev < entry.finallyLoc) {
592 return handle(entry.finallyLoc);
593 }
594 } else if (hasCatch) {
595 if (this.prev < entry.catchLoc) {
596 return handle(entry.catchLoc, true);
597 }
598 } else if (hasFinally) {
599 if (this.prev < entry.finallyLoc) {
600 return handle(entry.finallyLoc);
601 }
602 } else {
603 throw new Error("try statement without catch or finally");
604 }
605 }
606 }
607 },
608 abrupt: function (type, arg) {
609 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
610 var entry = this.tryEntries[i];
611 if (
612 entry.tryLoc <= this.prev &&
613 hasOwn.call(entry, "finallyLoc") &&
614 this.prev < entry.finallyLoc
615 ) {
616 var finallyEntry = entry;
617 break;
618 }
619 }
620 if (
621 finallyEntry &&
622 (type === "break" || type === "continue") &&
623 finallyEntry.tryLoc <= arg &&
624 arg <= finallyEntry.finallyLoc
625 ) {
626 // Ignore the finally entry if control is not jumping to a
627 // location outside the try/catch block.
628 finallyEntry = null;
629 }
630 var record = finallyEntry ? finallyEntry.completion : {};
631 record.type = type;
632 record.arg = arg;
633 if (finallyEntry) {
634 this.method = "next";
635 this.next = finallyEntry.finallyLoc;
636 return ContinueSentinel;
637 }
638 return this.complete(record);
639 },
640 complete: function (record, afterLoc) {
641 if (record.type === "throw") {
642 throw record.arg;
643 }
644 if (record.type === "break" || record.type === "continue") {
645 this.next = record.arg;
646 } else if (record.type === "return") {
647 this.rval = this.arg = record.arg;
648 this.method = "return";
649 this.next = "end";
650 } else if (record.type === "normal" && afterLoc) {
651 this.next = afterLoc;
652 }
653 return ContinueSentinel;
654 },
655 finish: function (finallyLoc) {
656 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
657 var entry = this.tryEntries[i];
658 if (entry.finallyLoc === finallyLoc) {
659 this.complete(entry.completion, entry.afterLoc);
660 resetTryEntry(entry);
661 return ContinueSentinel;
662 }
663 }
664 },
665 catch: function (tryLoc) {
666 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
667 var entry = this.tryEntries[i];
668 if (entry.tryLoc === tryLoc) {
669 var record = entry.completion;
670 if (record.type === "throw") {
671 var thrown = record.arg;
672 resetTryEntry(entry);
673 }
674 return thrown;
675 }
676 }
677
678 // The context.catch method must only be called with a location
679 // argument that corresponds to a known catch block.
680 throw new Error("illegal catch attempt");
681 },
682 delegateYield: function (iterable, resultName, nextLoc) {
683 this.delegate = {
684 iterator: values(iterable),
685 resultName: resultName,
686 nextLoc: nextLoc,
687 };
688 if (this.method === "next") {
689 // Deliberately forget the last sent value so that we don't
690 // accidentally pass it on to the delegate.
691 this.arg = undefined;
692 }
693 return ContinueSentinel;
694 },
695 };
696
697 // Regardless of whether this script is executing as a CommonJS module
698 // or not, return the runtime object so that we can declare the variable
699 // regeneratorRuntime in the outer scope, which allows this module to be
700 // injected easily by `bin/regenerator --include-runtime script.js`.
701 return exports;
702 }