1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = _default;
|
---|
7 | var _helperWrapFunction = require("@babel/helper-wrap-function");
|
---|
8 | var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
|
---|
9 | var _core = require("@babel/core");
|
---|
10 | var _traverse = require("@babel/traverse");
|
---|
11 | const {
|
---|
12 | callExpression,
|
---|
13 | cloneNode,
|
---|
14 | isIdentifier,
|
---|
15 | isThisExpression,
|
---|
16 | yieldExpression
|
---|
17 | } = _core.types;
|
---|
18 | const awaitVisitor = _traverse.visitors.environmentVisitor({
|
---|
19 | ArrowFunctionExpression(path) {
|
---|
20 | path.skip();
|
---|
21 | },
|
---|
22 | AwaitExpression(path, {
|
---|
23 | wrapAwait
|
---|
24 | }) {
|
---|
25 | const argument = path.get("argument");
|
---|
26 | path.replaceWith(yieldExpression(wrapAwait ? callExpression(cloneNode(wrapAwait), [argument.node]) : argument.node));
|
---|
27 | }
|
---|
28 | });
|
---|
29 | function _default(path, helpers, noNewArrows, ignoreFunctionLength) {
|
---|
30 | path.traverse(awaitVisitor, {
|
---|
31 | wrapAwait: helpers.wrapAwait
|
---|
32 | });
|
---|
33 | const isIIFE = checkIsIIFE(path);
|
---|
34 | path.node.async = false;
|
---|
35 | path.node.generator = true;
|
---|
36 | (0, _helperWrapFunction.default)(path, cloneNode(helpers.wrapAsync), noNewArrows, ignoreFunctionLength);
|
---|
37 | const isProperty = path.isObjectMethod() || path.isClassMethod() || path.parentPath.isObjectProperty() || path.parentPath.isClassProperty();
|
---|
38 | if (!isProperty && !isIIFE && path.isExpression()) {
|
---|
39 | (0, _helperAnnotateAsPure.default)(path);
|
---|
40 | }
|
---|
41 | function checkIsIIFE(path) {
|
---|
42 | if (path.parentPath.isCallExpression({
|
---|
43 | callee: path.node
|
---|
44 | })) {
|
---|
45 | return true;
|
---|
46 | }
|
---|
47 | const {
|
---|
48 | parentPath
|
---|
49 | } = path;
|
---|
50 | if (parentPath.isMemberExpression() && isIdentifier(parentPath.node.property, {
|
---|
51 | name: "bind"
|
---|
52 | })) {
|
---|
53 | const {
|
---|
54 | parentPath: bindCall
|
---|
55 | } = parentPath;
|
---|
56 | return bindCall.isCallExpression() && bindCall.node.arguments.length === 1 && isThisExpression(bindCall.node.arguments[0]) && bindCall.parentPath.isCallExpression({
|
---|
57 | callee: bindCall.node
|
---|
58 | });
|
---|
59 | }
|
---|
60 | return false;
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | //# sourceMappingURL=index.js.map
|
---|