helpers.js 53 KB

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