index.mjs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 = false
  14. } = {}
  15. } = options;
  16. return {
  17. name: "regenerator",
  18. polyfills: ["regenerator-runtime"],
  19. usageGlobal(meta, utils) {
  20. if (isRegenerator(meta)) {
  21. debug("regenerator-runtime");
  22. utils.injectGlobalImport("regenerator-runtime/runtime.js");
  23. }
  24. },
  25. usagePure(meta, utils, path) {
  26. if (isRegenerator(meta)) {
  27. let pureName = "regenerator-runtime";
  28. if (useBabelRuntime) {
  29. var _get;
  30. const runtimeName = (_get = path.hub.file.get("runtimeHelpersModuleName")) != null ? _get : "@babel/runtime";
  31. pureName = `${runtimeName}/regenerator`;
  32. }
  33. path.replaceWith(utils.injectDefaultImport(pureName, "regenerator-runtime"));
  34. }
  35. }
  36. };
  37. });
  38. const isRegenerator = meta => meta.kind === "global" && meta.name === "regeneratorRuntime";
  39. function shallowEqual(obj1, obj2) {
  40. return JSON.stringify(obj1) === JSON.stringify(obj2);
  41. }
  42. export default index;
  43. //# sourceMappingURL=index.mjs.map