index.mjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import defineProvider from '@babel/helper-define-polyfill-provider';
  2. const runtimeCompat = "#__secret_key__@babel/runtime__compatibility";
  3. var index = defineProvider(({
  4. debug,
  5. targets,
  6. babel
  7. }, options) => {
  8. if (!shallowEqual(targets, babel.targets())) {
  9. 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.");
  10. }
  11. const {
  12. [runtimeCompat]: {
  13. useBabelRuntime
  14. } = {
  15. useBabelRuntime: ""
  16. }
  17. } = options;
  18. const pureName = useBabelRuntime ? `${useBabelRuntime}/regenerator` : "regenerator-runtime";
  19. return {
  20. name: "regenerator",
  21. polyfills: ["regenerator-runtime"],
  22. usageGlobal(meta, utils) {
  23. if (isRegenerator(meta)) {
  24. debug("regenerator-runtime");
  25. utils.injectGlobalImport("regenerator-runtime/runtime.js");
  26. }
  27. },
  28. usagePure(meta, utils, path) {
  29. if (isRegenerator(meta)) {
  30. path.replaceWith(utils.injectDefaultImport(pureName, "regenerator-runtime"));
  31. }
  32. }
  33. };
  34. });
  35. const isRegenerator = meta => meta.kind === "global" && meta.name === "regeneratorRuntime";
  36. function shallowEqual(obj1, obj2) {
  37. return JSON.stringify(obj1) === JSON.stringify(obj2);
  38. }
  39. export default index;
  40. //# sourceMappingURL=index.mjs.map