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