utils.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.BABEL_RUNTIME = void 0;
  4. exports.callMethod = callMethod;
  5. exports.coreJSModule = coreJSModule;
  6. exports.coreJSPureHelper = coreJSPureHelper;
  7. exports.isCoreJSSource = isCoreJSSource;
  8. var _babel = _interopRequireWildcard(require("@babel/core"));
  9. var _entries = _interopRequireDefault(require("../core-js-compat/entries.js"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. 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); }
  12. 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; }
  13. const {
  14. types: t
  15. } = _babel.default || _babel;
  16. const BABEL_RUNTIME = "@babel/runtime-corejs3";
  17. exports.BABEL_RUNTIME = BABEL_RUNTIME;
  18. function callMethod(path, id) {
  19. const {
  20. object
  21. } = path.node;
  22. let context1, context2;
  23. if (t.isIdentifier(object)) {
  24. context1 = object;
  25. context2 = t.cloneNode(object);
  26. } else {
  27. context1 = path.scope.generateDeclaredUidIdentifier("context");
  28. context2 = t.assignmentExpression("=", t.cloneNode(context1), object);
  29. }
  30. path.replaceWith(t.memberExpression(t.callExpression(id, [context2]), t.identifier("call")));
  31. path.parentPath.unshiftContainer("arguments", context1);
  32. }
  33. function isCoreJSSource(source) {
  34. if (typeof source === "string") {
  35. source = source.replace(/\\/g, "/").replace(/(\/(index)?)?(\.js)?$/i, "").toLowerCase();
  36. }
  37. return Object.prototype.hasOwnProperty.call(_entries.default, source) && _entries.default[source];
  38. }
  39. function coreJSModule(name) {
  40. return `core-js/modules/${name}.js`;
  41. }
  42. function coreJSPureHelper(name, useBabelRuntime, ext) {
  43. return useBabelRuntime ? `${BABEL_RUNTIME}/core-js/${name}${ext}` : `core-js-pure/features/${name}.js`;
  44. }