helpers.js 59 KB

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