source: trip-planner-front/node_modules/@babel/helpers/lib/helpers.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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