web 3d图形渲染器
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.

2118 lines
66 KiB

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