source: trip-planner-front/node_modules/@babel/helper-remap-async-to-generator/lib/index.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = _default;
7
8var _helperWrapFunction = require("@babel/helper-wrap-function");
9
10var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
11
12var _t = require("@babel/types");
13
14const {
15 callExpression,
16 cloneNode,
17 isIdentifier,
18 isThisExpression,
19 yieldExpression
20} = _t;
21const awaitVisitor = {
22 Function(path) {
23 path.skip();
24 },
25
26 AwaitExpression(path, {
27 wrapAwait
28 }) {
29 const argument = path.get("argument");
30
31 if (path.parentPath.isYieldExpression()) {
32 path.replaceWith(argument.node);
33 return;
34 }
35
36 path.replaceWith(yieldExpression(wrapAwait ? callExpression(cloneNode(wrapAwait), [argument.node]) : argument.node));
37 }
38
39};
40
41function _default(path, helpers, noNewArrows) {
42 path.traverse(awaitVisitor, {
43 wrapAwait: helpers.wrapAwait
44 });
45 const isIIFE = checkIsIIFE(path);
46 path.node.async = false;
47 path.node.generator = true;
48 (0, _helperWrapFunction.default)(path, cloneNode(helpers.wrapAsync), noNewArrows);
49 const isProperty = path.isObjectMethod() || path.isClassMethod() || path.parentPath.isObjectProperty() || path.parentPath.isClassProperty();
50
51 if (!isProperty && !isIIFE && path.isExpression()) {
52 (0, _helperAnnotateAsPure.default)(path);
53 }
54
55 function checkIsIIFE(path) {
56 if (path.parentPath.isCallExpression({
57 callee: path.node
58 })) {
59 return true;
60 }
61
62 const {
63 parentPath
64 } = path;
65
66 if (parentPath.isMemberExpression() && isIdentifier(parentPath.node.property, {
67 name: "bind"
68 })) {
69 const {
70 parentPath: bindCall
71 } = parentPath;
72 return bindCall.isCallExpression() && bindCall.node.arguments.length === 1 && isThisExpression(bindCall.node.arguments[0]) && bindCall.parentPath.isCallExpression({
73 callee: bindCall.node
74 });
75 }
76
77 return false;
78 }
79}
Note: See TracBrowser for help on using the repository browser.