regeneratorRuntime.js 15 KB

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