utils.js 2.6 KB

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