helpers.js 57 KB

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