index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _helperPluginUtils() {
  7. const data = require("@babel/helper-plugin-utils");
  8. _helperPluginUtils = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _helperRemapAsyncToGenerator() {
  14. const data = _interopRequireDefault(require("@babel/helper-remap-async-to-generator"));
  15. _helperRemapAsyncToGenerator = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _helperModuleImports() {
  21. const data = require("@babel/helper-module-imports");
  22. _helperModuleImports = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. function _core() {
  28. const data = require("@babel/core");
  29. _core = function () {
  30. return data;
  31. };
  32. return data;
  33. }
  34. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  35. var _default = (0, _helperPluginUtils().declare)((api, options) => {
  36. api.assertVersion(7);
  37. const {
  38. method,
  39. module
  40. } = options;
  41. if (method && module) {
  42. return {
  43. name: "transform-async-to-generator",
  44. visitor: {
  45. Function(path, state) {
  46. if (!path.node.async || path.node.generator) return;
  47. let wrapAsync = state.methodWrapper;
  48. if (wrapAsync) {
  49. wrapAsync = _core().types.cloneNode(wrapAsync);
  50. } else {
  51. wrapAsync = state.methodWrapper = (0, _helperModuleImports().addNamed)(path, method, module);
  52. }
  53. (0, _helperRemapAsyncToGenerator().default)(path, {
  54. wrapAsync
  55. });
  56. }
  57. }
  58. };
  59. }
  60. return {
  61. name: "transform-async-to-generator",
  62. visitor: {
  63. Function(path, state) {
  64. if (!path.node.async || path.node.generator) return;
  65. (0, _helperRemapAsyncToGenerator().default)(path, {
  66. wrapAsync: state.addHelper("asyncToGenerator")
  67. });
  68. }
  69. }
  70. };
  71. });
  72. exports.default = _default;