source: frontend/node_modules/babel-plugin-polyfill-corejs3/lib/utils.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.1 KB
Line 
1"use strict";
2
3exports.__esModule = true;
4exports.BABEL_RUNTIME = void 0;
5exports.callMethod = callMethod;
6exports.coreJSModule = coreJSModule;
7exports.coreJSPureHelper = coreJSPureHelper;
8exports.extractOptionalCheck = extractOptionalCheck;
9exports.isCoreJSSource = isCoreJSSource;
10exports.maybeMemoizeContext = maybeMemoizeContext;
11var _babel = _interopRequireWildcard(require("@babel/core"));
12var _entries = _interopRequireDefault(require("../core-js-compat/entries.js"));
13function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14function _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); }
15const {
16 types: t
17} = _babel.default || _babel;
18const BABEL_RUNTIME = exports.BABEL_RUNTIME = "@babel/runtime-corejs3";
19function 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}
27function 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}
41function 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}
52function 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}
58function coreJSModule(name) {
59 return `core-js/modules/${name}.js`;
60}
61function coreJSPureHelper(name, useBabelRuntime, ext) {
62 return useBabelRuntime ? `${BABEL_RUNTIME}/core-js/${name}${ext}` : `core-js-pure/features/${name}.js`;
63}
Note: See TracBrowser for help on using the repository browser.