You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1913 lines
59 KiB

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