regeneratorRuntime.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _regeneratorRuntime;
  6. function _regeneratorRuntime() {
  7. "use strict";
  8. exports.default = _regeneratorRuntime = function () {
  9. return _exports;
  10. };
  11. var _exports = {};
  12. var Op = Object.prototype;
  13. var hasOwn = Op.hasOwnProperty;
  14. var defineProperty = Object.defineProperty || function (obj, key, desc) {
  15. obj[key] = desc.value;
  16. };
  17. var undefined;
  18. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  19. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  20. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  21. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  22. function define(obj, key, value) {
  23. Object.defineProperty(obj, key, {
  24. value: value,
  25. enumerable: true,
  26. configurable: true,
  27. writable: true
  28. });
  29. return obj[key];
  30. }
  31. try {
  32. define({}, "");
  33. } catch (err) {
  34. define = function (obj, key, value) {
  35. return obj[key] = value;
  36. };
  37. }
  38. function wrap(innerFn, outerFn, self, tryLocsList) {
  39. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  40. var generator = Object.create(protoGenerator.prototype);
  41. var context = new Context(tryLocsList || []);
  42. defineProperty(generator, "_invoke", {
  43. value: makeInvokeMethod(innerFn, self, context)
  44. });
  45. return generator;
  46. }
  47. _exports.wrap = wrap;
  48. function tryCatch(fn, obj, arg) {
  49. try {
  50. return {
  51. type: "normal",
  52. arg: fn.call(obj, arg)
  53. };
  54. } catch (err) {
  55. return {
  56. type: "throw",
  57. arg: err
  58. };
  59. }
  60. }
  61. var GenStateSuspendedStart = "suspendedStart";
  62. var GenStateSuspendedYield = "suspendedYield";
  63. var GenStateExecuting = "executing";
  64. var GenStateCompleted = "completed";
  65. var ContinueSentinel = {};
  66. function Generator() {}
  67. function GeneratorFunction() {}
  68. function GeneratorFunctionPrototype() {}
  69. var IteratorPrototype = {};
  70. define(IteratorPrototype, iteratorSymbol, function () {
  71. return this;
  72. });
  73. var getProto = Object.getPrototypeOf;
  74. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  75. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  76. IteratorPrototype = NativeIteratorPrototype;
  77. }
  78. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  79. GeneratorFunction.prototype = GeneratorFunctionPrototype;
  80. defineProperty(Gp, "constructor", {
  81. value: GeneratorFunctionPrototype,
  82. configurable: true
  83. });
  84. defineProperty(GeneratorFunctionPrototype, "constructor", {
  85. value: GeneratorFunction,
  86. configurable: true
  87. });
  88. GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction");
  89. function defineIteratorMethods(prototype) {
  90. ["next", "throw", "return"].forEach(function (method) {
  91. define(prototype, method, function (arg) {
  92. return this._invoke(method, arg);
  93. });
  94. });
  95. }
  96. _exports.isGeneratorFunction = function (genFun) {
  97. var ctor = typeof genFun === "function" && genFun.constructor;
  98. return ctor ? ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  99. };
  100. _exports.mark = function (genFun) {
  101. if (Object.setPrototypeOf) {
  102. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  103. } else {
  104. genFun.__proto__ = GeneratorFunctionPrototype;
  105. define(genFun, toStringTagSymbol, "GeneratorFunction");
  106. }
  107. genFun.prototype = Object.create(Gp);
  108. return genFun;
  109. };
  110. _exports.awrap = function (arg) {
  111. return {
  112. __await: arg
  113. };
  114. };
  115. function AsyncIterator(generator, PromiseImpl) {
  116. function invoke(method, arg, resolve, reject) {
  117. var record = tryCatch(generator[method], generator, arg);
  118. if (record.type === "throw") {
  119. reject(record.arg);
  120. } else {
  121. var result = record.arg;
  122. var value = result.value;
  123. if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
  124. return PromiseImpl.resolve(value.__await).then(function (value) {
  125. invoke("next", value, resolve, reject);
  126. }, function (err) {
  127. invoke("throw", err, resolve, reject);
  128. });
  129. }
  130. return PromiseImpl.resolve(value).then(function (unwrapped) {
  131. result.value = unwrapped;
  132. resolve(result);
  133. }, function (error) {
  134. return invoke("throw", error, resolve, reject);
  135. });
  136. }
  137. }
  138. var previousPromise;
  139. function enqueue(method, arg) {
  140. function callInvokeWithMethodAndArg() {
  141. return new PromiseImpl(function (resolve, reject) {
  142. invoke(method, arg, resolve, reject);
  143. });
  144. }
  145. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  146. }
  147. defineProperty(this, "_invoke", {
  148. value: enqueue
  149. });
  150. }
  151. defineIteratorMethods(AsyncIterator.prototype);
  152. define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  153. return this;
  154. });
  155. _exports.AsyncIterator = AsyncIterator;
  156. _exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  157. if (PromiseImpl === void 0) PromiseImpl = Promise;
  158. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  159. return _exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  160. return result.done ? result.value : iter.next();
  161. });
  162. };
  163. function makeInvokeMethod(innerFn, self, context) {
  164. var state = GenStateSuspendedStart;
  165. return function invoke(method, arg) {
  166. if (state === GenStateExecuting) {
  167. throw new Error("Generator is already running");
  168. }
  169. if (state === GenStateCompleted) {
  170. if (method === "throw") {
  171. throw arg;
  172. }
  173. return doneResult();
  174. }
  175. context.method = method;
  176. context.arg = arg;
  177. while (true) {
  178. var delegate = context.delegate;
  179. if (delegate) {
  180. var delegateResult = maybeInvokeDelegate(delegate, context);
  181. if (delegateResult) {
  182. if (delegateResult === ContinueSentinel) continue;
  183. return delegateResult;
  184. }
  185. }
  186. if (context.method === "next") {
  187. context.sent = context._sent = context.arg;
  188. } else if (context.method === "throw") {
  189. if (state === GenStateSuspendedStart) {
  190. state = GenStateCompleted;
  191. throw context.arg;
  192. }
  193. context.dispatchException(context.arg);
  194. } else if (context.method === "return") {
  195. context.abrupt("return", context.arg);
  196. }
  197. state = GenStateExecuting;
  198. var record = tryCatch(innerFn, self, context);
  199. if (record.type === "normal") {
  200. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  201. if (record.arg === ContinueSentinel) {
  202. continue;
  203. }
  204. return {
  205. value: record.arg,
  206. done: context.done
  207. };
  208. } else if (record.type === "throw") {
  209. state = GenStateCompleted;
  210. context.method = "throw";
  211. context.arg = record.arg;
  212. }
  213. }
  214. };
  215. }
  216. function maybeInvokeDelegate(delegate, context) {
  217. var methodName = context.method;
  218. var method = delegate.iterator[methodName];
  219. if (method === undefined) {
  220. context.delegate = null;
  221. if (methodName === "throw" && delegate.iterator["return"]) {
  222. context.method = "return";
  223. context.arg = undefined;
  224. maybeInvokeDelegate(delegate, context);
  225. if (context.method === "throw") {
  226. return ContinueSentinel;
  227. }
  228. }
  229. if (methodName !== "return") {
  230. context.method = "throw";
  231. context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method");
  232. }
  233. return ContinueSentinel;
  234. }
  235. var record = tryCatch(method, delegate.iterator, context.arg);
  236. if (record.type === "throw") {
  237. context.method = "throw";
  238. context.arg = record.arg;
  239. context.delegate = null;
  240. return ContinueSentinel;
  241. }
  242. var info = record.arg;
  243. if (!info) {
  244. context.method = "throw";
  245. context.arg = new TypeError("iterator result is not an object");
  246. context.delegate = null;
  247. return ContinueSentinel;
  248. }
  249. if (info.done) {
  250. context[delegate.resultName] = info.value;
  251. context.next = delegate.nextLoc;
  252. if (context.method !== "return") {
  253. context.method = "next";
  254. context.arg = undefined;
  255. }
  256. } else {
  257. return info;
  258. }
  259. context.delegate = null;
  260. return ContinueSentinel;
  261. }
  262. defineIteratorMethods(Gp);
  263. define(Gp, toStringTagSymbol, "Generator");
  264. define(Gp, iteratorSymbol, function () {
  265. return this;
  266. });
  267. define(Gp, "toString", function () {
  268. return "[object Generator]";
  269. });
  270. function pushTryEntry(locs) {
  271. var entry = {
  272. tryLoc: locs[0]
  273. };
  274. if (1 in locs) {
  275. entry.catchLoc = locs[1];
  276. }
  277. if (2 in locs) {
  278. entry.finallyLoc = locs[2];
  279. entry.afterLoc = locs[3];
  280. }
  281. this.tryEntries.push(entry);
  282. }
  283. function resetTryEntry(entry) {
  284. var record = entry.completion || {};
  285. record.type = "normal";
  286. delete record.arg;
  287. entry.completion = record;
  288. }
  289. function Context(tryLocsList) {
  290. this.tryEntries = [{
  291. tryLoc: "root"
  292. }];
  293. tryLocsList.forEach(pushTryEntry, this);
  294. this.reset(true);
  295. }
  296. _exports.keys = function (val) {
  297. var object = Object(val);
  298. var keys = [];
  299. for (var key in object) {
  300. keys.push(key);
  301. }
  302. keys.reverse();
  303. return function next() {
  304. while (keys.length) {
  305. var key = keys.pop();
  306. if (key in object) {
  307. next.value = key;
  308. next.done = false;
  309. return next;
  310. }
  311. }
  312. next.done = true;
  313. return next;
  314. };
  315. };
  316. function values(iterable) {
  317. if (iterable || iterable === "") {
  318. var iteratorMethod = iterable[iteratorSymbol];
  319. if (iteratorMethod) {
  320. return iteratorMethod.call(iterable);
  321. }
  322. if (typeof iterable.next === "function") {
  323. return iterable;
  324. }
  325. if (!isNaN(iterable.length)) {
  326. var i = -1,
  327. next = function next() {
  328. while (++i < iterable.length) {
  329. if (hasOwn.call(iterable, i)) {
  330. next.value = iterable[i];
  331. next.done = false;
  332. return next;
  333. }
  334. }
  335. next.value = undefined;
  336. next.done = true;
  337. return next;
  338. };
  339. return next.next = next;
  340. }
  341. }
  342. throw new TypeError(typeof iterable + " is not iterable");
  343. }
  344. _exports.values = values;
  345. function doneResult() {
  346. return {
  347. value: undefined,
  348. done: true
  349. };
  350. }
  351. Context.prototype = {
  352. constructor: Context,
  353. reset: function (skipTempReset) {
  354. this.prev = 0;
  355. this.next = 0;
  356. this.sent = this._sent = undefined;
  357. this.done = false;
  358. this.delegate = null;
  359. this.method = "next";
  360. this.arg = undefined;
  361. this.tryEntries.forEach(resetTryEntry);
  362. if (!skipTempReset) {
  363. for (var name in this) {
  364. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  365. this[name] = undefined;
  366. }
  367. }
  368. }
  369. },
  370. stop: function () {
  371. this.done = true;
  372. var rootEntry = this.tryEntries[0];
  373. var rootRecord = rootEntry.completion;
  374. if (rootRecord.type === "throw") {
  375. throw rootRecord.arg;
  376. }
  377. return this.rval;
  378. },
  379. dispatchException: function (exception) {
  380. if (this.done) {
  381. throw exception;
  382. }
  383. var context = this;
  384. function handle(loc, caught) {
  385. record.type = "throw";
  386. record.arg = exception;
  387. context.next = loc;
  388. if (caught) {
  389. context.method = "next";
  390. context.arg = undefined;
  391. }
  392. return !!caught;
  393. }
  394. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  395. var entry = this.tryEntries[i];
  396. var record = entry.completion;
  397. if (entry.tryLoc === "root") {
  398. return handle("end");
  399. }
  400. if (entry.tryLoc <= this.prev) {
  401. var hasCatch = hasOwn.call(entry, "catchLoc");
  402. var hasFinally = hasOwn.call(entry, "finallyLoc");
  403. if (hasCatch && hasFinally) {
  404. if (this.prev < entry.catchLoc) {
  405. return handle(entry.catchLoc, true);
  406. } else if (this.prev < entry.finallyLoc) {
  407. return handle(entry.finallyLoc);
  408. }
  409. } else if (hasCatch) {
  410. if (this.prev < entry.catchLoc) {
  411. return handle(entry.catchLoc, true);
  412. }
  413. } else if (hasFinally) {
  414. if (this.prev < entry.finallyLoc) {
  415. return handle(entry.finallyLoc);
  416. }
  417. } else {
  418. throw new Error("try statement without catch or finally");
  419. }
  420. }
  421. }
  422. },
  423. abrupt: function (type, arg) {
  424. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  425. var entry = this.tryEntries[i];
  426. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  427. var finallyEntry = entry;
  428. break;
  429. }
  430. }
  431. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  432. finallyEntry = null;
  433. }
  434. var record = finallyEntry ? finallyEntry.completion : {};
  435. record.type = type;
  436. record.arg = arg;
  437. if (finallyEntry) {
  438. this.method = "next";
  439. this.next = finallyEntry.finallyLoc;
  440. return ContinueSentinel;
  441. }
  442. return this.complete(record);
  443. },
  444. complete: function (record, afterLoc) {
  445. if (record.type === "throw") {
  446. throw record.arg;
  447. }
  448. if (record.type === "break" || record.type === "continue") {
  449. this.next = record.arg;
  450. } else if (record.type === "return") {
  451. this.rval = this.arg = record.arg;
  452. this.method = "return";
  453. this.next = "end";
  454. } else if (record.type === "normal" && afterLoc) {
  455. this.next = afterLoc;
  456. }
  457. return ContinueSentinel;
  458. },
  459. finish: function (finallyLoc) {
  460. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  461. var entry = this.tryEntries[i];
  462. if (entry.finallyLoc === finallyLoc) {
  463. this.complete(entry.completion, entry.afterLoc);
  464. resetTryEntry(entry);
  465. return ContinueSentinel;
  466. }
  467. }
  468. },
  469. catch: function (tryLoc) {
  470. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  471. var entry = this.tryEntries[i];
  472. if (entry.tryLoc === tryLoc) {
  473. var record = entry.completion;
  474. if (record.type === "throw") {
  475. var thrown = record.arg;
  476. resetTryEntry(entry);
  477. }
  478. return thrown;
  479. }
  480. }
  481. throw new Error("illegal catch attempt");
  482. },
  483. delegateYield: function (iterable, resultName, nextLoc) {
  484. this.delegate = {
  485. iterator: values(iterable),
  486. resultName: resultName,
  487. nextLoc: nextLoc
  488. };
  489. if (this.method === "next") {
  490. this.arg = undefined;
  491. }
  492. return ContinueSentinel;
  493. }
  494. };
  495. return _exports;
  496. }
  497. //# sourceMappingURL=regeneratorRuntime.js.map