token-list.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. this["wp"] = this["wp"] || {}; this["wp"]["tokenList"] =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 337);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 11:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _createClass; });
  93. function _defineProperties(target, props) {
  94. for (var i = 0; i < props.length; i++) {
  95. var descriptor = props[i];
  96. descriptor.enumerable = descriptor.enumerable || false;
  97. descriptor.configurable = true;
  98. if ("value" in descriptor) descriptor.writable = true;
  99. Object.defineProperty(target, descriptor.key, descriptor);
  100. }
  101. }
  102. function _createClass(Constructor, protoProps, staticProps) {
  103. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  104. if (staticProps) _defineProperties(Constructor, staticProps);
  105. return Constructor;
  106. }
  107. /***/ }),
  108. /***/ 12:
  109. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  110. "use strict";
  111. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _classCallCheck; });
  112. function _classCallCheck(instance, Constructor) {
  113. if (!(instance instanceof Constructor)) {
  114. throw new TypeError("Cannot call a class as a function");
  115. }
  116. }
  117. /***/ }),
  118. /***/ 2:
  119. /***/ (function(module, exports) {
  120. (function() { module.exports = this["lodash"]; }());
  121. /***/ }),
  122. /***/ 20:
  123. /***/ (function(module, exports, __webpack_require__) {
  124. module.exports = __webpack_require__(47);
  125. /***/ }),
  126. /***/ 337:
  127. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  128. "use strict";
  129. __webpack_require__.r(__webpack_exports__);
  130. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "default", function() { return TokenList; });
  131. /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(20);
  132. /* harmony import */ var _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0__);
  133. /* harmony import */ var _babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
  134. /* harmony import */ var _babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11);
  135. /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2);
  136. /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_3__);
  137. /**
  138. * External dependencies
  139. */
  140. /**
  141. * A set of tokens.
  142. *
  143. * @see https://dom.spec.whatwg.org/#domtokenlist
  144. */
  145. var TokenList =
  146. /*#__PURE__*/
  147. function () {
  148. /**
  149. * Constructs a new instance of TokenList.
  150. *
  151. * @param {string} initialValue Initial value to assign.
  152. */
  153. function TokenList() {
  154. var _this = this;
  155. var initialValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  156. Object(_babel_runtime_helpers_esm_classCallCheck__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])(this, TokenList);
  157. this.value = initialValue;
  158. ['entries', 'forEach', 'keys', 'values'].forEach(function (fn) {
  159. _this[fn] = function () {
  160. var _this$_valueAsArray;
  161. return (_this$_valueAsArray = this._valueAsArray)[fn].apply(_this$_valueAsArray, arguments);
  162. }.bind(_this);
  163. });
  164. }
  165. /**
  166. * Returns the associated set as string.
  167. *
  168. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
  169. *
  170. * @return {string} Token set as string.
  171. */
  172. Object(_babel_runtime_helpers_esm_createClass__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"])(TokenList, [{
  173. key: "toString",
  174. /**
  175. * Returns the stringified form of the TokenList.
  176. *
  177. * @see https://dom.spec.whatwg.org/#DOMTokenList-stringification-behavior
  178. * @see https://www.ecma-international.org/ecma-262/9.0/index.html#sec-tostring
  179. *
  180. * @return {string} Token set as string.
  181. */
  182. value: function toString() {
  183. return this.value;
  184. }
  185. /**
  186. * Returns an iterator for the TokenList, iterating items of the set.
  187. *
  188. * @see https://dom.spec.whatwg.org/#domtokenlist
  189. *
  190. * @return {IterableIterator<string>} TokenList iterator.
  191. */
  192. }, {
  193. key: Symbol.iterator,
  194. value:
  195. /*#__PURE__*/
  196. _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.mark(function value() {
  197. return _babel_runtime_regenerator__WEBPACK_IMPORTED_MODULE_0___default.a.wrap(function value$(_context) {
  198. while (1) {
  199. switch (_context.prev = _context.next) {
  200. case 0:
  201. return _context.delegateYield(this._valueAsArray, "t0", 1);
  202. case 1:
  203. return _context.abrupt("return", _context.t0);
  204. case 2:
  205. case "end":
  206. return _context.stop();
  207. }
  208. }
  209. }, value, this);
  210. })
  211. /**
  212. * Returns the token with index `index`.
  213. *
  214. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-item
  215. *
  216. * @param {number} index Index at which to return token.
  217. *
  218. * @return {?string} Token at index.
  219. */
  220. }, {
  221. key: "item",
  222. value: function item(index) {
  223. return this._valueAsArray[index];
  224. }
  225. /**
  226. * Returns true if `token` is present, and false otherwise.
  227. *
  228. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-contains
  229. *
  230. * @param {string} item Token to test.
  231. *
  232. * @return {boolean} Whether token is present.
  233. */
  234. }, {
  235. key: "contains",
  236. value: function contains(item) {
  237. return this._valueAsArray.indexOf(item) !== -1;
  238. }
  239. /**
  240. * Adds all arguments passed, except those already present.
  241. *
  242. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-add
  243. *
  244. * @param {...string} items Items to add.
  245. */
  246. }, {
  247. key: "add",
  248. value: function add() {
  249. for (var _len = arguments.length, items = new Array(_len), _key = 0; _key < _len; _key++) {
  250. items[_key] = arguments[_key];
  251. }
  252. this.value += ' ' + items.join(' ');
  253. }
  254. /**
  255. * Removes arguments passed, if they are present.
  256. *
  257. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-remove
  258. *
  259. * @param {...string} items Items to remove.
  260. */
  261. }, {
  262. key: "remove",
  263. value: function remove() {
  264. for (var _len2 = arguments.length, items = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  265. items[_key2] = arguments[_key2];
  266. }
  267. this.value = lodash__WEBPACK_IMPORTED_MODULE_3__["without"].apply(void 0, [this._valueAsArray].concat(items)).join(' ');
  268. }
  269. /**
  270. * If `force` is not given, "toggles" `token`, removing it if it’s present
  271. * and adding it if it’s not present. If `force` is true, adds token (same
  272. * as add()). If force is false, removes token (same as remove()). Returns
  273. * true if `token` is now present, and false otherwise.
  274. *
  275. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
  276. *
  277. * @param {string} token Token to toggle.
  278. * @param {?boolean} force Presence to force.
  279. *
  280. * @return {boolean} Whether token is present after toggle.
  281. */
  282. }, {
  283. key: "toggle",
  284. value: function toggle(token, force) {
  285. if (undefined === force) {
  286. force = !this.contains(token);
  287. }
  288. if (force) {
  289. this.add(token);
  290. } else {
  291. this.remove(token);
  292. }
  293. return force;
  294. }
  295. /**
  296. * Replaces `token` with `newToken`. Returns true if `token` was replaced
  297. * with `newToken`, and false otherwise.
  298. *
  299. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-replace
  300. *
  301. * @param {string} token Token to replace with `newToken`.
  302. * @param {string} newToken Token to use in place of `token`.
  303. *
  304. * @return {boolean} Whether replacement occurred.
  305. */
  306. }, {
  307. key: "replace",
  308. value: function replace(token, newToken) {
  309. if (!this.contains(token)) {
  310. return false;
  311. }
  312. this.remove(token);
  313. this.add(newToken);
  314. return true;
  315. }
  316. /**
  317. * Returns true if `token` is in the associated attribute’s supported
  318. * tokens. Returns false otherwise.
  319. *
  320. * Always returns `true` in this implementation.
  321. *
  322. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-supports
  323. *
  324. * @return {boolean} Whether token is supported.
  325. */
  326. }, {
  327. key: "supports",
  328. value: function supports() {
  329. return true;
  330. }
  331. }, {
  332. key: "value",
  333. get: function get() {
  334. return this._currentValue;
  335. }
  336. /**
  337. * Replaces the associated set with a new string value.
  338. *
  339. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-value
  340. *
  341. * @param {string} value New token set as string.
  342. */
  343. ,
  344. set: function set(value) {
  345. value = String(value);
  346. this._valueAsArray = Object(lodash__WEBPACK_IMPORTED_MODULE_3__["uniq"])(Object(lodash__WEBPACK_IMPORTED_MODULE_3__["compact"])(value.split(/\s+/g)));
  347. this._currentValue = this._valueAsArray.join(' ');
  348. }
  349. /**
  350. * Returns the number of tokens.
  351. *
  352. * @see https://dom.spec.whatwg.org/#dom-domtokenlist-length
  353. *
  354. * @return {number} Number of tokens.
  355. */
  356. }, {
  357. key: "length",
  358. get: function get() {
  359. return this._valueAsArray.length;
  360. }
  361. }]);
  362. return TokenList;
  363. }();
  364. /***/ }),
  365. /***/ 47:
  366. /***/ (function(module, exports, __webpack_require__) {
  367. /**
  368. * Copyright (c) 2014-present, Facebook, Inc.
  369. *
  370. * This source code is licensed under the MIT license found in the
  371. * LICENSE file in the root directory of this source tree.
  372. */
  373. var runtime = (function (exports) {
  374. "use strict";
  375. var Op = Object.prototype;
  376. var hasOwn = Op.hasOwnProperty;
  377. var undefined; // More compressible than void 0.
  378. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  379. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  380. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  381. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  382. function wrap(innerFn, outerFn, self, tryLocsList) {
  383. // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
  384. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  385. var generator = Object.create(protoGenerator.prototype);
  386. var context = new Context(tryLocsList || []);
  387. // The ._invoke method unifies the implementations of the .next,
  388. // .throw, and .return methods.
  389. generator._invoke = makeInvokeMethod(innerFn, self, context);
  390. return generator;
  391. }
  392. exports.wrap = wrap;
  393. // Try/catch helper to minimize deoptimizations. Returns a completion
  394. // record like context.tryEntries[i].completion. This interface could
  395. // have been (and was previously) designed to take a closure to be
  396. // invoked without arguments, but in all the cases we care about we
  397. // already have an existing method we want to call, so there's no need
  398. // to create a new function object. We can even get away with assuming
  399. // the method takes exactly one argument, since that happens to be true
  400. // in every case, so we don't have to touch the arguments object. The
  401. // only additional allocation required is the completion record, which
  402. // has a stable shape and so hopefully should be cheap to allocate.
  403. function tryCatch(fn, obj, arg) {
  404. try {
  405. return { type: "normal", arg: fn.call(obj, arg) };
  406. } catch (err) {
  407. return { type: "throw", arg: err };
  408. }
  409. }
  410. var GenStateSuspendedStart = "suspendedStart";
  411. var GenStateSuspendedYield = "suspendedYield";
  412. var GenStateExecuting = "executing";
  413. var GenStateCompleted = "completed";
  414. // Returning this object from the innerFn has the same effect as
  415. // breaking out of the dispatch switch statement.
  416. var ContinueSentinel = {};
  417. // Dummy constructor functions that we use as the .constructor and
  418. // .constructor.prototype properties for functions that return Generator
  419. // objects. For full spec compliance, you may wish to configure your
  420. // minifier not to mangle the names of these two functions.
  421. function Generator() {}
  422. function GeneratorFunction() {}
  423. function GeneratorFunctionPrototype() {}
  424. // This is a polyfill for %IteratorPrototype% for environments that
  425. // don't natively support it.
  426. var IteratorPrototype = {};
  427. IteratorPrototype[iteratorSymbol] = function () {
  428. return this;
  429. };
  430. var getProto = Object.getPrototypeOf;
  431. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  432. if (NativeIteratorPrototype &&
  433. NativeIteratorPrototype !== Op &&
  434. hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  435. // This environment has a native %IteratorPrototype%; use it instead
  436. // of the polyfill.
  437. IteratorPrototype = NativeIteratorPrototype;
  438. }
  439. var Gp = GeneratorFunctionPrototype.prototype =
  440. Generator.prototype = Object.create(IteratorPrototype);
  441. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  442. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  443. GeneratorFunctionPrototype[toStringTagSymbol] =
  444. GeneratorFunction.displayName = "GeneratorFunction";
  445. // Helper for defining the .next, .throw, and .return methods of the
  446. // Iterator interface in terms of a single ._invoke method.
  447. function defineIteratorMethods(prototype) {
  448. ["next", "throw", "return"].forEach(function(method) {
  449. prototype[method] = function(arg) {
  450. return this._invoke(method, arg);
  451. };
  452. });
  453. }
  454. exports.isGeneratorFunction = function(genFun) {
  455. var ctor = typeof genFun === "function" && genFun.constructor;
  456. return ctor
  457. ? ctor === GeneratorFunction ||
  458. // For the native GeneratorFunction constructor, the best we can
  459. // do is to check its .name property.
  460. (ctor.displayName || ctor.name) === "GeneratorFunction"
  461. : false;
  462. };
  463. exports.mark = function(genFun) {
  464. if (Object.setPrototypeOf) {
  465. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  466. } else {
  467. genFun.__proto__ = GeneratorFunctionPrototype;
  468. if (!(toStringTagSymbol in genFun)) {
  469. genFun[toStringTagSymbol] = "GeneratorFunction";
  470. }
  471. }
  472. genFun.prototype = Object.create(Gp);
  473. return genFun;
  474. };
  475. // Within the body of any async function, `await x` is transformed to
  476. // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
  477. // `hasOwn.call(value, "__await")` to determine if the yielded value is
  478. // meant to be awaited.
  479. exports.awrap = function(arg) {
  480. return { __await: arg };
  481. };
  482. function AsyncIterator(generator) {
  483. function invoke(method, arg, resolve, reject) {
  484. var record = tryCatch(generator[method], generator, arg);
  485. if (record.type === "throw") {
  486. reject(record.arg);
  487. } else {
  488. var result = record.arg;
  489. var value = result.value;
  490. if (value &&
  491. typeof value === "object" &&
  492. hasOwn.call(value, "__await")) {
  493. return Promise.resolve(value.__await).then(function(value) {
  494. invoke("next", value, resolve, reject);
  495. }, function(err) {
  496. invoke("throw", err, resolve, reject);
  497. });
  498. }
  499. return Promise.resolve(value).then(function(unwrapped) {
  500. // When a yielded Promise is resolved, its final value becomes
  501. // the .value of the Promise<{value,done}> result for the
  502. // current iteration.
  503. result.value = unwrapped;
  504. resolve(result);
  505. }, function(error) {
  506. // If a rejected Promise was yielded, throw the rejection back
  507. // into the async generator function so it can be handled there.
  508. return invoke("throw", error, resolve, reject);
  509. });
  510. }
  511. }
  512. var previousPromise;
  513. function enqueue(method, arg) {
  514. function callInvokeWithMethodAndArg() {
  515. return new Promise(function(resolve, reject) {
  516. invoke(method, arg, resolve, reject);
  517. });
  518. }
  519. return previousPromise =
  520. // If enqueue has been called before, then we want to wait until
  521. // all previous Promises have been resolved before calling invoke,
  522. // so that results are always delivered in the correct order. If
  523. // enqueue has not been called before, then it is important to
  524. // call invoke immediately, without waiting on a callback to fire,
  525. // so that the async generator function has the opportunity to do
  526. // any necessary setup in a predictable way. This predictability
  527. // is why the Promise constructor synchronously invokes its
  528. // executor callback, and why async functions synchronously
  529. // execute code before the first await. Since we implement simple
  530. // async functions in terms of async generators, it is especially
  531. // important to get this right, even though it requires care.
  532. previousPromise ? previousPromise.then(
  533. callInvokeWithMethodAndArg,
  534. // Avoid propagating failures to Promises returned by later
  535. // invocations of the iterator.
  536. callInvokeWithMethodAndArg
  537. ) : callInvokeWithMethodAndArg();
  538. }
  539. // Define the unified helper method that is used to implement .next,
  540. // .throw, and .return (see defineIteratorMethods).
  541. this._invoke = enqueue;
  542. }
  543. defineIteratorMethods(AsyncIterator.prototype);
  544. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  545. return this;
  546. };
  547. exports.AsyncIterator = AsyncIterator;
  548. // Note that simple async functions are implemented on top of
  549. // AsyncIterator objects; they just return a Promise for the value of
  550. // the final result produced by the iterator.
  551. exports.async = function(innerFn, outerFn, self, tryLocsList) {
  552. var iter = new AsyncIterator(
  553. wrap(innerFn, outerFn, self, tryLocsList)
  554. );
  555. return exports.isGeneratorFunction(outerFn)
  556. ? iter // If outerFn is a generator, return the full iterator.
  557. : iter.next().then(function(result) {
  558. return result.done ? result.value : iter.next();
  559. });
  560. };
  561. function makeInvokeMethod(innerFn, self, context) {
  562. var state = GenStateSuspendedStart;
  563. return function invoke(method, arg) {
  564. if (state === GenStateExecuting) {
  565. throw new Error("Generator is already running");
  566. }
  567. if (state === GenStateCompleted) {
  568. if (method === "throw") {
  569. throw arg;
  570. }
  571. // Be forgiving, per 25.3.3.3.3 of the spec:
  572. // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
  573. return doneResult();
  574. }
  575. context.method = method;
  576. context.arg = arg;
  577. while (true) {
  578. var delegate = context.delegate;
  579. if (delegate) {
  580. var delegateResult = maybeInvokeDelegate(delegate, context);
  581. if (delegateResult) {
  582. if (delegateResult === ContinueSentinel) continue;
  583. return delegateResult;
  584. }
  585. }
  586. if (context.method === "next") {
  587. // Setting context._sent for legacy support of Babel's
  588. // function.sent implementation.
  589. context.sent = context._sent = context.arg;
  590. } else if (context.method === "throw") {
  591. if (state === GenStateSuspendedStart) {
  592. state = GenStateCompleted;
  593. throw context.arg;
  594. }
  595. context.dispatchException(context.arg);
  596. } else if (context.method === "return") {
  597. context.abrupt("return", context.arg);
  598. }
  599. state = GenStateExecuting;
  600. var record = tryCatch(innerFn, self, context);
  601. if (record.type === "normal") {
  602. // If an exception is thrown from innerFn, we leave state ===
  603. // GenStateExecuting and loop back for another invocation.
  604. state = context.done
  605. ? GenStateCompleted
  606. : GenStateSuspendedYield;
  607. if (record.arg === ContinueSentinel) {
  608. continue;
  609. }
  610. return {
  611. value: record.arg,
  612. done: context.done
  613. };
  614. } else if (record.type === "throw") {
  615. state = GenStateCompleted;
  616. // Dispatch the exception by looping back around to the
  617. // context.dispatchException(context.arg) call above.
  618. context.method = "throw";
  619. context.arg = record.arg;
  620. }
  621. }
  622. };
  623. }
  624. // Call delegate.iterator[context.method](context.arg) and handle the
  625. // result, either by returning a { value, done } result from the
  626. // delegate iterator, or by modifying context.method and context.arg,
  627. // setting context.delegate to null, and returning the ContinueSentinel.
  628. function maybeInvokeDelegate(delegate, context) {
  629. var method = delegate.iterator[context.method];
  630. if (method === undefined) {
  631. // A .throw or .return when the delegate iterator has no .throw
  632. // method always terminates the yield* loop.
  633. context.delegate = null;
  634. if (context.method === "throw") {
  635. // Note: ["return"] must be used for ES3 parsing compatibility.
  636. if (delegate.iterator["return"]) {
  637. // If the delegate iterator has a return method, give it a
  638. // chance to clean up.
  639. context.method = "return";
  640. context.arg = undefined;
  641. maybeInvokeDelegate(delegate, context);
  642. if (context.method === "throw") {
  643. // If maybeInvokeDelegate(context) changed context.method from
  644. // "return" to "throw", let that override the TypeError below.
  645. return ContinueSentinel;
  646. }
  647. }
  648. context.method = "throw";
  649. context.arg = new TypeError(
  650. "The iterator does not provide a 'throw' method");
  651. }
  652. return ContinueSentinel;
  653. }
  654. var record = tryCatch(method, delegate.iterator, context.arg);
  655. if (record.type === "throw") {
  656. context.method = "throw";
  657. context.arg = record.arg;
  658. context.delegate = null;
  659. return ContinueSentinel;
  660. }
  661. var info = record.arg;
  662. if (! info) {
  663. context.method = "throw";
  664. context.arg = new TypeError("iterator result is not an object");
  665. context.delegate = null;
  666. return ContinueSentinel;
  667. }
  668. if (info.done) {
  669. // Assign the result of the finished delegate to the temporary
  670. // variable specified by delegate.resultName (see delegateYield).
  671. context[delegate.resultName] = info.value;
  672. // Resume execution at the desired location (see delegateYield).
  673. context.next = delegate.nextLoc;
  674. // If context.method was "throw" but the delegate handled the
  675. // exception, let the outer generator proceed normally. If
  676. // context.method was "next", forget context.arg since it has been
  677. // "consumed" by the delegate iterator. If context.method was
  678. // "return", allow the original .return call to continue in the
  679. // outer generator.
  680. if (context.method !== "return") {
  681. context.method = "next";
  682. context.arg = undefined;
  683. }
  684. } else {
  685. // Re-yield the result returned by the delegate method.
  686. return info;
  687. }
  688. // The delegate iterator is finished, so forget it and continue with
  689. // the outer generator.
  690. context.delegate = null;
  691. return ContinueSentinel;
  692. }
  693. // Define Generator.prototype.{next,throw,return} in terms of the
  694. // unified ._invoke helper method.
  695. defineIteratorMethods(Gp);
  696. Gp[toStringTagSymbol] = "Generator";
  697. // A Generator should always return itself as the iterator object when the
  698. // @@iterator function is called on it. Some browsers' implementations of the
  699. // iterator prototype chain incorrectly implement this, causing the Generator
  700. // object to not be returned from this call. This ensures that doesn't happen.
  701. // See https://github.com/facebook/regenerator/issues/274 for more details.
  702. Gp[iteratorSymbol] = function() {
  703. return this;
  704. };
  705. Gp.toString = function() {
  706. return "[object Generator]";
  707. };
  708. function pushTryEntry(locs) {
  709. var entry = { tryLoc: locs[0] };
  710. if (1 in locs) {
  711. entry.catchLoc = locs[1];
  712. }
  713. if (2 in locs) {
  714. entry.finallyLoc = locs[2];
  715. entry.afterLoc = locs[3];
  716. }
  717. this.tryEntries.push(entry);
  718. }
  719. function resetTryEntry(entry) {
  720. var record = entry.completion || {};
  721. record.type = "normal";
  722. delete record.arg;
  723. entry.completion = record;
  724. }
  725. function Context(tryLocsList) {
  726. // The root entry object (effectively a try statement without a catch
  727. // or a finally block) gives us a place to store values thrown from
  728. // locations where there is no enclosing try statement.
  729. this.tryEntries = [{ tryLoc: "root" }];
  730. tryLocsList.forEach(pushTryEntry, this);
  731. this.reset(true);
  732. }
  733. exports.keys = function(object) {
  734. var keys = [];
  735. for (var key in object) {
  736. keys.push(key);
  737. }
  738. keys.reverse();
  739. // Rather than returning an object with a next method, we keep
  740. // things simple and return the next function itself.
  741. return function next() {
  742. while (keys.length) {
  743. var key = keys.pop();
  744. if (key in object) {
  745. next.value = key;
  746. next.done = false;
  747. return next;
  748. }
  749. }
  750. // To avoid creating an additional object, we just hang the .value
  751. // and .done properties off the next function object itself. This
  752. // also ensures that the minifier will not anonymize the function.
  753. next.done = true;
  754. return next;
  755. };
  756. };
  757. function values(iterable) {
  758. if (iterable) {
  759. var iteratorMethod = iterable[iteratorSymbol];
  760. if (iteratorMethod) {
  761. return iteratorMethod.call(iterable);
  762. }
  763. if (typeof iterable.next === "function") {
  764. return iterable;
  765. }
  766. if (!isNaN(iterable.length)) {
  767. var i = -1, next = function next() {
  768. while (++i < iterable.length) {
  769. if (hasOwn.call(iterable, i)) {
  770. next.value = iterable[i];
  771. next.done = false;
  772. return next;
  773. }
  774. }
  775. next.value = undefined;
  776. next.done = true;
  777. return next;
  778. };
  779. return next.next = next;
  780. }
  781. }
  782. // Return an iterator with no values.
  783. return { next: doneResult };
  784. }
  785. exports.values = values;
  786. function doneResult() {
  787. return { value: undefined, done: true };
  788. }
  789. Context.prototype = {
  790. constructor: Context,
  791. reset: function(skipTempReset) {
  792. this.prev = 0;
  793. this.next = 0;
  794. // Resetting context._sent for legacy support of Babel's
  795. // function.sent implementation.
  796. this.sent = this._sent = undefined;
  797. this.done = false;
  798. this.delegate = null;
  799. this.method = "next";
  800. this.arg = undefined;
  801. this.tryEntries.forEach(resetTryEntry);
  802. if (!skipTempReset) {
  803. for (var name in this) {
  804. // Not sure about the optimal order of these conditions:
  805. if (name.charAt(0) === "t" &&
  806. hasOwn.call(this, name) &&
  807. !isNaN(+name.slice(1))) {
  808. this[name] = undefined;
  809. }
  810. }
  811. }
  812. },
  813. stop: function() {
  814. this.done = true;
  815. var rootEntry = this.tryEntries[0];
  816. var rootRecord = rootEntry.completion;
  817. if (rootRecord.type === "throw") {
  818. throw rootRecord.arg;
  819. }
  820. return this.rval;
  821. },
  822. dispatchException: function(exception) {
  823. if (this.done) {
  824. throw exception;
  825. }
  826. var context = this;
  827. function handle(loc, caught) {
  828. record.type = "throw";
  829. record.arg = exception;
  830. context.next = loc;
  831. if (caught) {
  832. // If the dispatched exception was caught by a catch block,
  833. // then let that catch block handle the exception normally.
  834. context.method = "next";
  835. context.arg = undefined;
  836. }
  837. return !! caught;
  838. }
  839. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  840. var entry = this.tryEntries[i];
  841. var record = entry.completion;
  842. if (entry.tryLoc === "root") {
  843. // Exception thrown outside of any try block that could handle
  844. // it, so set the completion value of the entire function to
  845. // throw the exception.
  846. return handle("end");
  847. }
  848. if (entry.tryLoc <= this.prev) {
  849. var hasCatch = hasOwn.call(entry, "catchLoc");
  850. var hasFinally = hasOwn.call(entry, "finallyLoc");
  851. if (hasCatch && hasFinally) {
  852. if (this.prev < entry.catchLoc) {
  853. return handle(entry.catchLoc, true);
  854. } else if (this.prev < entry.finallyLoc) {
  855. return handle(entry.finallyLoc);
  856. }
  857. } else if (hasCatch) {
  858. if (this.prev < entry.catchLoc) {
  859. return handle(entry.catchLoc, true);
  860. }
  861. } else if (hasFinally) {
  862. if (this.prev < entry.finallyLoc) {
  863. return handle(entry.finallyLoc);
  864. }
  865. } else {
  866. throw new Error("try statement without catch or finally");
  867. }
  868. }
  869. }
  870. },
  871. abrupt: function(type, arg) {
  872. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  873. var entry = this.tryEntries[i];
  874. if (entry.tryLoc <= this.prev &&
  875. hasOwn.call(entry, "finallyLoc") &&
  876. this.prev < entry.finallyLoc) {
  877. var finallyEntry = entry;
  878. break;
  879. }
  880. }
  881. if (finallyEntry &&
  882. (type === "break" ||
  883. type === "continue") &&
  884. finallyEntry.tryLoc <= arg &&
  885. arg <= finallyEntry.finallyLoc) {
  886. // Ignore the finally entry if control is not jumping to a
  887. // location outside the try/catch block.
  888. finallyEntry = null;
  889. }
  890. var record = finallyEntry ? finallyEntry.completion : {};
  891. record.type = type;
  892. record.arg = arg;
  893. if (finallyEntry) {
  894. this.method = "next";
  895. this.next = finallyEntry.finallyLoc;
  896. return ContinueSentinel;
  897. }
  898. return this.complete(record);
  899. },
  900. complete: function(record, afterLoc) {
  901. if (record.type === "throw") {
  902. throw record.arg;
  903. }
  904. if (record.type === "break" ||
  905. record.type === "continue") {
  906. this.next = record.arg;
  907. } else if (record.type === "return") {
  908. this.rval = this.arg = record.arg;
  909. this.method = "return";
  910. this.next = "end";
  911. } else if (record.type === "normal" && afterLoc) {
  912. this.next = afterLoc;
  913. }
  914. return ContinueSentinel;
  915. },
  916. finish: function(finallyLoc) {
  917. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  918. var entry = this.tryEntries[i];
  919. if (entry.finallyLoc === finallyLoc) {
  920. this.complete(entry.completion, entry.afterLoc);
  921. resetTryEntry(entry);
  922. return ContinueSentinel;
  923. }
  924. }
  925. },
  926. "catch": function(tryLoc) {
  927. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  928. var entry = this.tryEntries[i];
  929. if (entry.tryLoc === tryLoc) {
  930. var record = entry.completion;
  931. if (record.type === "throw") {
  932. var thrown = record.arg;
  933. resetTryEntry(entry);
  934. }
  935. return thrown;
  936. }
  937. }
  938. // The context.catch method must only be called with a location
  939. // argument that corresponds to a known catch block.
  940. throw new Error("illegal catch attempt");
  941. },
  942. delegateYield: function(iterable, resultName, nextLoc) {
  943. this.delegate = {
  944. iterator: values(iterable),
  945. resultName: resultName,
  946. nextLoc: nextLoc
  947. };
  948. if (this.method === "next") {
  949. // Deliberately forget the last sent value so that we don't
  950. // accidentally pass it on to the delegate.
  951. this.arg = undefined;
  952. }
  953. return ContinueSentinel;
  954. }
  955. };
  956. // Regardless of whether this script is executing as a CommonJS module
  957. // or not, return the runtime object so that we can declare the variable
  958. // regeneratorRuntime in the outer scope, which allows this module to be
  959. // injected easily by `bin/regenerator --include-runtime script.js`.
  960. return exports;
  961. }(
  962. // If this script is executing as a CommonJS module, use module.exports
  963. // as the regeneratorRuntime namespace. Otherwise create a new empty
  964. // object. Either way, the resulting object will be used to initialize
  965. // the regeneratorRuntime variable at the top of this file.
  966. true ? module.exports : undefined
  967. ));
  968. try {
  969. regeneratorRuntime = runtime;
  970. } catch (accidentalStrictMode) {
  971. // This module should not be running in strict mode, so the above
  972. // assignment should always work unless something is misconfigured. Just
  973. // in case runtime.js accidentally runs in strict mode, we can escape
  974. // strict mode using a global Function call. This could conceivably fail
  975. // if a Content Security Policy forbids using Function, but in that case
  976. // the proper solution is to fix the accidental strict mode problem. If
  977. // you've misconfigured your bundler to force strict mode and applied a
  978. // CSP to forbid Function, and you're not willing to fix either of those
  979. // problems, please detail your unique predicament in a GitHub issue.
  980. Function("r", "regeneratorRuntime = r")(runtime);
  981. }
  982. /***/ })
  983. /******/ })["default"];