helpers.js 57 KB

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