regenerator.cjs 1.2 KB

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