helpers.js 56 KB

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