| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | exports.__esModule = true;
|
|---|
| 4 | exports.BABEL_RUNTIME = void 0;
|
|---|
| 5 | exports.callMethod = callMethod;
|
|---|
| 6 | exports.coreJSModule = coreJSModule;
|
|---|
| 7 | exports.coreJSPureHelper = coreJSPureHelper;
|
|---|
| 8 | exports.extractOptionalCheck = extractOptionalCheck;
|
|---|
| 9 | exports.isCoreJSSource = isCoreJSSource;
|
|---|
| 10 | exports.maybeMemoizeContext = maybeMemoizeContext;
|
|---|
| 11 | var _babel = _interopRequireWildcard(require("@babel/core"));
|
|---|
| 12 | var _entries = _interopRequireDefault(require("../core-js-compat/entries.js"));
|
|---|
| 13 | function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|---|
| 14 | function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|---|
| 15 | const {
|
|---|
| 16 | types: t
|
|---|
| 17 | } = _babel.default || _babel;
|
|---|
| 18 | const BABEL_RUNTIME = exports.BABEL_RUNTIME = "@babel/runtime-corejs3";
|
|---|
| 19 | function callMethod(path, id, optionalCall, wrapCallee) {
|
|---|
| 20 | const [context1, context2] = maybeMemoizeContext(path.node, path.scope);
|
|---|
| 21 | let callee = t.callExpression(id, [context1]);
|
|---|
| 22 | if (wrapCallee) callee = wrapCallee(callee);
|
|---|
| 23 | const call = t.identifier("call");
|
|---|
| 24 | path.replaceWith(optionalCall ? t.optionalMemberExpression(callee, call, false, true) : t.memberExpression(callee, call));
|
|---|
| 25 | path.parentPath.unshiftContainer("arguments", context2);
|
|---|
| 26 | }
|
|---|
| 27 | function maybeMemoizeContext(node, scope) {
|
|---|
| 28 | const {
|
|---|
| 29 | object
|
|---|
| 30 | } = node;
|
|---|
| 31 | let context1, context2;
|
|---|
| 32 | if (t.isIdentifier(object)) {
|
|---|
| 33 | context2 = object;
|
|---|
| 34 | context1 = t.cloneNode(object);
|
|---|
| 35 | } else {
|
|---|
| 36 | context2 = scope.generateDeclaredUidIdentifier("context");
|
|---|
| 37 | context1 = t.assignmentExpression("=", t.cloneNode(context2), object);
|
|---|
| 38 | }
|
|---|
| 39 | return [context1, context2];
|
|---|
| 40 | }
|
|---|
| 41 | function extractOptionalCheck(scope, node) {
|
|---|
| 42 | let optionalNode = node;
|
|---|
| 43 | while (!optionalNode.optional && t.isOptionalMemberExpression(optionalNode.object)) {
|
|---|
| 44 | optionalNode = optionalNode.object;
|
|---|
| 45 | }
|
|---|
| 46 | optionalNode.optional = false;
|
|---|
| 47 | const ctx = scope.generateDeclaredUidIdentifier("context");
|
|---|
| 48 | const assign = t.assignmentExpression("=", ctx, optionalNode.object);
|
|---|
| 49 | optionalNode.object = t.cloneNode(ctx);
|
|---|
| 50 | return ifNotNullish => t.conditionalExpression(t.binaryExpression("==", assign, t.nullLiteral()), t.unaryExpression("void", t.numericLiteral(0)), ifNotNullish);
|
|---|
| 51 | }
|
|---|
| 52 | function isCoreJSSource(source) {
|
|---|
| 53 | if (typeof source === "string") {
|
|---|
| 54 | source = source.replace(/\\/g, "/").replace(/(\/(index)?)?(\.js)?$/i, "").toLowerCase();
|
|---|
| 55 | }
|
|---|
| 56 | return Object.prototype.hasOwnProperty.call(_entries.default, source) && _entries.default[source];
|
|---|
| 57 | }
|
|---|
| 58 | function coreJSModule(name) {
|
|---|
| 59 | return `core-js/modules/${name}.js`;
|
|---|
| 60 | }
|
|---|
| 61 | function coreJSPureHelper(name, useBabelRuntime, ext) {
|
|---|
| 62 | return useBabelRuntime ? `${BABEL_RUNTIME}/core-js/${name}${ext}` : `core-js-pure/features/${name}.js`;
|
|---|
| 63 | } |
|---|