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.

61 lines
1.5 KiB

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