regenerator.cjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ;
  2. const {
  3. getImportSource,
  4. getRequireSource
  5. } = require("./utils.cjs");
  6. function isRegeneratorSource(source) {
  7. return source === "regenerator-runtime/runtime" || source === "regenerator-runtime/runtime.js";
  8. }
  9. module.exports = function () {
  10. const visitor = {
  11. ImportDeclaration(path) {
  12. if (isRegeneratorSource(getImportSource(path))) {
  13. this.regeneratorImportExcluded = true;
  14. path.remove();
  15. }
  16. },
  17. Program(path) {
  18. path.get("body").forEach(bodyPath => {
  19. if (isRegeneratorSource(getRequireSource(bodyPath))) {
  20. this.regeneratorImportExcluded = true;
  21. bodyPath.remove();
  22. }
  23. });
  24. }
  25. };
  26. return {
  27. name: "preset-env/remove-regenerator",
  28. visitor,
  29. pre() {
  30. this.regeneratorImportExcluded = false;
  31. },
  32. post() {
  33. if (this.opts.debug && this.regeneratorImportExcluded) {
  34. let filename = this.file.opts.filename;
  35. if (process.env.BABEL_ENV === "test") {
  36. filename = filename.replace(/\\/g, "/");
  37. }
  38. console.log(`\n[${filename}] Based on your targets, regenerator-runtime import excluded.`);
  39. }
  40. }
  41. };
  42. };
  43. //# sourceMappingURL=regenerator.cjs.map