helpers.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _template() {
  7. const data = _interopRequireDefault(require("@babel/template"));
  8. _template = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. const helpers = Object.create(null);
  15. var _default = helpers;
  16. exports.default = _default;
  17. const helper = minVersion => tpl => ({
  18. minVersion,
  19. ast: () => _template().default.program.ast(tpl)
  20. });
  21. helpers.typeof = helper("7.0.0-beta.0")`
  22. export default function _typeof(obj) {
  23. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  24. _typeof = function (obj) { return typeof obj; };
  25. } else {
  26. _typeof = function (obj) {
  27. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype
  28. ? "symbol"
  29. : typeof obj;
  30. };
  31. }
  32. return _typeof(obj);
  33. }
  34. `;
  35. helpers.jsx = helper("7.0.0-beta.0")`
  36. var REACT_ELEMENT_TYPE;
  37. export default function _createRawReactElement(type, props, key, children) {
  38. if (!REACT_ELEMENT_TYPE) {
  39. REACT_ELEMENT_TYPE = (
  40. typeof Symbol === "function" && Symbol["for"] && Symbol["for"]("react.element")
  41. ) || 0xeac7;
  42. }
  43. var defaultProps = type && type.defaultProps;
  44. var childrenLength = arguments.length - 3;
  45. if (!props && childrenLength !== 0) {
  46. // If we're going to assign props.children, we create a new object now
  47. // to avoid mutating defaultProps.
  48. props = {
  49. children: void 0,
  50. };
  51. }
  52. if (props && defaultProps) {
  53. for (var propName in defaultProps) {
  54. if (props[propName] === void 0) {
  55. props[propName] = defaultProps[propName];
  56. }
  57. }
  58. } else if (!props) {
  59. props = defaultProps || {};
  60. }
  61. if (childrenLength === 1) {
  62. props.children = children;
  63. } else if (childrenLength > 1) {
  64. var childArray = new Array(childrenLength);
  65. for (var i = 0; i < childrenLength; i++) {
  66. childArray[i] = arguments[i + 3];
  67. }
  68. props.children = childArray;
  69. }
  70. return {
  71. $$typeof: REACT_ELEMENT_TYPE,
  72. type: type,
  73. key: key === undefined ? null : '' + key,
  74. ref: null,
  75. props: props,
  76. _owner: null,
  77. };
  78. }
  79. `;
  80. helpers.asyncIterator = helper("7.0.0-beta.0")`
  81. export default function _asyncIterator(iterable) {
  82. var method
  83. if (typeof Symbol !== "undefined") {
  84. if (Symbol.asyncIterator) {
  85. method = iterable[Symbol.asyncIterator]
  86. if (method != null) return method.call(iterable);
  87. }
  88. if (Symbol.iterator) {
  89. method = iterable[Symbol.iterator]
  90. if (method != null) return method.call(iterable);
  91. }
  92. }
  93. throw new TypeError("Object is not async iterable");
  94. }
  95. `;
  96. helpers.AwaitValue = helper("7.0.0-beta.0")`
  97. export default function _AwaitValue(value) {
  98. this.wrapped = value;
  99. }
  100. `;
  101. helpers.AsyncGenerator = helper("7.0.0-beta.0")`
  102. import AwaitValue from "AwaitValue";
  103. export default function AsyncGenerator(gen) {
  104. var front, back;
  105. function send(key, arg) {
  106. return new Promise(function (resolve, reject) {
  107. var request = {
  108. key: key,
  109. arg: arg,
  110. resolve: resolve,
  111. reject: reject,
  112. next: null,
  113. };
  114. if (back) {
  115. back = back.next = request;
  116. } else {
  117. front = back = request;
  118. resume(key, arg);
  119. }
  120. });
  121. }
  122. function resume(key, arg) {
  123. try {
  124. var result = gen[key](arg)
  125. var value = result.value;
  126. var wrappedAwait = value instanceof AwaitValue;
  127. Promise.resolve(wrappedAwait ? value.wrapped : value).then(
  128. function (arg) {
  129. if (wrappedAwait) {
  130. resume("next", arg);
  131. return
  132. }
  133. settle(result.done ? "return" : "normal", arg);
  134. },
  135. function (err) { resume("throw", err); });
  136. } catch (err) {
  137. settle("throw", err);
  138. }
  139. }
  140. function settle(type, value) {
  141. switch (type) {
  142. case "return":
  143. front.resolve({ value: value, done: true });
  144. break;
  145. case "throw":
  146. front.reject(value);
  147. break;
  148. default:
  149. front.resolve({ value: value, done: false });
  150. break;
  151. }
  152. front = front.next;
  153. if (front) {
  154. resume(front.key, front.arg);
  155. } else {
  156. back = null;
  157. }
  158. }
  159. this._invoke = send;
  160. // Hide "return" method if generator return is not supported
  161. if (typeof gen.return !== "function") {
  162. this.return = undefined;
  163. }
  164. }
  165. if (typeof Symbol === "function" && Symbol.asyncIterator) {
  166. AsyncGenerator.prototype[Symbol.asyncIterator] = function () { return this; };
  167. }
  168. AsyncGenerator.prototype.next = function (arg) { return this._invoke("next", arg); };
  169. AsyncGenerator.prototype.throw = function (arg) { return this._invoke("throw", arg); };
  170. AsyncGenerator.prototype.return = function (arg) { return this._invoke("return", arg); };
  171. `;
  172. helpers.wrapAsyncGenerator = helper("7.0.0-beta.0")`
  173. import AsyncGenerator from "AsyncGenerator";
  174. export default function _wrapAsyncGenerator(fn) {
  175. return function () {
  176. return new AsyncGenerator(fn.apply(this, arguments));
  177. };
  178. }
  179. `;
  180. helpers.awaitAsyncGenerator = helper("7.0.0-beta.0")`
  181. import AwaitValue from "AwaitValue";
  182. export default function _awaitAsyncGenerator(value) {
  183. return new AwaitValue(value);
  184. }
  185. `;
  186. helpers.asyncGeneratorDelegate = helper("7.0.0-beta.0")`
  187. export default function _asyncGeneratorDelegate(inner, awaitWrap) {
  188. var iter = {}, waiting = false;
  189. function pump(key, value) {
  190. waiting = true;
  191. value = new Promise(function (resolve) { resolve(inner[key](value)); });
  192. return { done: false, value: awaitWrap(value) };
  193. };
  194. if (typeof Symbol === "function" && Symbol.iterator) {
  195. iter[Symbol.iterator] = function () { return this; };
  196. }
  197. iter.next = function (value) {
  198. if (waiting) {
  199. waiting = false;
  200. return value;
  201. }
  202. return pump("next", value);
  203. };
  204. if (typeof inner.throw === "function") {
  205. iter.throw = function (value) {
  206. if (waiting) {
  207. waiting = false;
  208. throw value;
  209. }
  210. return pump("throw", value);
  211. };
  212. }
  213. if (typeof inner.return === "function") {
  214. iter.return = function (value) {
  215. return pump("return", value);
  216. };
  217. }
  218. return iter;
  219. }
  220. `;
  221. helpers.asyncToGenerator = helper("7.0.0-beta.0")`
  222. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  223. try {
  224. var info = gen[key](arg);
  225. var value = info.value;
  226. } catch (error) {
  227. reject(error);
  228. return;
  229. }
  230. if (info.done) {
  231. resolve(value);
  232. } else {
  233. Promise.resolve(value).then(_next, _throw);
  234. }
  235. }
  236. export default function _asyncToGenerator(fn) {
  237. return function () {
  238. var self = this, args = arguments;
  239. return new Promise(function (resolve, reject) {
  240. var gen = fn.apply(self, args);
  241. function _next(value) {
  242. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
  243. }
  244. function _throw(err) {
  245. asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
  246. }
  247. _next(undefined);
  248. });
  249. };
  250. }
  251. `;
  252. helpers.classCallCheck = helper("7.0.0-beta.0")`
  253. export default function _classCallCheck(instance, Constructor) {
  254. if (!(instance instanceof Constructor)) {
  255. throw new TypeError("Cannot call a class as a function");
  256. }
  257. }
  258. `;
  259. helpers.createClass = helper("7.0.0-beta.0")`
  260. function _defineProperties(target, props) {
  261. for (var i = 0; i < props.length; i ++) {
  262. var descriptor = props[i];
  263. descriptor.enumerable = descriptor.enumerable || false;
  264. descriptor.configurable = true;
  265. if ("value" in descriptor) descriptor.writable = true;
  266. Object.defineProperty(target, descriptor.key, descriptor);
  267. }
  268. }
  269. export default function _createClass(Constructor, protoProps, staticProps) {
  270. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  271. if (staticProps) _defineProperties(Constructor, staticProps);
  272. return Constructor;
  273. }
  274. `;
  275. helpers.defineEnumerableProperties = helper("7.0.0-beta.0")`
  276. export default function _defineEnumerableProperties(obj, descs) {
  277. for (var key in descs) {
  278. var desc = descs[key];
  279. desc.configurable = desc.enumerable = true;
  280. if ("value" in desc) desc.writable = true;
  281. Object.defineProperty(obj, key, desc);
  282. }
  283. // Symbols are not enumerated over by for-in loops. If native
  284. // Symbols are available, fetch all of the descs object's own
  285. // symbol properties and define them on our target object too.
  286. if (Object.getOwnPropertySymbols) {
  287. var objectSymbols = Object.getOwnPropertySymbols(descs);
  288. for (var i = 0; i < objectSymbols.length; i++) {
  289. var sym = objectSymbols[i];
  290. var desc = descs[sym];
  291. desc.configurable = desc.enumerable = true;
  292. if ("value" in desc) desc.writable = true;
  293. Object.defineProperty(obj, sym, desc);
  294. }
  295. }
  296. return obj;
  297. }
  298. `;
  299. helpers.defaults = helper("7.0.0-beta.0")`
  300. export default function _defaults(obj, defaults) {
  301. var keys = Object.getOwnPropertyNames(defaults);
  302. for (var i = 0; i < keys.length; i++) {
  303. var key = keys[i];
  304. var value = Object.getOwnPropertyDescriptor(defaults, key);
  305. if (value && value.configurable && obj[key] === undefined) {
  306. Object.defineProperty(obj, key, value);
  307. }
  308. }
  309. return obj;
  310. }
  311. `;
  312. helpers.defineProperty = helper("7.0.0-beta.0")`
  313. export default function _defineProperty(obj, key, value) {
  314. // Shortcircuit the slow defineProperty path when possible.
  315. // We are trying to avoid issues where setters defined on the
  316. // prototype cause side effects under the fast path of simple
  317. // assignment. By checking for existence of the property with
  318. // the in operator, we can optimize most of this overhead away.
  319. if (key in obj) {
  320. Object.defineProperty(obj, key, {
  321. value: value,
  322. enumerable: true,
  323. configurable: true,
  324. writable: true
  325. });
  326. } else {
  327. obj[key] = value;
  328. }
  329. return obj;
  330. }
  331. `;
  332. helpers.extends = helper("7.0.0-beta.0")`
  333. export default function _extends() {
  334. _extends = Object.assign || function (target) {
  335. for (var i = 1; i < arguments.length; i++) {
  336. var source = arguments[i];
  337. for (var key in source) {
  338. if (Object.prototype.hasOwnProperty.call(source, key)) {
  339. target[key] = source[key];
  340. }
  341. }
  342. }
  343. return target;
  344. };
  345. return _extends.apply(this, arguments);
  346. }
  347. `;
  348. helpers.objectSpread = helper("7.0.0-beta.0")`
  349. import defineProperty from "defineProperty";
  350. export default function _objectSpread(target) {
  351. for (var i = 1; i < arguments.length; i++) {
  352. var source = (arguments[i] != null) ? arguments[i] : {};
  353. var ownKeys = Object.keys(source);
  354. if (typeof Object.getOwnPropertySymbols === 'function') {
  355. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
  356. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  357. }));
  358. }
  359. ownKeys.forEach(function(key) {
  360. defineProperty(target, key, source[key]);
  361. });
  362. }
  363. return target;
  364. }
  365. `;
  366. helpers.objectSpread2 = helper("7.5.0")`
  367. import defineProperty from "defineProperty";
  368. function ownKeys(object, enumerableOnly) {
  369. var keys = Object.keys(object);
  370. if (Object.getOwnPropertySymbols) {
  371. keys.push.apply(keys, Object.getOwnPropertySymbols(object));
  372. }
  373. if (enumerableOnly) keys = keys.filter(function (sym) {
  374. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  375. });
  376. return keys;
  377. }
  378. export default function _objectSpread2(target) {
  379. for (var i = 1; i < arguments.length; i++) {
  380. var source = (arguments[i] != null) ? arguments[i] : {};
  381. if (i % 2) {
  382. ownKeys(source, true).forEach(function (key) {
  383. defineProperty(target, key, source[key]);
  384. });
  385. } else if (Object.getOwnPropertyDescriptors) {
  386. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  387. } else {
  388. ownKeys(source).forEach(function (key) {
  389. Object.defineProperty(
  390. target,
  391. key,
  392. Object.getOwnPropertyDescriptor(source, key)
  393. );
  394. });
  395. }
  396. }
  397. return target;
  398. }
  399. `;
  400. helpers.inherits = helper("7.0.0-beta.0")`
  401. import setPrototypeOf from "setPrototypeOf";
  402. export default function _inherits(subClass, superClass) {
  403. if (typeof superClass !== "function" && superClass !== null) {
  404. throw new TypeError("Super expression must either be null or a function");
  405. }
  406. subClass.prototype = Object.create(superClass && superClass.prototype, {
  407. constructor: {
  408. value: subClass,
  409. writable: true,
  410. configurable: true
  411. }
  412. });
  413. if (superClass) setPrototypeOf(subClass, superClass);
  414. }
  415. `;
  416. helpers.inheritsLoose = helper("7.0.0-beta.0")`
  417. export default function _inheritsLoose(subClass, superClass) {
  418. subClass.prototype = Object.create(superClass.prototype);
  419. subClass.prototype.constructor = subClass;
  420. subClass.__proto__ = superClass;
  421. }
  422. `;
  423. helpers.getPrototypeOf = helper("7.0.0-beta.0")`
  424. export default function _getPrototypeOf(o) {
  425. _getPrototypeOf = Object.setPrototypeOf
  426. ? Object.getPrototypeOf
  427. : function _getPrototypeOf(o) {
  428. return o.__proto__ || Object.getPrototypeOf(o);
  429. };
  430. return _getPrototypeOf(o);
  431. }
  432. `;
  433. helpers.setPrototypeOf = helper("7.0.0-beta.0")`
  434. export default function _setPrototypeOf(o, p) {
  435. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  436. o.__proto__ = p;
  437. return o;
  438. };
  439. return _setPrototypeOf(o, p);
  440. }
  441. `;
  442. helpers.construct = helper("7.0.0-beta.0")`
  443. import setPrototypeOf from "setPrototypeOf";
  444. function isNativeReflectConstruct() {
  445. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  446. // core-js@3
  447. if (Reflect.construct.sham) return false;
  448. // Proxy can't be polyfilled. Every browser implemented
  449. // proxies before or at the same time as Reflect.construct,
  450. // so if they support Proxy they also support Reflect.construct.
  451. if (typeof Proxy === "function") return true;
  452. // Since Reflect.construct can't be properly polyfilled, some
  453. // implementations (e.g. core-js@2) don't set the correct internal slots.
  454. // Those polyfills don't allow us to subclass built-ins, so we need to
  455. // use our fallback implementation.
  456. try {
  457. // If the internal slots aren't set, this throws an error similar to
  458. // TypeError: this is not a Date object.
  459. Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
  460. return true;
  461. } catch (e) {
  462. return false;
  463. }
  464. }
  465. export default function _construct(Parent, args, Class) {
  466. if (isNativeReflectConstruct()) {
  467. _construct = Reflect.construct;
  468. } else {
  469. // NOTE: If Parent !== Class, the correct __proto__ is set *after*
  470. // calling the constructor.
  471. _construct = function _construct(Parent, args, Class) {
  472. var a = [null];
  473. a.push.apply(a, args);
  474. var Constructor = Function.bind.apply(Parent, a);
  475. var instance = new Constructor();
  476. if (Class) setPrototypeOf(instance, Class.prototype);
  477. return instance;
  478. };
  479. }
  480. // Avoid issues with Class being present but undefined when it wasn't
  481. // present in the original call.
  482. return _construct.apply(null, arguments);
  483. }
  484. `;
  485. helpers.isNativeFunction = helper("7.0.0-beta.0")`
  486. export default function _isNativeFunction(fn) {
  487. // Note: This function returns "true" for core-js functions.
  488. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  489. }
  490. `;
  491. helpers.wrapNativeSuper = helper("7.0.0-beta.0")`
  492. import getPrototypeOf from "getPrototypeOf";
  493. import setPrototypeOf from "setPrototypeOf";
  494. import isNativeFunction from "isNativeFunction";
  495. import construct from "construct";
  496. export default function _wrapNativeSuper(Class) {
  497. var _cache = typeof Map === "function" ? new Map() : undefined;
  498. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  499. if (Class === null || !isNativeFunction(Class)) return Class;
  500. if (typeof Class !== "function") {
  501. throw new TypeError("Super expression must either be null or a function");
  502. }
  503. if (typeof _cache !== "undefined") {
  504. if (_cache.has(Class)) return _cache.get(Class);
  505. _cache.set(Class, Wrapper);
  506. }
  507. function Wrapper() {
  508. return construct(Class, arguments, getPrototypeOf(this).constructor)
  509. }
  510. Wrapper.prototype = Object.create(Class.prototype, {
  511. constructor: {
  512. value: Wrapper,
  513. enumerable: false,
  514. writable: true,
  515. configurable: true,
  516. }
  517. });
  518. return setPrototypeOf(Wrapper, Class);
  519. }
  520. return _wrapNativeSuper(Class)
  521. }
  522. `;
  523. helpers.instanceof = helper("7.0.0-beta.0")`
  524. export default function _instanceof(left, right) {
  525. if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
  526. return right[Symbol.hasInstance](left);
  527. } else {
  528. return left instanceof right;
  529. }
  530. }
  531. `;
  532. helpers.interopRequireDefault = helper("7.0.0-beta.0")`
  533. export default function _interopRequireDefault(obj) {
  534. return obj && obj.__esModule ? obj : { default: obj };
  535. }
  536. `;
  537. helpers.interopRequireWildcard = helper("7.0.0-beta.0")`
  538. export default function _interopRequireWildcard(obj) {
  539. if (obj && obj.__esModule) {
  540. return obj;
  541. } else {
  542. var newObj = {};
  543. if (obj != null) {
  544. for (var key in obj) {
  545. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  546. var desc = Object.defineProperty && Object.getOwnPropertyDescriptor
  547. ? Object.getOwnPropertyDescriptor(obj, key)
  548. : {};
  549. if (desc.get || desc.set) {
  550. Object.defineProperty(newObj, key, desc);
  551. } else {
  552. newObj[key] = obj[key];
  553. }
  554. }
  555. }
  556. }
  557. newObj.default = obj;
  558. return newObj;
  559. }
  560. }
  561. `;
  562. helpers.newArrowCheck = helper("7.0.0-beta.0")`
  563. export default function _newArrowCheck(innerThis, boundThis) {
  564. if (innerThis !== boundThis) {
  565. throw new TypeError("Cannot instantiate an arrow function");
  566. }
  567. }
  568. `;
  569. helpers.objectDestructuringEmpty = helper("7.0.0-beta.0")`
  570. export default function _objectDestructuringEmpty(obj) {
  571. if (obj == null) throw new TypeError("Cannot destructure undefined");
  572. }
  573. `;
  574. helpers.objectWithoutPropertiesLoose = helper("7.0.0-beta.0")`
  575. export default function _objectWithoutPropertiesLoose(source, excluded) {
  576. if (source == null) return {};
  577. var target = {};
  578. var sourceKeys = Object.keys(source);
  579. var key, i;
  580. for (i = 0; i < sourceKeys.length; i++) {
  581. key = sourceKeys[i];
  582. if (excluded.indexOf(key) >= 0) continue;
  583. target[key] = source[key];
  584. }
  585. return target;
  586. }
  587. `;
  588. helpers.objectWithoutProperties = helper("7.0.0-beta.0")`
  589. import objectWithoutPropertiesLoose from "objectWithoutPropertiesLoose";
  590. export default function _objectWithoutProperties(source, excluded) {
  591. if (source == null) return {};
  592. var target = objectWithoutPropertiesLoose(source, excluded);
  593. var key, i;
  594. if (Object.getOwnPropertySymbols) {
  595. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  596. for (i = 0; i < sourceSymbolKeys.length; i++) {
  597. key = sourceSymbolKeys[i];
  598. if (excluded.indexOf(key) >= 0) continue;
  599. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  600. target[key] = source[key];
  601. }
  602. }
  603. return target;
  604. }
  605. `;
  606. helpers.assertThisInitialized = helper("7.0.0-beta.0")`
  607. export default function _assertThisInitialized(self) {
  608. if (self === void 0) {
  609. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  610. }
  611. return self;
  612. }
  613. `;
  614. helpers.possibleConstructorReturn = helper("7.0.0-beta.0")`
  615. import assertThisInitialized from "assertThisInitialized";
  616. export default function _possibleConstructorReturn(self, call) {
  617. if (call && (typeof call === "object" || typeof call === "function")) {
  618. return call;
  619. }
  620. return assertThisInitialized(self);
  621. }
  622. `;
  623. helpers.superPropBase = helper("7.0.0-beta.0")`
  624. import getPrototypeOf from "getPrototypeOf";
  625. export default function _superPropBase(object, property) {
  626. // Yes, this throws if object is null to being with, that's on purpose.
  627. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  628. object = getPrototypeOf(object);
  629. if (object === null) break;
  630. }
  631. return object;
  632. }
  633. `;
  634. helpers.get = helper("7.0.0-beta.0")`
  635. import getPrototypeOf from "getPrototypeOf";
  636. import superPropBase from "superPropBase";
  637. export default function _get(target, property, receiver) {
  638. if (typeof Reflect !== "undefined" && Reflect.get) {
  639. _get = Reflect.get;
  640. } else {
  641. _get = function _get(target, property, receiver) {
  642. var base = superPropBase(target, property);
  643. if (!base) return;
  644. var desc = Object.getOwnPropertyDescriptor(base, property);
  645. if (desc.get) {
  646. return desc.get.call(receiver);
  647. }
  648. return desc.value;
  649. };
  650. }
  651. return _get(target, property, receiver || target);
  652. }
  653. `;
  654. helpers.set = helper("7.0.0-beta.0")`
  655. import getPrototypeOf from "getPrototypeOf";
  656. import superPropBase from "superPropBase";
  657. import defineProperty from "defineProperty";
  658. function set(target, property, value, receiver) {
  659. if (typeof Reflect !== "undefined" && Reflect.set) {
  660. set = Reflect.set;
  661. } else {
  662. set = function set(target, property, value, receiver) {
  663. var base = superPropBase(target, property);
  664. var desc;
  665. if (base) {
  666. desc = Object.getOwnPropertyDescriptor(base, property);
  667. if (desc.set) {
  668. desc.set.call(receiver, value);
  669. return true;
  670. } else if (!desc.writable) {
  671. // Both getter and non-writable fall into this.
  672. return false;
  673. }
  674. }
  675. // Without a super that defines the property, spec boils down to
  676. // "define on receiver" for some reason.
  677. desc = Object.getOwnPropertyDescriptor(receiver, property);
  678. if (desc) {
  679. if (!desc.writable) {
  680. // Setter, getter, and non-writable fall into this.
  681. return false;
  682. }
  683. desc.value = value;
  684. Object.defineProperty(receiver, property, desc);
  685. } else {
  686. // Avoid setters that may be defined on Sub's prototype, but not on
  687. // the instance.
  688. defineProperty(receiver, property, value);
  689. }
  690. return true;
  691. };
  692. }
  693. return set(target, property, value, receiver);
  694. }
  695. export default function _set(target, property, value, receiver, isStrict) {
  696. var s = set(target, property, value, receiver || target);
  697. if (!s && isStrict) {
  698. throw new Error('failed to set property');
  699. }
  700. return value;
  701. }
  702. `;
  703. helpers.taggedTemplateLiteral = helper("7.0.0-beta.0")`
  704. export default function _taggedTemplateLiteral(strings, raw) {
  705. if (!raw) { raw = strings.slice(0); }
  706. return Object.freeze(Object.defineProperties(strings, {
  707. raw: { value: Object.freeze(raw) }
  708. }));
  709. }
  710. `;
  711. helpers.taggedTemplateLiteralLoose = helper("7.0.0-beta.0")`
  712. export default function _taggedTemplateLiteralLoose(strings, raw) {
  713. if (!raw) { raw = strings.slice(0); }
  714. strings.raw = raw;
  715. return strings;
  716. }
  717. `;
  718. helpers.temporalRef = helper("7.0.0-beta.0")`
  719. import undef from "temporalUndefined";
  720. export default function _temporalRef(val, name) {
  721. if (val === undef) {
  722. throw new ReferenceError(name + " is not defined - temporal dead zone");
  723. } else {
  724. return val;
  725. }
  726. }
  727. `;
  728. helpers.readOnlyError = helper("7.0.0-beta.0")`
  729. export default function _readOnlyError(name) {
  730. throw new Error("\\"" + name + "\\" is read-only");
  731. }
  732. `;
  733. helpers.classNameTDZError = helper("7.0.0-beta.0")`
  734. export default function _classNameTDZError(name) {
  735. throw new Error("Class \\"" + name + "\\" cannot be referenced in computed property keys.");
  736. }
  737. `;
  738. helpers.temporalUndefined = helper("7.0.0-beta.0")`
  739. export default {};
  740. `;
  741. helpers.slicedToArray = helper("7.0.0-beta.0")`
  742. import arrayWithHoles from "arrayWithHoles";
  743. import iterableToArrayLimit from "iterableToArrayLimit";
  744. import nonIterableRest from "nonIterableRest";
  745. export default function _slicedToArray(arr, i) {
  746. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || nonIterableRest();
  747. }
  748. `;
  749. helpers.slicedToArrayLoose = helper("7.0.0-beta.0")`
  750. import arrayWithHoles from "arrayWithHoles";
  751. import iterableToArrayLimitLoose from "iterableToArrayLimitLoose";
  752. import nonIterableRest from "nonIterableRest";
  753. export default function _slicedToArrayLoose(arr, i) {
  754. return arrayWithHoles(arr) || iterableToArrayLimitLoose(arr, i) || nonIterableRest();
  755. }
  756. `;
  757. helpers.toArray = helper("7.0.0-beta.0")`
  758. import arrayWithHoles from "arrayWithHoles";
  759. import iterableToArray from "iterableToArray";
  760. import nonIterableRest from "nonIterableRest";
  761. export default function _toArray(arr) {
  762. return arrayWithHoles(arr) || iterableToArray(arr) || nonIterableRest();
  763. }
  764. `;
  765. helpers.toConsumableArray = helper("7.0.0-beta.0")`
  766. import arrayWithoutHoles from "arrayWithoutHoles";
  767. import iterableToArray from "iterableToArray";
  768. import nonIterableSpread from "nonIterableSpread";
  769. export default function _toConsumableArray(arr) {
  770. return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();
  771. }
  772. `;
  773. helpers.arrayWithoutHoles = helper("7.0.0-beta.0")`
  774. export default function _arrayWithoutHoles(arr) {
  775. if (Array.isArray(arr)) {
  776. for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
  777. return arr2;
  778. }
  779. }
  780. `;
  781. helpers.arrayWithHoles = helper("7.0.0-beta.0")`
  782. export default function _arrayWithHoles(arr) {
  783. if (Array.isArray(arr)) return arr;
  784. }
  785. `;
  786. helpers.iterableToArray = helper("7.0.0-beta.0")`
  787. export default function _iterableToArray(iter) {
  788. if (
  789. Symbol.iterator in Object(iter) ||
  790. Object.prototype.toString.call(iter) === "[object Arguments]"
  791. ) return Array.from(iter);
  792. }
  793. `;
  794. helpers.iterableToArrayLimit = helper("7.0.0-beta.0")`
  795. export default function _iterableToArrayLimit(arr, i) {
  796. // this is an expanded form of \`for...of\` that properly supports abrupt completions of
  797. // iterators etc. variable names have been minimised to reduce the size of this massive
  798. // helper. sometimes spec compliancy is annoying :(
  799. //
  800. // _n = _iteratorNormalCompletion
  801. // _d = _didIteratorError
  802. // _e = _iteratorError
  803. // _i = _iterator
  804. // _s = _step
  805. var _arr = [];
  806. var _n = true;
  807. var _d = false;
  808. var _e = undefined;
  809. try {
  810. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  811. _arr.push(_s.value);
  812. if (i && _arr.length === i) break;
  813. }
  814. } catch (err) {
  815. _d = true;
  816. _e = err;
  817. } finally {
  818. try {
  819. if (!_n && _i["return"] != null) _i["return"]();
  820. } finally {
  821. if (_d) throw _e;
  822. }
  823. }
  824. return _arr;
  825. }
  826. `;
  827. helpers.iterableToArrayLimitLoose = helper("7.0.0-beta.0")`
  828. export default function _iterableToArrayLimitLoose(arr, i) {
  829. var _arr = [];
  830. for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
  831. _arr.push(_step.value);
  832. if (i && _arr.length === i) break;
  833. }
  834. return _arr;
  835. }
  836. `;
  837. helpers.nonIterableSpread = helper("7.0.0-beta.0")`
  838. export default function _nonIterableSpread() {
  839. throw new TypeError("Invalid attempt to spread non-iterable instance");
  840. }
  841. `;
  842. helpers.nonIterableRest = helper("7.0.0-beta.0")`
  843. export default function _nonIterableRest() {
  844. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  845. }
  846. `;
  847. helpers.skipFirstGeneratorNext = helper("7.0.0-beta.0")`
  848. export default function _skipFirstGeneratorNext(fn) {
  849. return function () {
  850. var it = fn.apply(this, arguments);
  851. it.next();
  852. return it;
  853. }
  854. }
  855. `;
  856. helpers.toPrimitive = helper("7.1.5")`
  857. export default function _toPrimitive(
  858. input,
  859. hint /*: "default" | "string" | "number" | void */
  860. ) {
  861. if (typeof input !== "object" || input === null) return input;
  862. var prim = input[Symbol.toPrimitive];
  863. if (prim !== undefined) {
  864. var res = prim.call(input, hint || "default");
  865. if (typeof res !== "object") return res;
  866. throw new TypeError("@@toPrimitive must return a primitive value.");
  867. }
  868. return (hint === "string" ? String : Number)(input);
  869. }
  870. `;
  871. helpers.toPropertyKey = helper("7.1.5")`
  872. import toPrimitive from "toPrimitive";
  873. export default function _toPropertyKey(arg) {
  874. var key = toPrimitive(arg, "string");
  875. return typeof key === "symbol" ? key : String(key);
  876. }
  877. `;
  878. helpers.initializerWarningHelper = helper("7.0.0-beta.0")`
  879. export default function _initializerWarningHelper(descriptor, context){
  880. throw new Error(
  881. 'Decorating class property failed. Please ensure that ' +
  882. 'proposal-class-properties is enabled and set to use loose mode. ' +
  883. 'To use proposal-class-properties in spec mode with decorators, wait for ' +
  884. 'the next major version of decorators in stage 2.'
  885. );
  886. }
  887. `;
  888. helpers.initializerDefineProperty = helper("7.0.0-beta.0")`
  889. export default function _initializerDefineProperty(target, property, descriptor, context){
  890. if (!descriptor) return;
  891. Object.defineProperty(target, property, {
  892. enumerable: descriptor.enumerable,
  893. configurable: descriptor.configurable,
  894. writable: descriptor.writable,
  895. value: descriptor.initializer ? descriptor.initializer.call(context) : void 0,
  896. });
  897. }
  898. `;
  899. helpers.applyDecoratedDescriptor = helper("7.0.0-beta.0")`
  900. export default function _applyDecoratedDescriptor(target, property, decorators, descriptor, context){
  901. var desc = {};
  902. Object.keys(descriptor).forEach(function(key){
  903. desc[key] = descriptor[key];
  904. });
  905. desc.enumerable = !!desc.enumerable;
  906. desc.configurable = !!desc.configurable;
  907. if ('value' in desc || desc.initializer){
  908. desc.writable = true;
  909. }
  910. desc = decorators.slice().reverse().reduce(function(desc, decorator){
  911. return decorator(target, property, desc) || desc;
  912. }, desc);
  913. if (context && desc.initializer !== void 0){
  914. desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
  915. desc.initializer = undefined;
  916. }
  917. if (desc.initializer === void 0){
  918. // This is a hack to avoid this being processed by 'transform-runtime'.
  919. // See issue #9.
  920. Object.defineProperty(target, property, desc);
  921. desc = null;
  922. }
  923. return desc;
  924. }
  925. `;
  926. helpers.classPrivateFieldLooseKey = helper("7.0.0-beta.0")`
  927. var id = 0;
  928. export default function _classPrivateFieldKey(name) {
  929. return "__private_" + (id++) + "_" + name;
  930. }
  931. `;
  932. helpers.classPrivateFieldLooseBase = helper("7.0.0-beta.0")`
  933. export default function _classPrivateFieldBase(receiver, privateKey) {
  934. if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
  935. throw new TypeError("attempted to use private field on non-instance");
  936. }
  937. return receiver;
  938. }
  939. `;
  940. helpers.classPrivateFieldGet = helper("7.0.0-beta.0")`
  941. export default function _classPrivateFieldGet(receiver, privateMap) {
  942. var descriptor = privateMap.get(receiver);
  943. if (!descriptor) {
  944. throw new TypeError("attempted to get private field on non-instance");
  945. }
  946. if (descriptor.get) {
  947. return descriptor.get.call(receiver);
  948. }
  949. return descriptor.value;
  950. }
  951. `;
  952. helpers.classPrivateFieldSet = helper("7.0.0-beta.0")`
  953. export default function _classPrivateFieldSet(receiver, privateMap, value) {
  954. var descriptor = privateMap.get(receiver);
  955. if (!descriptor) {
  956. throw new TypeError("attempted to set private field on non-instance");
  957. }
  958. if (descriptor.set) {
  959. descriptor.set.call(receiver, value);
  960. } else {
  961. if (!descriptor.writable) {
  962. // This should only throw in strict mode, but class bodies are
  963. // always strict and private fields can only be used inside
  964. // class bodies.
  965. throw new TypeError("attempted to set read only private field");
  966. }
  967. descriptor.value = value;
  968. }
  969. return value;
  970. }
  971. `;
  972. helpers.classStaticPrivateFieldSpecGet = helper("7.0.2")`
  973. export default function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
  974. if (receiver !== classConstructor) {
  975. throw new TypeError("Private static access of wrong provenance");
  976. }
  977. return descriptor.value;
  978. }
  979. `;
  980. helpers.classStaticPrivateFieldSpecSet = helper("7.0.2")`
  981. export default function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) {
  982. if (receiver !== classConstructor) {
  983. throw new TypeError("Private static access of wrong provenance");
  984. }
  985. if (!descriptor.writable) {
  986. // This should only throw in strict mode, but class bodies are
  987. // always strict and private fields can only be used inside
  988. // class bodies.
  989. throw new TypeError("attempted to set read only private field");
  990. }
  991. descriptor.value = value;
  992. return value;
  993. }
  994. `;
  995. helpers.classStaticPrivateMethodGet = helper("7.3.2")`
  996. export default function _classStaticPrivateMethodGet(receiver, classConstructor, method) {
  997. if (receiver !== classConstructor) {
  998. throw new TypeError("Private static access of wrong provenance");
  999. }
  1000. return method;
  1001. }
  1002. `;
  1003. helpers.classStaticPrivateMethodSet = helper("7.3.2")`
  1004. export default function _classStaticPrivateMethodSet() {
  1005. throw new TypeError("attempted to set read only static private field");
  1006. }
  1007. `;
  1008. helpers.decorate = helper("7.1.5")`
  1009. import toArray from "toArray";
  1010. import toPropertyKey from "toPropertyKey";
  1011. // These comments are stripped by @babel/template
  1012. /*::
  1013. type PropertyDescriptor =
  1014. | {
  1015. value: any,
  1016. writable: boolean,
  1017. configurable: boolean,
  1018. enumerable: boolean,
  1019. }
  1020. | {
  1021. get?: () => any,
  1022. set?: (v: any) => void,
  1023. configurable: boolean,
  1024. enumerable: boolean,
  1025. };
  1026. type FieldDescriptor ={
  1027. writable: boolean,
  1028. configurable: boolean,
  1029. enumerable: boolean,
  1030. };
  1031. type Placement = "static" | "prototype" | "own";
  1032. type Key = string | symbol; // PrivateName is not supported yet.
  1033. type ElementDescriptor =
  1034. | {
  1035. kind: "method",
  1036. key: Key,
  1037. placement: Placement,
  1038. descriptor: PropertyDescriptor
  1039. }
  1040. | {
  1041. kind: "field",
  1042. key: Key,
  1043. placement: Placement,
  1044. descriptor: FieldDescriptor,
  1045. initializer?: () => any,
  1046. };
  1047. // This is exposed to the user code
  1048. type ElementObjectInput = ElementDescriptor & {
  1049. [@@toStringTag]?: "Descriptor"
  1050. };
  1051. // This is exposed to the user code
  1052. type ElementObjectOutput = ElementDescriptor & {
  1053. [@@toStringTag]?: "Descriptor"
  1054. extras?: ElementDescriptor[],
  1055. finisher?: ClassFinisher,
  1056. };
  1057. // This is exposed to the user code
  1058. type ClassObject = {
  1059. [@@toStringTag]?: "Descriptor",
  1060. kind: "class",
  1061. elements: ElementDescriptor[],
  1062. };
  1063. type ElementDecorator = (descriptor: ElementObjectInput) => ?ElementObjectOutput;
  1064. type ClassDecorator = (descriptor: ClassObject) => ?ClassObject;
  1065. type ClassFinisher = <A, B>(cl: Class<A>) => Class<B>;
  1066. // Only used by Babel in the transform output, not part of the spec.
  1067. type ElementDefinition =
  1068. | {
  1069. kind: "method",
  1070. value: any,
  1071. key: Key,
  1072. static?: boolean,
  1073. decorators?: ElementDecorator[],
  1074. }
  1075. | {
  1076. kind: "field",
  1077. value: () => any,
  1078. key: Key,
  1079. static?: boolean,
  1080. decorators?: ElementDecorator[],
  1081. };
  1082. declare function ClassFactory<C>(initialize: (instance: C) => void): {
  1083. F: Class<C>,
  1084. d: ElementDefinition[]
  1085. }
  1086. */
  1087. /*::
  1088. // Various combinations with/without extras and with one or many finishers
  1089. type ElementFinisherExtras = {
  1090. element: ElementDescriptor,
  1091. finisher?: ClassFinisher,
  1092. extras?: ElementDescriptor[],
  1093. };
  1094. type ElementFinishersExtras = {
  1095. element: ElementDescriptor,
  1096. finishers: ClassFinisher[],
  1097. extras: ElementDescriptor[],
  1098. };
  1099. type ElementsFinisher = {
  1100. elements: ElementDescriptor[],
  1101. finisher?: ClassFinisher,
  1102. };
  1103. type ElementsFinishers = {
  1104. elements: ElementDescriptor[],
  1105. finishers: ClassFinisher[],
  1106. };
  1107. */
  1108. /*::
  1109. type Placements = {
  1110. static: Key[],
  1111. prototype: Key[],
  1112. own: Key[],
  1113. };
  1114. */
  1115. // ClassDefinitionEvaluation (Steps 26-*)
  1116. export default function _decorate(
  1117. decorators /*: ClassDecorator[] */,
  1118. factory /*: ClassFactory */,
  1119. superClass /*: ?Class<*> */,
  1120. mixins /*: ?Array<Function> */,
  1121. ) /*: Class<*> */ {
  1122. var api = _getDecoratorsApi();
  1123. if (mixins) {
  1124. for (var i = 0; i < mixins.length; i++) {
  1125. api = mixins[i](api);
  1126. }
  1127. }
  1128. var r = factory(function initialize(O) {
  1129. api.initializeInstanceElements(O, decorated.elements);
  1130. }, superClass);
  1131. var decorated = api.decorateClass(
  1132. _coalesceClassElements(r.d.map(_createElementDescriptor)),
  1133. decorators,
  1134. );
  1135. api.initializeClassElements(r.F, decorated.elements);
  1136. return api.runClassFinishers(r.F, decorated.finishers);
  1137. }
  1138. function _getDecoratorsApi() {
  1139. _getDecoratorsApi = function() {
  1140. return api;
  1141. };
  1142. var api = {
  1143. elementsDefinitionOrder: [["method"], ["field"]],
  1144. // InitializeInstanceElements
  1145. initializeInstanceElements: function(
  1146. /*::<C>*/ O /*: C */,
  1147. elements /*: ElementDescriptor[] */,
  1148. ) {
  1149. ["method", "field"].forEach(function(kind) {
  1150. elements.forEach(function(element /*: ElementDescriptor */) {
  1151. if (element.kind === kind && element.placement === "own") {
  1152. this.defineClassElement(O, element);
  1153. }
  1154. }, this);
  1155. }, this);
  1156. },
  1157. // InitializeClassElements
  1158. initializeClassElements: function(
  1159. /*::<C>*/ F /*: Class<C> */,
  1160. elements /*: ElementDescriptor[] */,
  1161. ) {
  1162. var proto = F.prototype;
  1163. ["method", "field"].forEach(function(kind) {
  1164. elements.forEach(function(element /*: ElementDescriptor */) {
  1165. var placement = element.placement;
  1166. if (
  1167. element.kind === kind &&
  1168. (placement === "static" || placement === "prototype")
  1169. ) {
  1170. var receiver = placement === "static" ? F : proto;
  1171. this.defineClassElement(receiver, element);
  1172. }
  1173. }, this);
  1174. }, this);
  1175. },
  1176. // DefineClassElement
  1177. defineClassElement: function(
  1178. /*::<C>*/ receiver /*: C | Class<C> */,
  1179. element /*: ElementDescriptor */,
  1180. ) {
  1181. var descriptor /*: PropertyDescriptor */ = element.descriptor;
  1182. if (element.kind === "field") {
  1183. var initializer = element.initializer;
  1184. descriptor = {
  1185. enumerable: descriptor.enumerable,
  1186. writable: descriptor.writable,
  1187. configurable: descriptor.configurable,
  1188. value: initializer === void 0 ? void 0 : initializer.call(receiver),
  1189. };
  1190. }
  1191. Object.defineProperty(receiver, element.key, descriptor);
  1192. },
  1193. // DecorateClass
  1194. decorateClass: function(
  1195. elements /*: ElementDescriptor[] */,
  1196. decorators /*: ClassDecorator[] */,
  1197. ) /*: ElementsFinishers */ {
  1198. var newElements /*: ElementDescriptor[] */ = [];
  1199. var finishers /*: ClassFinisher[] */ = [];
  1200. var placements /*: Placements */ = {
  1201. static: [],
  1202. prototype: [],
  1203. own: [],
  1204. };
  1205. elements.forEach(function(element /*: ElementDescriptor */) {
  1206. this.addElementPlacement(element, placements);
  1207. }, this);
  1208. elements.forEach(function(element /*: ElementDescriptor */) {
  1209. if (!_hasDecorators(element)) return newElements.push(element);
  1210. var elementFinishersExtras /*: ElementFinishersExtras */ = this.decorateElement(
  1211. element,
  1212. placements,
  1213. );
  1214. newElements.push(elementFinishersExtras.element);
  1215. newElements.push.apply(newElements, elementFinishersExtras.extras);
  1216. finishers.push.apply(finishers, elementFinishersExtras.finishers);
  1217. }, this);
  1218. if (!decorators) {
  1219. return { elements: newElements, finishers: finishers };
  1220. }
  1221. var result /*: ElementsFinishers */ = this.decorateConstructor(
  1222. newElements,
  1223. decorators,
  1224. );
  1225. finishers.push.apply(finishers, result.finishers);
  1226. result.finishers = finishers;
  1227. return result;
  1228. },
  1229. // AddElementPlacement
  1230. addElementPlacement: function(
  1231. element /*: ElementDescriptor */,
  1232. placements /*: Placements */,
  1233. silent /*: boolean */,
  1234. ) {
  1235. var keys = placements[element.placement];
  1236. if (!silent && keys.indexOf(element.key) !== -1) {
  1237. throw new TypeError("Duplicated element (" + element.key + ")");
  1238. }
  1239. keys.push(element.key);
  1240. },
  1241. // DecorateElement
  1242. decorateElement: function(
  1243. element /*: ElementDescriptor */,
  1244. placements /*: Placements */,
  1245. ) /*: ElementFinishersExtras */ {
  1246. var extras /*: ElementDescriptor[] */ = [];
  1247. var finishers /*: ClassFinisher[] */ = [];
  1248. for (
  1249. var decorators = element.decorators, i = decorators.length - 1;
  1250. i >= 0;
  1251. i--
  1252. ) {
  1253. // (inlined) RemoveElementPlacement
  1254. var keys = placements[element.placement];
  1255. keys.splice(keys.indexOf(element.key), 1);
  1256. var elementObject /*: ElementObjectInput */ = this.fromElementDescriptor(
  1257. element,
  1258. );
  1259. var elementFinisherExtras /*: ElementFinisherExtras */ = this.toElementFinisherExtras(
  1260. (0, decorators[i])(elementObject) /*: ElementObjectOutput */ ||
  1261. elementObject,
  1262. );
  1263. element = elementFinisherExtras.element;
  1264. this.addElementPlacement(element, placements);
  1265. if (elementFinisherExtras.finisher) {
  1266. finishers.push(elementFinisherExtras.finisher);
  1267. }
  1268. var newExtras /*: ElementDescriptor[] | void */ =
  1269. elementFinisherExtras.extras;
  1270. if (newExtras) {
  1271. for (var j = 0; j < newExtras.length; j++) {
  1272. this.addElementPlacement(newExtras[j], placements);
  1273. }
  1274. extras.push.apply(extras, newExtras);
  1275. }
  1276. }
  1277. return { element: element, finishers: finishers, extras: extras };
  1278. },
  1279. // DecorateConstructor
  1280. decorateConstructor: function(
  1281. elements /*: ElementDescriptor[] */,
  1282. decorators /*: ClassDecorator[] */,
  1283. ) /*: ElementsFinishers */ {
  1284. var finishers /*: ClassFinisher[] */ = [];
  1285. for (var i = decorators.length - 1; i >= 0; i--) {
  1286. var obj /*: ClassObject */ = this.fromClassDescriptor(elements);
  1287. var elementsAndFinisher /*: ElementsFinisher */ = this.toClassDescriptor(
  1288. (0, decorators[i])(obj) /*: ClassObject */ || obj,
  1289. );
  1290. if (elementsAndFinisher.finisher !== undefined) {
  1291. finishers.push(elementsAndFinisher.finisher);
  1292. }
  1293. if (elementsAndFinisher.elements !== undefined) {
  1294. elements = elementsAndFinisher.elements;
  1295. for (var j = 0; j < elements.length - 1; j++) {
  1296. for (var k = j + 1; k < elements.length; k++) {
  1297. if (
  1298. elements[j].key === elements[k].key &&
  1299. elements[j].placement === elements[k].placement
  1300. ) {
  1301. throw new TypeError(
  1302. "Duplicated element (" + elements[j].key + ")",
  1303. );
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. return { elements: elements, finishers: finishers };
  1310. },
  1311. // FromElementDescriptor
  1312. fromElementDescriptor: function(
  1313. element /*: ElementDescriptor */,
  1314. ) /*: ElementObject */ {
  1315. var obj /*: ElementObject */ = {
  1316. kind: element.kind,
  1317. key: element.key,
  1318. placement: element.placement,
  1319. descriptor: element.descriptor,
  1320. };
  1321. var desc = {
  1322. value: "Descriptor",
  1323. configurable: true,
  1324. };
  1325. Object.defineProperty(obj, Symbol.toStringTag, desc);
  1326. if (element.kind === "field") obj.initializer = element.initializer;
  1327. return obj;
  1328. },
  1329. // ToElementDescriptors
  1330. toElementDescriptors: function(
  1331. elementObjects /*: ElementObject[] */,
  1332. ) /*: ElementDescriptor[] */ {
  1333. if (elementObjects === undefined) return;
  1334. return toArray(elementObjects).map(function(elementObject) {
  1335. var element = this.toElementDescriptor(elementObject);
  1336. this.disallowProperty(elementObject, "finisher", "An element descriptor");
  1337. this.disallowProperty(elementObject, "extras", "An element descriptor");
  1338. return element;
  1339. }, this);
  1340. },
  1341. // ToElementDescriptor
  1342. toElementDescriptor: function(
  1343. elementObject /*: ElementObject */,
  1344. ) /*: ElementDescriptor */ {
  1345. var kind = String(elementObject.kind);
  1346. if (kind !== "method" && kind !== "field") {
  1347. throw new TypeError(
  1348. 'An element descriptor\\'s .kind property must be either "method" or' +
  1349. ' "field", but a decorator created an element descriptor with' +
  1350. ' .kind "' +
  1351. kind +
  1352. '"',
  1353. );
  1354. }
  1355. var key = toPropertyKey(elementObject.key);
  1356. var placement = String(elementObject.placement);
  1357. if (
  1358. placement !== "static" &&
  1359. placement !== "prototype" &&
  1360. placement !== "own"
  1361. ) {
  1362. throw new TypeError(
  1363. 'An element descriptor\\'s .placement property must be one of "static",' +
  1364. ' "prototype" or "own", but a decorator created an element descriptor' +
  1365. ' with .placement "' +
  1366. placement +
  1367. '"',
  1368. );
  1369. }
  1370. var descriptor /*: PropertyDescriptor */ = elementObject.descriptor;
  1371. this.disallowProperty(elementObject, "elements", "An element descriptor");
  1372. var element /*: ElementDescriptor */ = {
  1373. kind: kind,
  1374. key: key,
  1375. placement: placement,
  1376. descriptor: Object.assign({}, descriptor),
  1377. };
  1378. if (kind !== "field") {
  1379. this.disallowProperty(elementObject, "initializer", "A method descriptor");
  1380. } else {
  1381. this.disallowProperty(
  1382. descriptor,
  1383. "get",
  1384. "The property descriptor of a field descriptor",
  1385. );
  1386. this.disallowProperty(
  1387. descriptor,
  1388. "set",
  1389. "The property descriptor of a field descriptor",
  1390. );
  1391. this.disallowProperty(
  1392. descriptor,
  1393. "value",
  1394. "The property descriptor of a field descriptor",
  1395. );
  1396. element.initializer = elementObject.initializer;
  1397. }
  1398. return element;
  1399. },
  1400. toElementFinisherExtras: function(
  1401. elementObject /*: ElementObject */,
  1402. ) /*: ElementFinisherExtras */ {
  1403. var element /*: ElementDescriptor */ = this.toElementDescriptor(
  1404. elementObject,
  1405. );
  1406. var finisher /*: ClassFinisher */ = _optionalCallableProperty(
  1407. elementObject,
  1408. "finisher",
  1409. );
  1410. var extras /*: ElementDescriptors[] */ = this.toElementDescriptors(
  1411. elementObject.extras,
  1412. );
  1413. return { element: element, finisher: finisher, extras: extras };
  1414. },
  1415. // FromClassDescriptor
  1416. fromClassDescriptor: function(
  1417. elements /*: ElementDescriptor[] */,
  1418. ) /*: ClassObject */ {
  1419. var obj = {
  1420. kind: "class",
  1421. elements: elements.map(this.fromElementDescriptor, this),
  1422. };
  1423. var desc = { value: "Descriptor", configurable: true };
  1424. Object.defineProperty(obj, Symbol.toStringTag, desc);
  1425. return obj;
  1426. },
  1427. // ToClassDescriptor
  1428. toClassDescriptor: function(
  1429. obj /*: ClassObject */,
  1430. ) /*: ElementsFinisher */ {
  1431. var kind = String(obj.kind);
  1432. if (kind !== "class") {
  1433. throw new TypeError(
  1434. 'A class descriptor\\'s .kind property must be "class", but a decorator' +
  1435. ' created a class descriptor with .kind "' +
  1436. kind +
  1437. '"',
  1438. );
  1439. }
  1440. this.disallowProperty(obj, "key", "A class descriptor");
  1441. this.disallowProperty(obj, "placement", "A class descriptor");
  1442. this.disallowProperty(obj, "descriptor", "A class descriptor");
  1443. this.disallowProperty(obj, "initializer", "A class descriptor");
  1444. this.disallowProperty(obj, "extras", "A class descriptor");
  1445. var finisher = _optionalCallableProperty(obj, "finisher");
  1446. var elements = this.toElementDescriptors(obj.elements);
  1447. return { elements: elements, finisher: finisher };
  1448. },
  1449. // RunClassFinishers
  1450. runClassFinishers: function(
  1451. constructor /*: Class<*> */,
  1452. finishers /*: ClassFinisher[] */,
  1453. ) /*: Class<*> */ {
  1454. for (var i = 0; i < finishers.length; i++) {
  1455. var newConstructor /*: ?Class<*> */ = (0, finishers[i])(constructor);
  1456. if (newConstructor !== undefined) {
  1457. // NOTE: This should check if IsConstructor(newConstructor) is false.
  1458. if (typeof newConstructor !== "function") {
  1459. throw new TypeError("Finishers must return a constructor.");
  1460. }
  1461. constructor = newConstructor;
  1462. }
  1463. }
  1464. return constructor;
  1465. },
  1466. disallowProperty: function(obj, name, objectType) {
  1467. if (obj[name] !== undefined) {
  1468. throw new TypeError(objectType + " can't have a ." + name + " property.");
  1469. }
  1470. }
  1471. };
  1472. return api;
  1473. }
  1474. // ClassElementEvaluation
  1475. function _createElementDescriptor(
  1476. def /*: ElementDefinition */,
  1477. ) /*: ElementDescriptor */ {
  1478. var key = toPropertyKey(def.key);
  1479. var descriptor /*: PropertyDescriptor */;
  1480. if (def.kind === "method") {
  1481. descriptor = {
  1482. value: def.value,
  1483. writable: true,
  1484. configurable: true,
  1485. enumerable: false,
  1486. };
  1487. } else if (def.kind === "get") {
  1488. descriptor = { get: def.value, configurable: true, enumerable: false };
  1489. } else if (def.kind === "set") {
  1490. descriptor = { set: def.value, configurable: true, enumerable: false };
  1491. } else if (def.kind === "field") {
  1492. descriptor = { configurable: true, writable: true, enumerable: true };
  1493. }
  1494. var element /*: ElementDescriptor */ = {
  1495. kind: def.kind === "field" ? "field" : "method",
  1496. key: key,
  1497. placement: def.static
  1498. ? "static"
  1499. : def.kind === "field"
  1500. ? "own"
  1501. : "prototype",
  1502. descriptor: descriptor,
  1503. };
  1504. if (def.decorators) element.decorators = def.decorators;
  1505. if (def.kind === "field") element.initializer = def.value;
  1506. return element;
  1507. }
  1508. // CoalesceGetterSetter
  1509. function _coalesceGetterSetter(
  1510. element /*: ElementDescriptor */,
  1511. other /*: ElementDescriptor */,
  1512. ) {
  1513. if (element.descriptor.get !== undefined) {
  1514. other.descriptor.get = element.descriptor.get;
  1515. } else {
  1516. other.descriptor.set = element.descriptor.set;
  1517. }
  1518. }
  1519. // CoalesceClassElements
  1520. function _coalesceClassElements(
  1521. elements /*: ElementDescriptor[] */,
  1522. ) /*: ElementDescriptor[] */ {
  1523. var newElements /*: ElementDescriptor[] */ = [];
  1524. var isSameElement = function(
  1525. other /*: ElementDescriptor */,
  1526. ) /*: boolean */ {
  1527. return (
  1528. other.kind === "method" &&
  1529. other.key === element.key &&
  1530. other.placement === element.placement
  1531. );
  1532. };
  1533. for (var i = 0; i < elements.length; i++) {
  1534. var element /*: ElementDescriptor */ = elements[i];
  1535. var other /*: ElementDescriptor */;
  1536. if (
  1537. element.kind === "method" &&
  1538. (other = newElements.find(isSameElement))
  1539. ) {
  1540. if (
  1541. _isDataDescriptor(element.descriptor) ||
  1542. _isDataDescriptor(other.descriptor)
  1543. ) {
  1544. if (_hasDecorators(element) || _hasDecorators(other)) {
  1545. throw new ReferenceError(
  1546. "Duplicated methods (" + element.key + ") can't be decorated.",
  1547. );
  1548. }
  1549. other.descriptor = element.descriptor;
  1550. } else {
  1551. if (_hasDecorators(element)) {
  1552. if (_hasDecorators(other)) {
  1553. throw new ReferenceError(
  1554. "Decorators can't be placed on different accessors with for " +
  1555. "the same property (" +
  1556. element.key +
  1557. ").",
  1558. );
  1559. }
  1560. other.decorators = element.decorators;
  1561. }
  1562. _coalesceGetterSetter(element, other);
  1563. }
  1564. } else {
  1565. newElements.push(element);
  1566. }
  1567. }
  1568. return newElements;
  1569. }
  1570. function _hasDecorators(element /*: ElementDescriptor */) /*: boolean */ {
  1571. return element.decorators && element.decorators.length;
  1572. }
  1573. function _isDataDescriptor(desc /*: PropertyDescriptor */) /*: boolean */ {
  1574. return (
  1575. desc !== undefined &&
  1576. !(desc.value === undefined && desc.writable === undefined)
  1577. );
  1578. }
  1579. function _optionalCallableProperty /*::<T>*/(
  1580. obj /*: T */,
  1581. name /*: $Keys<T> */,
  1582. ) /*: ?Function */ {
  1583. var value = obj[name];
  1584. if (value !== undefined && typeof value !== "function") {
  1585. throw new TypeError("Expected '" + name + "' to be a function");
  1586. }
  1587. return value;
  1588. }
  1589. `;
  1590. helpers.classPrivateMethodGet = helper("7.1.6")`
  1591. export default function _classPrivateMethodGet(receiver, privateSet, fn) {
  1592. if (!privateSet.has(receiver)) {
  1593. throw new TypeError("attempted to get private field on non-instance");
  1594. }
  1595. return fn;
  1596. }
  1597. `;
  1598. helpers.classPrivateMethodSet = helper("7.1.6")`
  1599. export default function _classPrivateMethodSet() {
  1600. throw new TypeError("attempted to reassign private method");
  1601. }
  1602. `;
  1603. helpers.wrapRegExp = helper("7.2.6")`
  1604. import wrapNativeSuper from "wrapNativeSuper";
  1605. import getPrototypeOf from "getPrototypeOf";
  1606. import possibleConstructorReturn from "possibleConstructorReturn";
  1607. import inherits from "inherits";
  1608. export default function _wrapRegExp(re, groups) {
  1609. _wrapRegExp = function(re, groups) {
  1610. return new BabelRegExp(re, groups);
  1611. };
  1612. var _RegExp = wrapNativeSuper(RegExp);
  1613. var _super = RegExp.prototype;
  1614. var _groups = new WeakMap();
  1615. function BabelRegExp(re, groups) {
  1616. var _this = _RegExp.call(this, re);
  1617. _groups.set(_this, groups);
  1618. return _this;
  1619. }
  1620. inherits(BabelRegExp, _RegExp);
  1621. BabelRegExp.prototype.exec = function(str) {
  1622. var result = _super.exec.call(this, str);
  1623. if (result) result.groups = buildGroups(result, this);
  1624. return result;
  1625. };
  1626. BabelRegExp.prototype[Symbol.replace] = function(str, substitution) {
  1627. if (typeof substitution === "string") {
  1628. var groups = _groups.get(this);
  1629. return _super[Symbol.replace].call(
  1630. this,
  1631. str,
  1632. substitution.replace(/\\$<([^>]+)>/g, function(_, name) {
  1633. return "$" + groups[name];
  1634. })
  1635. );
  1636. } else if (typeof substitution === "function") {
  1637. var _this = this;
  1638. return _super[Symbol.replace].call(
  1639. this,
  1640. str,
  1641. function() {
  1642. var args = [];
  1643. args.push.apply(args, arguments);
  1644. if (typeof args[args.length - 1] !== "object") {
  1645. // Modern engines already pass result.groups as the last arg.
  1646. args.push(buildGroups(args, _this));
  1647. }
  1648. return substitution.apply(this, args);
  1649. }
  1650. );
  1651. } else {
  1652. return _super[Symbol.replace].call(this, str, substitution);
  1653. }
  1654. }
  1655. function buildGroups(result, re) {
  1656. // NOTE: This function should return undefined if there are no groups,
  1657. // but in that case Babel doesn't add the wrapper anyway.
  1658. var g = _groups.get(re);
  1659. return Object.keys(g).reduce(function(groups, name) {
  1660. groups[name] = result[g[name]];
  1661. return groups;
  1662. }, Object.create(null));
  1663. }
  1664. return _wrapRegExp.apply(this, arguments);
  1665. }
  1666. `;