You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

4 years ago
  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";
  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: "regenerator-entry",
  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. }