regenerator.js 1.2 KB

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