index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 = require("@babel/helper-remap-async-to-generator");
  8. var _helperModuleImports = require("@babel/helper-module-imports");
  9. var _core = require("@babel/core");
  10. var _default = exports.default = (0, _helperPluginUtils.declare)((api, options) => {
  11. var _api$assumption, _api$assumption2;
  12. api.assertVersion("^7.0.0-0 || >8.0.0-alpha <8.0.0-beta");
  13. const {
  14. method,
  15. module
  16. } = options;
  17. const noNewArrows = (_api$assumption = api.assumption("noNewArrows")) != null ? _api$assumption : true;
  18. const ignoreFunctionLength = (_api$assumption2 = api.assumption("ignoreFunctionLength")) != null ? _api$assumption2 : false;
  19. if (method && module) {
  20. return {
  21. name: "transform-async-to-generator",
  22. visitor: {
  23. Function(path, state) {
  24. if (!path.node.async || path.node.generator) return;
  25. let wrapAsync = state.methodWrapper;
  26. if (wrapAsync) {
  27. wrapAsync = _core.types.cloneNode(wrapAsync);
  28. } else {
  29. wrapAsync = state.methodWrapper = (0, _helperModuleImports.addNamed)(path, method, module);
  30. }
  31. (0, _helperRemapAsyncToGenerator.default)(path, {
  32. wrapAsync
  33. }, noNewArrows, ignoreFunctionLength);
  34. }
  35. }
  36. };
  37. }
  38. return {
  39. name: "transform-async-to-generator",
  40. visitor: {
  41. Function(path, state) {
  42. if (!path.node.async || path.node.generator) return;
  43. (0, _helperRemapAsyncToGenerator.default)(path, {
  44. wrapAsync: state.addHelper("asyncToGenerator")
  45. }, noNewArrows, ignoreFunctionLength);
  46. }
  47. }
  48. };
  49. });
  50. //# sourceMappingURL=index.js.map