|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935 |
- "use strict";
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
-
- var _template = require("@babel/template");
-
- var generated = require("./helpers-generated");
-
- const helpers = Object.assign({
- __proto__: null
- }, generated);
- var _default = helpers;
- exports.default = _default;
-
- const helper = minVersion => tpl => ({
- minVersion,
- ast: () => _template.default.program.ast(tpl)
- });
-
- helpers.asyncIterator = helper("7.0.0-beta.0")`
- export default function _asyncIterator(iterable) {
- var method;
- if (typeof Symbol !== "undefined") {
- if (Symbol.asyncIterator) method = iterable[Symbol.asyncIterator];
- if (method == null && Symbol.iterator) method = iterable[Symbol.iterator];
- }
- if (method == null) method = iterable["@@asyncIterator"];
- if (method == null) method = iterable["@@iterator"]
- if (method == null) throw new TypeError("Object is not async iterable");
- return method.call(iterable);
- }
- `;
- helpers.AwaitValue = helper("7.0.0-beta.0")`
- export default function _AwaitValue(value) {
- this.wrapped = value;
- }
- `;
- helpers.AsyncGenerator = helper("7.0.0-beta.0")`
- import AwaitValue from "AwaitValue";
-
- export default function AsyncGenerator(gen) {
- var front, back;
-
- function send(key, arg) {
- return new Promise(function (resolve, reject) {
- var request = {
- key: key,
- arg: arg,
- resolve: resolve,
- reject: reject,
- next: null,
- };
-
- if (back) {
- back = back.next = request;
- } else {
- front = back = request;
- resume(key, arg);
- }
- });
- }
-
- function resume(key, arg) {
- try {
- var result = gen[key](arg)
- var value = result.value;
- var wrappedAwait = value instanceof AwaitValue;
-
- Promise.resolve(wrappedAwait ? value.wrapped : value).then(
- function (arg) {
- if (wrappedAwait) {
- resume(key === "return" ? "return" : "next", arg);
- return
- }
-
- settle(result.done ? "return" : "normal", arg);
- },
- function (err) { resume("throw", err); });
- } catch (err) {
- settle("throw", err);
- }
- }
-
- function settle(type, value) {
- switch (type) {
- case "return":
- front.resolve({ value: value, done: true });
- break;
- case "throw":
- front.reject(value);
- break;
- default:
- front.resolve({ value: value, done: false });
- break;
- }
-
- front = front.next;
- if (front) {
- resume(front.key, front.arg);
- } else {
- back = null;
- }
- }
-
- this._invoke = send;
-
- // Hide "return" method if generator return is not supported
- if (typeof gen.return !== "function") {
- this.return = undefined;
- }
- }
-
- AsyncGenerator.prototype[typeof Symbol === "function" && Symbol.asyncIterator || "@@asyncIterator"] = function () { return this; };
-
- AsyncGenerator.prototype.next = function (arg) { return this._invoke("next", arg); };
- AsyncGenerator.prototype.throw = function (arg) { return this._invoke("throw", arg); };
- AsyncGenerator.prototype.return = function (arg) { return this._invoke("return", arg); };
- `;
- helpers.wrapAsyncGenerator = helper("7.0.0-beta.0")`
- import AsyncGenerator from "AsyncGenerator";
-
- export default function _wrapAsyncGenerator(fn) {
- return function () {
- return new AsyncGenerator(fn.apply(this, arguments));
- };
- }
- `;
- helpers.awaitAsyncGenerator = helper("7.0.0-beta.0")`
- import AwaitValue from "AwaitValue";
-
- export default function _awaitAsyncGenerator(value) {
- return new AwaitValue(value);
- }
- `;
- helpers.asyncGeneratorDelegate = helper("7.0.0-beta.0")`
- export default function _asyncGeneratorDelegate(inner, awaitWrap) {
- var iter = {}, waiting = false;
-
- function pump(key, value) {
- waiting = true;
- value = new Promise(function (resolve) { resolve(inner[key](value)); });
- return { done: false, value: awaitWrap(value) };
- };
-
- iter[typeof Symbol !== "undefined" && Symbol.iterator || "@@iterator"] = function () { return this; };
-
- iter.next = function (value) {
- if (waiting) {
- waiting = false;
- return value;
- }
- return pump("next", value);
- };
-
- if (typeof inner.throw === "function") {
- iter.throw = function (value) {
- if (waiting) {
- waiting = false;
- throw value;
- }
- return pump("throw", value);
- };
- }
-
- if (typeof inner.return === "function") {
- iter.return = function (value) {
- if (waiting) {
- waiting = false;
- return value;
- }
- return pump("return", value);
- };
- }
-
- return iter;
- }
- `;
- helpers.asyncToGenerator = helper("7.0.0-beta.0")`
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
- try {
- var info = gen[key](arg);
- var value = info.value;
- } catch (error) {
- reject(error);
- return;
- }
-
- if (info.done) {
- resolve(value);
- } else {
- Promise.resolve(value).then(_next, _throw);
- }
- }
-
- export default function _asyncToGenerator(fn) {
- return function () {
- var self = this, args = arguments;
- return new Promise(function (resolve, reject) {
- var gen = fn.apply(self, args);
- function _next(value) {
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
- }
- function _throw(err) {
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
- }
-
- _next(undefined);
- });
- };
- }
- `;
- helpers.classCallCheck = helper("7.0.0-beta.0")`
- export default function _classCallCheck(instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function");
- }
- }
- `;
- helpers.createClass = helper("7.0.0-beta.0")`
- function _defineProperties(target, props) {
- for (var i = 0; i < props.length; i ++) {
- var descriptor = props[i];
- descriptor.enumerable = descriptor.enumerable || false;
- descriptor.configurable = true;
- if ("value" in descriptor) descriptor.writable = true;
- Object.defineProperty(target, descriptor.key, descriptor);
- }
- }
-
- export default function _createClass(Constructor, protoProps, staticProps) {
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
- if (staticProps) _defineProperties(Constructor, staticProps);
- return Constructor;
- }
- `;
- helpers.defineEnumerableProperties = helper("7.0.0-beta.0")`
- export default function _defineEnumerableProperties(obj, descs) {
- for (var key in descs) {
- var desc = descs[key];
- desc.configurable = desc.enumerable = true;
- if ("value" in desc) desc.writable = true;
- Object.defineProperty(obj, key, desc);
- }
-
- // Symbols are not enumerated over by for-in loops. If native
- // Symbols are available, fetch all of the descs object's own
- // symbol properties and define them on our target object too.
- if (Object.getOwnPropertySymbols) {
- var objectSymbols = Object.getOwnPropertySymbols(descs);
- for (var i = 0; i < objectSymbols.length; i++) {
- var sym = objectSymbols[i];
- var desc = descs[sym];
- desc.configurable = desc.enumerable = true;
- if ("value" in desc) desc.writable = true;
- Object.defineProperty(obj, sym, desc);
- }
- }
- return obj;
- }
- `;
- helpers.defaults = helper("7.0.0-beta.0")`
- export default function _defaults(obj, defaults) {
- var keys = Object.getOwnPropertyNames(defaults);
- for (var i = 0; i < keys.length; i++) {
- var key = keys[i];
- var value = Object.getOwnPropertyDescriptor(defaults, key);
- if (value && value.configurable && obj[key] === undefined) {
- Object.defineProperty(obj, key, value);
- }
- }
- return obj;
- }
- `;
- helpers.defineProperty = helper("7.0.0-beta.0")`
- export default function _defineProperty(obj, key, value) {
- // Shortcircuit the slow defineProperty path when possible.
- // We are trying to avoid issues where setters defined on the
- // prototype cause side effects under the fast path of simple
- // assignment. By checking for existence of the property with
- // the in operator, we can optimize most of this overhead away.
- if (key in obj) {
- Object.defineProperty(obj, key, {
- value: value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- } else {
- obj[key] = value;
- }
- return obj;
- }
- `;
- helpers.extends = helper("7.0.0-beta.0")`
- export default function _extends() {
- _extends = Object.assign || function (target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = arguments[i];
- for (var key in source) {
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- target[key] = source[key];
- }
- }
- }
- return target;
- };
-
- return _extends.apply(this, arguments);
- }
- `;
- helpers.objectSpread = helper("7.0.0-beta.0")`
- import defineProperty from "defineProperty";
-
- export default function _objectSpread(target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = (arguments[i] != null) ? Object(arguments[i]) : {};
- var ownKeys = Object.keys(source);
- if (typeof Object.getOwnPropertySymbols === 'function') {
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
- }));
- }
- ownKeys.forEach(function(key) {
- defineProperty(target, key, source[key]);
- });
- }
- return target;
- }
- `;
- helpers.inherits = helper("7.0.0-beta.0")`
- import setPrototypeOf from "setPrototypeOf";
-
- export default function _inherits(subClass, superClass) {
- if (typeof superClass !== "function" && superClass !== null) {
- throw new TypeError("Super expression must either be null or a function");
- }
- subClass.prototype = Object.create(superClass && superClass.prototype, {
- constructor: {
- value: subClass,
- writable: true,
- configurable: true
- }
- });
- if (superClass) setPrototypeOf(subClass, superClass);
- }
- `;
- helpers.inheritsLoose = helper("7.0.0-beta.0")`
- import setPrototypeOf from "setPrototypeOf";
-
- export default function _inheritsLoose(subClass, superClass) {
- subClass.prototype = Object.create(superClass.prototype);
- subClass.prototype.constructor = subClass;
- setPrototypeOf(subClass, superClass);
- }
- `;
- helpers.getPrototypeOf = helper("7.0.0-beta.0")`
- export default function _getPrototypeOf(o) {
- _getPrototypeOf = Object.setPrototypeOf
- ? Object.getPrototypeOf
- : function _getPrototypeOf(o) {
- return o.__proto__ || Object.getPrototypeOf(o);
- };
- return _getPrototypeOf(o);
- }
- `;
- helpers.setPrototypeOf = helper("7.0.0-beta.0")`
- export default function _setPrototypeOf(o, p) {
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
- o.__proto__ = p;
- return o;
- };
- return _setPrototypeOf(o, p);
- }
- `;
- helpers.isNativeReflectConstruct = helper("7.9.0")`
- export default function _isNativeReflectConstruct() {
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
-
- // core-js@3
- if (Reflect.construct.sham) return false;
-
- // Proxy can't be polyfilled. Every browser implemented
- // proxies before or at the same time as Reflect.construct,
- // so if they support Proxy they also support Reflect.construct.
- if (typeof Proxy === "function") return true;
-
- // Since Reflect.construct can't be properly polyfilled, some
- // implementations (e.g. core-js@2) don't set the correct internal slots.
- // Those polyfills don't allow us to subclass built-ins, so we need to
- // use our fallback implementation.
- try {
- // If the internal slots aren't set, this throws an error similar to
- // TypeError: this is not a Boolean object.
-
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
- return true;
- } catch (e) {
- return false;
- }
- }
- `;
- helpers.construct = helper("7.0.0-beta.0")`
- import setPrototypeOf from "setPrototypeOf";
- import isNativeReflectConstruct from "isNativeReflectConstruct";
-
- export default function _construct(Parent, args, Class) {
- if (isNativeReflectConstruct()) {
- _construct = Reflect.construct;
- } else {
- // NOTE: If Parent !== Class, the correct __proto__ is set *after*
- // calling the constructor.
- _construct = function _construct(Parent, args, Class) {
- var a = [null];
- a.push.apply(a, args);
- var Constructor = Function.bind.apply(Parent, a);
- var instance = new Constructor();
- if (Class) setPrototypeOf(instance, Class.prototype);
- return instance;
- };
- }
- // Avoid issues with Class being present but undefined when it wasn't
- // present in the original call.
- return _construct.apply(null, arguments);
- }
- `;
- helpers.isNativeFunction = helper("7.0.0-beta.0")`
- export default function _isNativeFunction(fn) {
- // Note: This function returns "true" for core-js functions.
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
- }
- `;
- helpers.wrapNativeSuper = helper("7.0.0-beta.0")`
- import getPrototypeOf from "getPrototypeOf";
- import setPrototypeOf from "setPrototypeOf";
- import isNativeFunction from "isNativeFunction";
- import construct from "construct";
-
- export default function _wrapNativeSuper(Class) {
- var _cache = typeof Map === "function" ? new Map() : undefined;
-
- _wrapNativeSuper = function _wrapNativeSuper(Class) {
- if (Class === null || !isNativeFunction(Class)) return Class;
- if (typeof Class !== "function") {
- throw new TypeError("Super expression must either be null or a function");
- }
- if (typeof _cache !== "undefined") {
- if (_cache.has(Class)) return _cache.get(Class);
- _cache.set(Class, Wrapper);
- }
- function Wrapper() {
- return construct(Class, arguments, getPrototypeOf(this).constructor)
- }
- Wrapper.prototype = Object.create(Class.prototype, {
- constructor: {
- value: Wrapper,
- enumerable: false,
- writable: true,
- configurable: true,
- }
- });
-
- return setPrototypeOf(Wrapper, Class);
- }
-
- return _wrapNativeSuper(Class)
- }
- `;
- helpers.instanceof = helper("7.0.0-beta.0")`
- export default function _instanceof(left, right) {
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
- return !!right[Symbol.hasInstance](left);
- } else {
- return left instanceof right;
- }
- }
- `;
- helpers.interopRequireDefault = helper("7.0.0-beta.0")`
- export default function _interopRequireDefault(obj) {
- return obj && obj.__esModule ? obj : { default: obj };
- }
- `;
- helpers.interopRequireWildcard = helper("7.14.0")`
- function _getRequireWildcardCache(nodeInterop) {
- if (typeof WeakMap !== "function") return null;
-
- var cacheBabelInterop = new WeakMap();
- var cacheNodeInterop = new WeakMap();
- return (_getRequireWildcardCache = function (nodeInterop) {
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
- })(nodeInterop);
- }
-
- export default function _interopRequireWildcard(obj, nodeInterop) {
- if (!nodeInterop && obj && obj.__esModule) {
- return obj;
- }
-
- if (obj === null || (typeof obj !== "object" && typeof obj !== "function")) {
- return { default: obj }
- }
-
- var cache = _getRequireWildcardCache(nodeInterop);
- if (cache && cache.has(obj)) {
- return cache.get(obj);
- }
-
- var newObj = {};
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
- for (var key in obj) {
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
- var desc = hasPropertyDescriptor
- ? Object.getOwnPropertyDescriptor(obj, key)
- : null;
- if (desc && (desc.get || desc.set)) {
- Object.defineProperty(newObj, key, desc);
- } else {
- newObj[key] = obj[key];
- }
- }
- }
- newObj.default = obj;
- if (cache) {
- cache.set(obj, newObj);
- }
- return newObj;
- }
- `;
- helpers.newArrowCheck = helper("7.0.0-beta.0")`
- export default function _newArrowCheck(innerThis, boundThis) {
- if (innerThis !== boundThis) {
- throw new TypeError("Cannot instantiate an arrow function");
- }
- }
- `;
- helpers.objectDestructuringEmpty = helper("7.0.0-beta.0")`
- export default function _objectDestructuringEmpty(obj) {
- if (obj == null) throw new TypeError("Cannot destructure undefined");
- }
- `;
- helpers.objectWithoutPropertiesLoose = helper("7.0.0-beta.0")`
- export default function _objectWithoutPropertiesLoose(source, excluded) {
- if (source == null) return {};
-
- var target = {};
- var sourceKeys = Object.keys(source);
- var key, i;
-
- for (i = 0; i < sourceKeys.length; i++) {
- key = sourceKeys[i];
- if (excluded.indexOf(key) >= 0) continue;
- target[key] = source[key];
- }
-
- return target;
- }
- `;
- helpers.objectWithoutProperties = helper("7.0.0-beta.0")`
- import objectWithoutPropertiesLoose from "objectWithoutPropertiesLoose";
-
- export default function _objectWithoutProperties(source, excluded) {
- if (source == null) return {};
-
- var target = objectWithoutPropertiesLoose(source, excluded);
- var key, i;
-
- if (Object.getOwnPropertySymbols) {
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
- for (i = 0; i < sourceSymbolKeys.length; i++) {
- key = sourceSymbolKeys[i];
- if (excluded.indexOf(key) >= 0) continue;
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
- target[key] = source[key];
- }
- }
-
- return target;
- }
- `;
- helpers.assertThisInitialized = helper("7.0.0-beta.0")`
- export default function _assertThisInitialized(self) {
- if (self === void 0) {
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
- }
- return self;
- }
- `;
- helpers.possibleConstructorReturn = helper("7.0.0-beta.0")`
- import assertThisInitialized from "assertThisInitialized";
-
- export default function _possibleConstructorReturn(self, call) {
- if (call && (typeof call === "object" || typeof call === "function")) {
- return call;
- }
- return assertThisInitialized(self);
- }
- `;
- helpers.createSuper = helper("7.9.0")`
- import getPrototypeOf from "getPrototypeOf";
- import isNativeReflectConstruct from "isNativeReflectConstruct";
- import possibleConstructorReturn from "possibleConstructorReturn";
-
- export default function _createSuper(Derived) {
- var hasNativeReflectConstruct = isNativeReflectConstruct();
-
- return function _createSuperInternal() {
- var Super = getPrototypeOf(Derived), result;
- if (hasNativeReflectConstruct) {
- // NOTE: This doesn't work if this.__proto__.constructor has been modified.
- var NewTarget = getPrototypeOf(this).constructor;
- result = Reflect.construct(Super, arguments, NewTarget);
- } else {
- result = Super.apply(this, arguments);
- }
- return possibleConstructorReturn(this, result);
- }
- }
- `;
- helpers.superPropBase = helper("7.0.0-beta.0")`
- import getPrototypeOf from "getPrototypeOf";
-
- export default function _superPropBase(object, property) {
- // Yes, this throws if object is null to being with, that's on purpose.
- while (!Object.prototype.hasOwnProperty.call(object, property)) {
- object = getPrototypeOf(object);
- if (object === null) break;
- }
- return object;
- }
- `;
- helpers.get = helper("7.0.0-beta.0")`
- import superPropBase from "superPropBase";
-
- export default function _get(target, property, receiver) {
- if (typeof Reflect !== "undefined" && Reflect.get) {
- _get = Reflect.get;
- } else {
- _get = function _get(target, property, receiver) {
- var base = superPropBase(target, property);
-
- if (!base) return;
-
- var desc = Object.getOwnPropertyDescriptor(base, property);
- if (desc.get) {
- return desc.get.call(receiver);
- }
-
- return desc.value;
- };
- }
- return _get(target, property, receiver || target);
- }
- `;
- helpers.set = helper("7.0.0-beta.0")`
- import superPropBase from "superPropBase";
- import defineProperty from "defineProperty";
-
- function set(target, property, value, receiver) {
- if (typeof Reflect !== "undefined" && Reflect.set) {
- set = Reflect.set;
- } else {
- set = function set(target, property, value, receiver) {
- var base = superPropBase(target, property);
- var desc;
-
- if (base) {
- desc = Object.getOwnPropertyDescriptor(base, property);
- if (desc.set) {
- desc.set.call(receiver, value);
- return true;
- } else if (!desc.writable) {
- // Both getter and non-writable fall into this.
- return false;
- }
- }
-
- // Without a super that defines the property, spec boils down to
- // "define on receiver" for some reason.
- desc = Object.getOwnPropertyDescriptor(receiver, property);
- if (desc) {
- if (!desc.writable) {
- // Setter, getter, and non-writable fall into this.
- return false;
- }
-
- desc.value = value;
- Object.defineProperty(receiver, property, desc);
- } else {
- // Avoid setters that may be defined on Sub's prototype, but not on
- // the instance.
- defineProperty(receiver, property, value);
- }
-
- return true;
- };
- }
-
- return set(target, property, value, receiver);
- }
-
- export default function _set(target, property, value, receiver, isStrict) {
- var s = set(target, property, value, receiver || target);
- if (!s && isStrict) {
- throw new Error('failed to set property');
- }
-
- return value;
- }
- `;
- helpers.taggedTemplateLiteral = helper("7.0.0-beta.0")`
- export default function _taggedTemplateLiteral(strings, raw) {
- if (!raw) { raw = strings.slice(0); }
- return Object.freeze(Object.defineProperties(strings, {
- raw: { value: Object.freeze(raw) }
- }));
- }
- `;
- helpers.taggedTemplateLiteralLoose = helper("7.0.0-beta.0")`
- export default function _taggedTemplateLiteralLoose(strings, raw) {
- if (!raw) { raw = strings.slice(0); }
- strings.raw = raw;
- return strings;
- }
- `;
- helpers.readOnlyError = helper("7.0.0-beta.0")`
- export default function _readOnlyError(name) {
- throw new TypeError("\\"" + name + "\\" is read-only");
- }
- `;
- helpers.writeOnlyError = helper("7.12.13")`
- export default function _writeOnlyError(name) {
- throw new TypeError("\\"" + name + "\\" is write-only");
- }
- `;
- helpers.classNameTDZError = helper("7.0.0-beta.0")`
- export default function _classNameTDZError(name) {
- throw new Error("Class \\"" + name + "\\" cannot be referenced in computed property keys.");
- }
- `;
- helpers.temporalUndefined = helper("7.0.0-beta.0")`
- // This function isn't mean to be called, but to be used as a reference.
- // We can't use a normal object because it isn't hoisted.
- export default function _temporalUndefined() {}
- `;
- helpers.tdz = helper("7.5.5")`
- export default function _tdzError(name) {
- throw new ReferenceError(name + " is not defined - temporal dead zone");
- }
- `;
- helpers.temporalRef = helper("7.0.0-beta.0")`
- import undef from "temporalUndefined";
- import err from "tdz";
-
- export default function _temporalRef(val, name) {
- return val === undef ? err(name) : val;
- }
- `;
- helpers.slicedToArray = helper("7.0.0-beta.0")`
- import arrayWithHoles from "arrayWithHoles";
- import iterableToArrayLimit from "iterableToArrayLimit";
- import unsupportedIterableToArray from "unsupportedIterableToArray";
- import nonIterableRest from "nonIterableRest";
-
- export default function _slicedToArray(arr, i) {
- return (
- arrayWithHoles(arr) ||
- iterableToArrayLimit(arr, i) ||
- unsupportedIterableToArray(arr, i) ||
- nonIterableRest()
- );
- }
- `;
- helpers.slicedToArrayLoose = helper("7.0.0-beta.0")`
- import arrayWithHoles from "arrayWithHoles";
- import iterableToArrayLimitLoose from "iterableToArrayLimitLoose";
- import unsupportedIterableToArray from "unsupportedIterableToArray";
- import nonIterableRest from "nonIterableRest";
-
- export default function _slicedToArrayLoose(arr, i) {
- return (
- arrayWithHoles(arr) ||
- iterableToArrayLimitLoose(arr, i) ||
- unsupportedIterableToArray(arr, i) ||
- nonIterableRest()
- );
- }
- `;
- helpers.toArray = helper("7.0.0-beta.0")`
- import arrayWithHoles from "arrayWithHoles";
- import iterableToArray from "iterableToArray";
- import unsupportedIterableToArray from "unsupportedIterableToArray";
- import nonIterableRest from "nonIterableRest";
-
- export default function _toArray(arr) {
- return (
- arrayWithHoles(arr) ||
- iterableToArray(arr) ||
- unsupportedIterableToArray(arr) ||
- nonIterableRest()
- );
- }
- `;
- helpers.toConsumableArray = helper("7.0.0-beta.0")`
- import arrayWithoutHoles from "arrayWithoutHoles";
- import iterableToArray from "iterableToArray";
- import unsupportedIterableToArray from "unsupportedIterableToArray";
- import nonIterableSpread from "nonIterableSpread";
-
- export default function _toConsumableArray(arr) {
- return (
- arrayWithoutHoles(arr) ||
- iterableToArray(arr) ||
- unsupportedIterableToArray(arr) ||
- nonIterableSpread()
- );
- }
- `;
- helpers.arrayWithoutHoles = helper("7.0.0-beta.0")`
- import arrayLikeToArray from "arrayLikeToArray";
-
- export default function _arrayWithoutHoles(arr) {
- if (Array.isArray(arr)) return arrayLikeToArray(arr);
- }
- `;
- helpers.arrayWithHoles = helper("7.0.0-beta.0")`
- export default function _arrayWithHoles(arr) {
- if (Array.isArray(arr)) return arr;
- }
- `;
- helpers.maybeArrayLike = helper("7.9.0")`
- import arrayLikeToArray from "arrayLikeToArray";
-
- export default function _maybeArrayLike(next, arr, i) {
- if (arr && !Array.isArray(arr) && typeof arr.length === "number") {
- var len = arr.length;
- return arrayLikeToArray(arr, i !== void 0 && i < len ? i : len);
- }
- return next(arr, i);
- }
- `;
- helpers.iterableToArray = helper("7.0.0-beta.0")`
- export default function _iterableToArray(iter) {
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
- }
- `;
- helpers.iterableToArrayLimit = helper("7.0.0-beta.0")`
- export default function _iterableToArrayLimit(arr, i) {
- // this is an expanded form of \`for...of\` that properly supports abrupt completions of
- // iterators etc. variable names have been minimised to reduce the size of this massive
- // helper. sometimes spec compliance is annoying :(
- //
- // _n = _iteratorNormalCompletion
- // _d = _didIteratorError
- // _e = _iteratorError
- // _i = _iterator
- // _s = _step
-
- var _i = arr == null ? null : (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
- if (_i == null) return;
-
- var _arr = [];
- var _n = true;
- var _d = false;
- var _s, _e;
- try {
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
- _arr.push(_s.value);
- if (i && _arr.length === i) break;
- }
- } catch (err) {
- _d = true;
- _e = err;
- } finally {
- try {
- if (!_n && _i["return"] != null) _i["return"]();
- } finally {
- if (_d) throw _e;
- }
- }
- return _arr;
- }
- `;
- helpers.iterableToArrayLimitLoose = helper("7.0.0-beta.0")`
- export default function _iterableToArrayLimitLoose(arr, i) {
- var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
- if (_i == null) return;
-
- var _arr = [];
- for (_i = _i.call(arr), _step; !(_step = _i.next()).done;) {
- _arr.push(_step.value);
- if (i && _arr.length === i) break;
- }
- return _arr;
- }
- `;
- helpers.unsupportedIterableToArray = helper("7.9.0")`
- import arrayLikeToArray from "arrayLikeToArray";
-
- export default function _unsupportedIterableToArray(o, minLen) {
- if (!o) return;
- if (typeof o === "string") return arrayLikeToArray(o, minLen);
- var n = Object.prototype.toString.call(o).slice(8, -1);
- if (n === "Object" && o.constructor) n = o.constructor.name;
- if (n === "Map" || n === "Set") return Array.from(o);
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
- return arrayLikeToArray(o, minLen);
- }
- `;
- helpers.arrayLikeToArray = helper("7.9.0")`
- export default function _arrayLikeToArray(arr, len) {
- if (len == null || len > arr.length) len = arr.length;
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
- return arr2;
- }
- `;
- helpers.nonIterableSpread = helper("7.0.0-beta.0")`
- export default function _nonIterableSpread() {
- throw new TypeError(
- "Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
- );
- }
- `;
- helpers.nonIterableRest = helper("7.0.0-beta.0")`
- export default function _nonIterableRest() {
- throw new TypeError(
- "Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
- );
- }
- `;
- helpers.createForOfIteratorHelper = helper("7.9.0")`
- import unsupportedIterableToArray from "unsupportedIterableToArray";
-
- // s: start (create the iterator)
- // n: next
- // e: error (called whenever something throws)
- // f: finish (always called at the end)
-
- export default function _createForOfIteratorHelper(o, allowArrayLike) {
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
-
- if (!it) {
- // Fallback for engines without symbol support
- if (
- Array.isArray(o) ||
- (it = unsupportedIterableToArray(o)) ||
- (allowArrayLike && o && typeof o.length === "number")
- ) {
- if (it) o = it;
- var i = 0;
- var F = function(){};
- return {
- s: F,
- n: function() {
- if (i >= o.length) return { done: true };
- return { done: false, value: o[i++] };
- },
- e: function(e) { throw e; },
- f: F,
- };
- }
-
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
- }
-
- var normalCompletion = true, didErr = false, err;
-
- return {
- s: function() {
- it = it.call(o);
- },
- n: function() {
- var step = it.next();
- normalCompletion = step.done;
- return step;
- },
- e: function(e) {
- didErr = true;
- err = e;
- },
- f: function() {
- try {
- if (!normalCompletion && it.return != null) it.return();
- } finally {
- if (didErr) throw err;
- }
- }
- };
- }
- `;
- helpers.createForOfIteratorHelperLoose = helper("7.9.0")`
- import unsupportedIterableToArray from "unsupportedIterableToArray";
-
- export default function _createForOfIteratorHelperLoose(o, allowArrayLike) {
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
-
- if (it) return (it = it.call(o)).next.bind(it);
-
- // Fallback for engines without symbol support
- if (
- Array.isArray(o) ||
- (it = unsupportedIterableToArray(o)) ||
- (allowArrayLike && o && typeof o.length === "number")
- ) {
- if (it) o = it;
- var i = 0;
- return function() {
- if (i >= o.length) return { done: true };
- return { done: false, value: o[i++] };
- }
- }
-
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
- }
- `;
- helpers.skipFirstGeneratorNext = helper("7.0.0-beta.0")`
- export default function _skipFirstGeneratorNext(fn) {
- return function () {
- var it = fn.apply(this, arguments);
- it.next();
- return it;
- }
- }
- `;
- helpers.toPrimitive = helper("7.1.5")`
- export default function _toPrimitive(
- input,
- hint /*: "default" | "string" | "number" | void */
- ) {
- if (typeof input !== "object" || input === null) return input;
- var prim = input[Symbol.toPrimitive];
- if (prim !== undefined) {
- var res = prim.call(input, hint || "default");
- if (typeof res !== "object") return res;
- throw new TypeError("@@toPrimitive must return a primitive value.");
- }
- return (hint === "string" ? String : Number)(input);
- }
- `;
- helpers.toPropertyKey = helper("7.1.5")`
- import toPrimitive from "toPrimitive";
-
- export default function _toPropertyKey(arg) {
- var key = toPrimitive(arg, "string");
- return typeof key === "symbol" ? key : String(key);
- }
- `;
- helpers.initializerWarningHelper = helper("7.0.0-beta.0")`
- export default function _initializerWarningHelper(descriptor, context){
- throw new Error(
- 'Decorating class property failed. Please ensure that ' +
- 'proposal-class-properties is enabled and runs after the decorators transform.'
- );
- }
- `;
- helpers.initializerDefineProperty = helper("7.0.0-beta.0")`
- export default function _initializerDefineProperty(target, property, descriptor, context){
- if (!descriptor) return;
-
- Object.defineProperty(target, property, {
- enumerable: descriptor.enumerable,
- configurable: descriptor.configurable,
- writable: descriptor.writable,
- value: descriptor.initializer ? descriptor.initializer.call(context) : void 0,
- });
- }
- `;
- helpers.applyDecoratedDescriptor = helper("7.0.0-beta.0")`
- export default function _applyDecoratedDescriptor(target, property, decorators, descriptor, context){
- var desc = {};
- Object.keys(descriptor).forEach(function(key){
- desc[key] = descriptor[key];
- });
- desc.enumerable = !!desc.enumerable;
- desc.configurable = !!desc.configurable;
- if ('value' in desc || desc.initializer){
- desc.writable = true;
- }
-
- desc = decorators.slice().reverse().reduce(function(desc, decorator){
- return decorator(target, property, desc) || desc;
- }, desc);
-
- if (context && desc.initializer !== void 0){
- desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
- desc.initializer = undefined;
- }
-
- if (desc.initializer === void 0){
- Object.defineProperty(target, property, desc);
- desc = null;
- }
-
- return desc;
- }
- `;
- helpers.classPrivateFieldLooseKey = helper("7.0.0-beta.0")`
- var id = 0;
- export default function _classPrivateFieldKey(name) {
- return "__private_" + (id++) + "_" + name;
- }
- `;
- helpers.classPrivateFieldLooseBase = helper("7.0.0-beta.0")`
- export default function _classPrivateFieldBase(receiver, privateKey) {
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
- throw new TypeError("attempted to use private field on non-instance");
- }
- return receiver;
- }
- `;
- helpers.classPrivateFieldGet = helper("7.0.0-beta.0")`
- import classApplyDescriptorGet from "classApplyDescriptorGet";
- import classExtractFieldDescriptor from "classExtractFieldDescriptor";
- export default function _classPrivateFieldGet(receiver, privateMap) {
- var descriptor = classExtractFieldDescriptor(receiver, privateMap, "get");
- return classApplyDescriptorGet(receiver, descriptor);
- }
- `;
- helpers.classPrivateFieldSet = helper("7.0.0-beta.0")`
- import classApplyDescriptorSet from "classApplyDescriptorSet";
- import classExtractFieldDescriptor from "classExtractFieldDescriptor";
- export default function _classPrivateFieldSet(receiver, privateMap, value) {
- var descriptor = classExtractFieldDescriptor(receiver, privateMap, "set");
- classApplyDescriptorSet(receiver, descriptor, value);
- return value;
- }
- `;
- helpers.classPrivateFieldDestructureSet = helper("7.4.4")`
- import classApplyDescriptorDestructureSet from "classApplyDescriptorDestructureSet";
- import classExtractFieldDescriptor from "classExtractFieldDescriptor";
- export default function _classPrivateFieldDestructureSet(receiver, privateMap) {
- var descriptor = classExtractFieldDescriptor(receiver, privateMap, "set");
- return classApplyDescriptorDestructureSet(receiver, descriptor);
- }
- `;
- helpers.classExtractFieldDescriptor = helper("7.13.10")`
- export default function _classExtractFieldDescriptor(receiver, privateMap, action) {
- if (!privateMap.has(receiver)) {
- throw new TypeError("attempted to " + action + " private field on non-instance");
- }
- return privateMap.get(receiver);
- }
- `;
- helpers.classStaticPrivateFieldSpecGet = helper("7.0.2")`
- import classApplyDescriptorGet from "classApplyDescriptorGet";
- import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess";
- import classCheckPrivateStaticFieldDescriptor from "classCheckPrivateStaticFieldDescriptor";
- export default function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
- classCheckPrivateStaticAccess(receiver, classConstructor);
- classCheckPrivateStaticFieldDescriptor(descriptor, "get");
- return classApplyDescriptorGet(receiver, descriptor);
- }
- `;
- helpers.classStaticPrivateFieldSpecSet = helper("7.0.2")`
- import classApplyDescriptorSet from "classApplyDescriptorSet";
- import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess";
- import classCheckPrivateStaticFieldDescriptor from "classCheckPrivateStaticFieldDescriptor";
- export default function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) {
- classCheckPrivateStaticAccess(receiver, classConstructor);
- classCheckPrivateStaticFieldDescriptor(descriptor, "set");
- classApplyDescriptorSet(receiver, descriptor, value);
- return value;
- }
- `;
- helpers.classStaticPrivateMethodGet = helper("7.3.2")`
- import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess";
- export default function _classStaticPrivateMethodGet(receiver, classConstructor, method) {
- classCheckPrivateStaticAccess(receiver, classConstructor);
- return method;
- }
- `;
- helpers.classStaticPrivateMethodSet = helper("7.3.2")`
- export default function _classStaticPrivateMethodSet() {
- throw new TypeError("attempted to set read only static private field");
- }
- `;
- helpers.classApplyDescriptorGet = helper("7.13.10")`
- export default function _classApplyDescriptorGet(receiver, descriptor) {
- if (descriptor.get) {
- return descriptor.get.call(receiver);
- }
- return descriptor.value;
- }
- `;
- helpers.classApplyDescriptorSet = helper("7.13.10")`
- export default function _classApplyDescriptorSet(receiver, descriptor, value) {
- if (descriptor.set) {
- descriptor.set.call(receiver, value);
- } else {
- if (!descriptor.writable) {
- // This should only throw in strict mode, but class bodies are
- // always strict and private fields can only be used inside
- // class bodies.
- throw new TypeError("attempted to set read only private field");
- }
- descriptor.value = value;
- }
- }
- `;
- helpers.classApplyDescriptorDestructureSet = helper("7.13.10")`
- export default function _classApplyDescriptorDestructureSet(receiver, descriptor) {
- if (descriptor.set) {
- if (!("__destrObj" in descriptor)) {
- descriptor.__destrObj = {
- set value(v) {
- descriptor.set.call(receiver, v)
- },
- };
- }
- return descriptor.__destrObj;
- } else {
- if (!descriptor.writable) {
- // This should only throw in strict mode, but class bodies are
- // always strict and private fields can only be used inside
- // class bodies.
- throw new TypeError("attempted to set read only private field");
- }
-
- return descriptor;
- }
- }
- `;
- helpers.classStaticPrivateFieldDestructureSet = helper("7.13.10")`
- import classApplyDescriptorDestructureSet from "classApplyDescriptorDestructureSet";
- import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess";
- import classCheckPrivateStaticFieldDescriptor from "classCheckPrivateStaticFieldDescriptor";
- export default function _classStaticPrivateFieldDestructureSet(receiver, classConstructor, descriptor) {
- classCheckPrivateStaticAccess(receiver, classConstructor);
- classCheckPrivateStaticFieldDescriptor(descriptor, "set");
- return classApplyDescriptorDestructureSet(receiver, descriptor);
- }
- `;
- helpers.classCheckPrivateStaticAccess = helper("7.13.10")`
- export default function _classCheckPrivateStaticAccess(receiver, classConstructor) {
- if (receiver !== classConstructor) {
- throw new TypeError("Private static access of wrong provenance");
- }
- }
- `;
- helpers.classCheckPrivateStaticFieldDescriptor = helper("7.13.10")`
- export default function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {
- if (descriptor === undefined) {
- throw new TypeError("attempted to " + action + " private static field before its declaration");
- }
- }
- `;
- helpers.decorate = helper("7.1.5")`
- import toArray from "toArray";
- import toPropertyKey from "toPropertyKey";
-
- // These comments are stripped by @babel/template
- /*::
- type PropertyDescriptor =
- | {
- value: any,
- writable: boolean,
- configurable: boolean,
- enumerable: boolean,
- }
- | {
- get?: () => any,
- set?: (v: any) => void,
- configurable: boolean,
- enumerable: boolean,
- };
-
- type FieldDescriptor ={
- writable: boolean,
- configurable: boolean,
- enumerable: boolean,
- };
-
- type Placement = "static" | "prototype" | "own";
- type Key = string | symbol; // PrivateName is not supported yet.
-
- type ElementDescriptor =
- | {
- kind: "method",
- key: Key,
- placement: Placement,
- descriptor: PropertyDescriptor
- }
- | {
- kind: "field",
- key: Key,
- placement: Placement,
- descriptor: FieldDescriptor,
- initializer?: () => any,
- };
-
- // This is exposed to the user code
- type ElementObjectInput = ElementDescriptor & {
- [@@toStringTag]?: "Descriptor"
- };
-
- // This is exposed to the user code
- type ElementObjectOutput = ElementDescriptor & {
- [@@toStringTag]?: "Descriptor"
- extras?: ElementDescriptor[],
- finisher?: ClassFinisher,
- };
-
- // This is exposed to the user code
- type ClassObject = {
- [@@toStringTag]?: "Descriptor",
- kind: "class",
- elements: ElementDescriptor[],
- };
-
- type ElementDecorator = (descriptor: ElementObjectInput) => ?ElementObjectOutput;
- type ClassDecorator = (descriptor: ClassObject) => ?ClassObject;
- type ClassFinisher = <A, B>(cl: Class<A>) => Class<B>;
-
- // Only used by Babel in the transform output, not part of the spec.
- type ElementDefinition =
- | {
- kind: "method",
- value: any,
- key: Key,
- static?: boolean,
- decorators?: ElementDecorator[],
- }
- | {
- kind: "field",
- value: () => any,
- key: Key,
- static?: boolean,
- decorators?: ElementDecorator[],
- };
-
- declare function ClassFactory<C>(initialize: (instance: C) => void): {
- F: Class<C>,
- d: ElementDefinition[]
- }
-
- */
-
- /*::
- // Various combinations with/without extras and with one or many finishers
-
- type ElementFinisherExtras = {
- element: ElementDescriptor,
- finisher?: ClassFinisher,
- extras?: ElementDescriptor[],
- };
-
- type ElementFinishersExtras = {
- element: ElementDescriptor,
- finishers: ClassFinisher[],
- extras: ElementDescriptor[],
- };
-
- type ElementsFinisher = {
- elements: ElementDescriptor[],
- finisher?: ClassFinisher,
- };
-
- type ElementsFinishers = {
- elements: ElementDescriptor[],
- finishers: ClassFinisher[],
- };
-
- */
-
- /*::
-
- type Placements = {
- static: Key[],
- prototype: Key[],
- own: Key[],
- };
-
- */
-
- // ClassDefinitionEvaluation (Steps 26-*)
- export default function _decorate(
- decorators /*: ClassDecorator[] */,
- factory /*: ClassFactory */,
- superClass /*: ?Class<*> */,
- mixins /*: ?Array<Function> */,
- ) /*: Class<*> */ {
- var api = _getDecoratorsApi();
- if (mixins) {
- for (var i = 0; i < mixins.length; i++) {
- api = mixins[i](api);
- }
- }
-
- var r = factory(function initialize(O) {
- api.initializeInstanceElements(O, decorated.elements);
- }, superClass);
- var decorated = api.decorateClass(
- _coalesceClassElements(r.d.map(_createElementDescriptor)),
- decorators,
- );
-
- api.initializeClassElements(r.F, decorated.elements);
-
- return api.runClassFinishers(r.F, decorated.finishers);
- }
-
- function _getDecoratorsApi() {
- _getDecoratorsApi = function() {
- return api;
- };
-
- var api = {
- elementsDefinitionOrder: [["method"], ["field"]],
-
- // InitializeInstanceElements
- initializeInstanceElements: function(
- /*::<C>*/ O /*: C */,
- elements /*: ElementDescriptor[] */,
- ) {
- ["method", "field"].forEach(function(kind) {
- elements.forEach(function(element /*: ElementDescriptor */) {
- if (element.kind === kind && element.placement === "own") {
- this.defineClassElement(O, element);
- }
- }, this);
- }, this);
- },
-
- // InitializeClassElements
- initializeClassElements: function(
- /*::<C>*/ F /*: Class<C> */,
- elements /*: ElementDescriptor[] */,
- ) {
- var proto = F.prototype;
-
- ["method", "field"].forEach(function(kind) {
- elements.forEach(function(element /*: ElementDescriptor */) {
- var placement = element.placement;
- if (
- element.kind === kind &&
- (placement === "static" || placement === "prototype")
- ) {
- var receiver = placement === "static" ? F : proto;
- this.defineClassElement(receiver, element);
- }
- }, this);
- }, this);
- },
-
- // DefineClassElement
- defineClassElement: function(
- /*::<C>*/ receiver /*: C | Class<C> */,
- element /*: ElementDescriptor */,
- ) {
- var descriptor /*: PropertyDescriptor */ = element.descriptor;
- if (element.kind === "field") {
- var initializer = element.initializer;
- descriptor = {
- enumerable: descriptor.enumerable,
- writable: descriptor.writable,
- configurable: descriptor.configurable,
- value: initializer === void 0 ? void 0 : initializer.call(receiver),
- };
- }
- Object.defineProperty(receiver, element.key, descriptor);
- },
-
- // DecorateClass
- decorateClass: function(
- elements /*: ElementDescriptor[] */,
- decorators /*: ClassDecorator[] */,
- ) /*: ElementsFinishers */ {
- var newElements /*: ElementDescriptor[] */ = [];
- var finishers /*: ClassFinisher[] */ = [];
- var placements /*: Placements */ = {
- static: [],
- prototype: [],
- own: [],
- };
-
- elements.forEach(function(element /*: ElementDescriptor */) {
- this.addElementPlacement(element, placements);
- }, this);
-
- elements.forEach(function(element /*: ElementDescriptor */) {
- if (!_hasDecorators(element)) return newElements.push(element);
-
- var elementFinishersExtras /*: ElementFinishersExtras */ = this.decorateElement(
- element,
- placements,
- );
- newElements.push(elementFinishersExtras.element);
- newElements.push.apply(newElements, elementFinishersExtras.extras);
- finishers.push.apply(finishers, elementFinishersExtras.finishers);
- }, this);
-
- if (!decorators) {
- return { elements: newElements, finishers: finishers };
- }
-
- var result /*: ElementsFinishers */ = this.decorateConstructor(
- newElements,
- decorators,
- );
- finishers.push.apply(finishers, result.finishers);
- result.finishers = finishers;
-
- return result;
- },
-
- // AddElementPlacement
- addElementPlacement: function(
- element /*: ElementDescriptor */,
- placements /*: Placements */,
- silent /*: boolean */,
- ) {
- var keys = placements[element.placement];
- if (!silent && keys.indexOf(element.key) !== -1) {
- throw new TypeError("Duplicated element (" + element.key + ")");
- }
- keys.push(element.key);
- },
-
- // DecorateElement
- decorateElement: function(
- element /*: ElementDescriptor */,
- placements /*: Placements */,
- ) /*: ElementFinishersExtras */ {
- var extras /*: ElementDescriptor[] */ = [];
- var finishers /*: ClassFinisher[] */ = [];
-
- for (
- var decorators = element.decorators, i = decorators.length - 1;
- i >= 0;
- i--
- ) {
- // (inlined) RemoveElementPlacement
- var keys = placements[element.placement];
- keys.splice(keys.indexOf(element.key), 1);
-
- var elementObject /*: ElementObjectInput */ = this.fromElementDescriptor(
- element,
- );
- var elementFinisherExtras /*: ElementFinisherExtras */ = this.toElementFinisherExtras(
- (0, decorators[i])(elementObject) /*: ElementObjectOutput */ ||
- elementObject,
- );
-
- element = elementFinisherExtras.element;
- this.addElementPlacement(element, placements);
-
- if (elementFinisherExtras.finisher) {
- finishers.push(elementFinisherExtras.finisher);
- }
-
- var newExtras /*: ElementDescriptor[] | void */ =
- elementFinisherExtras.extras;
- if (newExtras) {
- for (var j = 0; j < newExtras.length; j++) {
- this.addElementPlacement(newExtras[j], placements);
- }
- extras.push.apply(extras, newExtras);
- }
- }
-
- return { element: element, finishers: finishers, extras: extras };
- },
-
- // DecorateConstructor
- decorateConstructor: function(
- elements /*: ElementDescriptor[] */,
- decorators /*: ClassDecorator[] */,
- ) /*: ElementsFinishers */ {
- var finishers /*: ClassFinisher[] */ = [];
-
- for (var i = decorators.length - 1; i >= 0; i--) {
- var obj /*: ClassObject */ = this.fromClassDescriptor(elements);
- var elementsAndFinisher /*: ElementsFinisher */ = this.toClassDescriptor(
- (0, decorators[i])(obj) /*: ClassObject */ || obj,
- );
-
- if (elementsAndFinisher.finisher !== undefined) {
- finishers.push(elementsAndFinisher.finisher);
- }
-
- if (elementsAndFinisher.elements !== undefined) {
- elements = elementsAndFinisher.elements;
-
- for (var j = 0; j < elements.length - 1; j++) {
- for (var k = j + 1; k < elements.length; k++) {
- if (
- elements[j].key === elements[k].key &&
- elements[j].placement === elements[k].placement
- ) {
- throw new TypeError(
- "Duplicated element (" + elements[j].key + ")",
- );
- }
- }
- }
- }
- }
-
- return { elements: elements, finishers: finishers };
- },
-
- // FromElementDescriptor
- fromElementDescriptor: function(
- element /*: ElementDescriptor */,
- ) /*: ElementObject */ {
- var obj /*: ElementObject */ = {
- kind: element.kind,
- key: element.key,
- placement: element.placement,
- descriptor: element.descriptor,
- };
-
- var desc = {
- value: "Descriptor",
- configurable: true,
- };
- Object.defineProperty(obj, Symbol.toStringTag, desc);
-
- if (element.kind === "field") obj.initializer = element.initializer;
-
- return obj;
- },
-
- // ToElementDescriptors
- toElementDescriptors: function(
- elementObjects /*: ElementObject[] */,
- ) /*: ElementDescriptor[] */ {
- if (elementObjects === undefined) return;
- return toArray(elementObjects).map(function(elementObject) {
- var element = this.toElementDescriptor(elementObject);
- this.disallowProperty(elementObject, "finisher", "An element descriptor");
- this.disallowProperty(elementObject, "extras", "An element descriptor");
- return element;
- }, this);
- },
-
- // ToElementDescriptor
- toElementDescriptor: function(
- elementObject /*: ElementObject */,
- ) /*: ElementDescriptor */ {
- var kind = String(elementObject.kind);
- if (kind !== "method" && kind !== "field") {
- throw new TypeError(
- 'An element descriptor\\'s .kind property must be either "method" or' +
- ' "field", but a decorator created an element descriptor with' +
- ' .kind "' +
- kind +
- '"',
- );
- }
-
- var key = toPropertyKey(elementObject.key);
-
- var placement = String(elementObject.placement);
- if (
- placement !== "static" &&
- placement !== "prototype" &&
- placement !== "own"
- ) {
- throw new TypeError(
- 'An element descriptor\\'s .placement property must be one of "static",' +
- ' "prototype" or "own", but a decorator created an element descriptor' +
- ' with .placement "' +
- placement +
- '"',
- );
- }
-
- var descriptor /*: PropertyDescriptor */ = elementObject.descriptor;
-
- this.disallowProperty(elementObject, "elements", "An element descriptor");
-
- var element /*: ElementDescriptor */ = {
- kind: kind,
- key: key,
- placement: placement,
- descriptor: Object.assign({}, descriptor),
- };
-
- if (kind !== "field") {
- this.disallowProperty(elementObject, "initializer", "A method descriptor");
- } else {
- this.disallowProperty(
- descriptor,
- "get",
- "The property descriptor of a field descriptor",
- );
- this.disallowProperty(
- descriptor,
- "set",
- "The property descriptor of a field descriptor",
- );
- this.disallowProperty(
- descriptor,
- "value",
- "The property descriptor of a field descriptor",
- );
-
- element.initializer = elementObject.initializer;
- }
-
- return element;
- },
-
- toElementFinisherExtras: function(
- elementObject /*: ElementObject */,
- ) /*: ElementFinisherExtras */ {
- var element /*: ElementDescriptor */ = this.toElementDescriptor(
- elementObject,
- );
- var finisher /*: ClassFinisher */ = _optionalCallableProperty(
- elementObject,
- "finisher",
- );
- var extras /*: ElementDescriptors[] */ = this.toElementDescriptors(
- elementObject.extras,
- );
-
- return { element: element, finisher: finisher, extras: extras };
- },
-
- // FromClassDescriptor
- fromClassDescriptor: function(
- elements /*: ElementDescriptor[] */,
- ) /*: ClassObject */ {
- var obj = {
- kind: "class",
- elements: elements.map(this.fromElementDescriptor, this),
- };
-
- var desc = { value: "Descriptor", configurable: true };
- Object.defineProperty(obj, Symbol.toStringTag, desc);
-
- return obj;
- },
-
- // ToClassDescriptor
- toClassDescriptor: function(
- obj /*: ClassObject */,
- ) /*: ElementsFinisher */ {
- var kind = String(obj.kind);
- if (kind !== "class") {
- throw new TypeError(
- 'A class descriptor\\'s .kind property must be "class", but a decorator' +
- ' created a class descriptor with .kind "' +
- kind +
- '"',
- );
- }
-
- this.disallowProperty(obj, "key", "A class descriptor");
- this.disallowProperty(obj, "placement", "A class descriptor");
- this.disallowProperty(obj, "descriptor", "A class descriptor");
- this.disallowProperty(obj, "initializer", "A class descriptor");
- this.disallowProperty(obj, "extras", "A class descriptor");
-
- var finisher = _optionalCallableProperty(obj, "finisher");
- var elements = this.toElementDescriptors(obj.elements);
-
- return { elements: elements, finisher: finisher };
- },
-
- // RunClassFinishers
- runClassFinishers: function(
- constructor /*: Class<*> */,
- finishers /*: ClassFinisher[] */,
- ) /*: Class<*> */ {
- for (var i = 0; i < finishers.length; i++) {
- var newConstructor /*: ?Class<*> */ = (0, finishers[i])(constructor);
- if (newConstructor !== undefined) {
- // NOTE: This should check if IsConstructor(newConstructor) is false.
- if (typeof newConstructor !== "function") {
- throw new TypeError("Finishers must return a constructor.");
- }
- constructor = newConstructor;
- }
- }
- return constructor;
- },
-
- disallowProperty: function(obj, name, objectType) {
- if (obj[name] !== undefined) {
- throw new TypeError(objectType + " can't have a ." + name + " property.");
- }
- }
- };
-
- return api;
- }
-
- // ClassElementEvaluation
- function _createElementDescriptor(
- def /*: ElementDefinition */,
- ) /*: ElementDescriptor */ {
- var key = toPropertyKey(def.key);
-
- var descriptor /*: PropertyDescriptor */;
- if (def.kind === "method") {
- descriptor = {
- value: def.value,
- writable: true,
- configurable: true,
- enumerable: false,
- };
- } else if (def.kind === "get") {
- descriptor = { get: def.value, configurable: true, enumerable: false };
- } else if (def.kind === "set") {
- descriptor = { set: def.value, configurable: true, enumerable: false };
- } else if (def.kind === "field") {
- descriptor = { configurable: true, writable: true, enumerable: true };
- }
-
- var element /*: ElementDescriptor */ = {
- kind: def.kind === "field" ? "field" : "method",
- key: key,
- placement: def.static
- ? "static"
- : def.kind === "field"
- ? "own"
- : "prototype",
- descriptor: descriptor,
- };
- if (def.decorators) element.decorators = def.decorators;
- if (def.kind === "field") element.initializer = def.value;
-
- return element;
- }
-
- // CoalesceGetterSetter
- function _coalesceGetterSetter(
- element /*: ElementDescriptor */,
- other /*: ElementDescriptor */,
- ) {
- if (element.descriptor.get !== undefined) {
- other.descriptor.get = element.descriptor.get;
- } else {
- other.descriptor.set = element.descriptor.set;
- }
- }
-
- // CoalesceClassElements
- function _coalesceClassElements(
- elements /*: ElementDescriptor[] */,
- ) /*: ElementDescriptor[] */ {
- var newElements /*: ElementDescriptor[] */ = [];
-
- var isSameElement = function(
- other /*: ElementDescriptor */,
- ) /*: boolean */ {
- return (
- other.kind === "method" &&
- other.key === element.key &&
- other.placement === element.placement
- );
- };
-
- for (var i = 0; i < elements.length; i++) {
- var element /*: ElementDescriptor */ = elements[i];
- var other /*: ElementDescriptor */;
-
- if (
- element.kind === "method" &&
- (other = newElements.find(isSameElement))
- ) {
- if (
- _isDataDescriptor(element.descriptor) ||
- _isDataDescriptor(other.descriptor)
- ) {
- if (_hasDecorators(element) || _hasDecorators(other)) {
- throw new ReferenceError(
- "Duplicated methods (" + element.key + ") can't be decorated.",
- );
- }
- other.descriptor = element.descriptor;
- } else {
- if (_hasDecorators(element)) {
- if (_hasDecorators(other)) {
- throw new ReferenceError(
- "Decorators can't be placed on different accessors with for " +
- "the same property (" +
- element.key +
- ").",
- );
- }
- other.decorators = element.decorators;
- }
- _coalesceGetterSetter(element, other);
- }
- } else {
- newElements.push(element);
- }
- }
-
- return newElements;
- }
-
- function _hasDecorators(element /*: ElementDescriptor */) /*: boolean */ {
- return element.decorators && element.decorators.length;
- }
-
- function _isDataDescriptor(desc /*: PropertyDescriptor */) /*: boolean */ {
- return (
- desc !== undefined &&
- !(desc.value === undefined && desc.writable === undefined)
- );
- }
-
- function _optionalCallableProperty /*::<T>*/(
- obj /*: T */,
- name /*: $Keys<T> */,
- ) /*: ?Function */ {
- var value = obj[name];
- if (value !== undefined && typeof value !== "function") {
- throw new TypeError("Expected '" + name + "' to be a function");
- }
- return value;
- }
-
- `;
- helpers.classPrivateMethodGet = helper("7.1.6")`
- export default function _classPrivateMethodGet(receiver, privateSet, fn) {
- if (!privateSet.has(receiver)) {
- throw new TypeError("attempted to get private field on non-instance");
- }
- return fn;
- }
- `;
- {
- helpers.classPrivateMethodSet = helper("7.1.6")`
- export default function _classPrivateMethodSet() {
- throw new TypeError("attempted to reassign private method");
- }
- `;
- }
|