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.

44 lines
903 B

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 _default() {
  8. return {
  9. name: "regenerator-usage",
  10. pre() {
  11. this.usesRegenerator = false;
  12. },
  13. visitor: {
  14. Function(path) {
  15. const {
  16. node
  17. } = path;
  18. if (!this.usesRegenerator && (node.generator || node.async)) {
  19. this.usesRegenerator = true;
  20. (0, _utils.createImport)(path, "regenerator-runtime");
  21. }
  22. }
  23. },
  24. post() {
  25. if (this.opts.debug && this.usesRegenerator) {
  26. let filename = this.file.opts.filename;
  27. if (process.env.BABEL_ENV === "test") {
  28. filename = filename.replace(/\\/g, "/");
  29. }
  30. console.log(`\n[${filename}] Based on your code and targets, added regenerator-runtime.`);
  31. }
  32. }
  33. };
  34. }