index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _helperDefinePolyfillProvider = _interopRequireDefault(require("@babel/helper-define-polyfill-provider"));
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6. const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
  7. var _default = (0, _helperDefinePolyfillProvider.default)(({
  8. debug,
  9. targets,
  10. babel
  11. }, options) => {
  12. if (!shallowEqual(targets, babel.targets())) {
  13. throw new Error("This plugin does not use the targets option. Only preset-env's targets" + " or top-level targets need to be configured for this plugin to work." + " See https://github.com/babel/babel-polyfills/issues/36 for more" + " details.");
  14. }
  15. const {
  16. [runtimeCompat]: {
  17. useBabelRuntime
  18. } = {
  19. useBabelRuntime: ""
  20. }
  21. } = options;
  22. const pureName = useBabelRuntime ? `${useBabelRuntime}/regenerator` : "regenerator-runtime";
  23. return {
  24. name: "regenerator",
  25. polyfills: ["regenerator-runtime"],
  26. usageGlobal(meta, utils) {
  27. if (isRegenerator(meta)) {
  28. debug("regenerator-runtime");
  29. utils.injectGlobalImport("regenerator-runtime/runtime.js");
  30. }
  31. },
  32. usagePure(meta, utils, path) {
  33. if (isRegenerator(meta)) {
  34. path.replaceWith(utils.injectDefaultImport(pureName, "regenerator-runtime"));
  35. }
  36. }
  37. };
  38. });
  39. exports.default = _default;
  40. const isRegenerator = meta => meta.kind === "global" && meta.name === "regeneratorRuntime";
  41. function shallowEqual(obj1, obj2) {
  42. return JSON.stringify(obj1) === JSON.stringify(obj2);
  43. }