index.mjs 1.6 KB

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