source: trip-planner-front/node_modules/@babel/plugin-proposal-async-generator-functions/lib/index.js@ 1ad8e64

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

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _helperPluginUtils = require("@babel/helper-plugin-utils");
9
10var _helperRemapAsyncToGenerator = require("@babel/helper-remap-async-to-generator");
11
12var _pluginSyntaxAsyncGenerators = require("@babel/plugin-syntax-async-generators");
13
14var _core = require("@babel/core");
15
16var _forAwait = require("./for-await");
17
18var _default = (0, _helperPluginUtils.declare)(api => {
19 api.assertVersion(7);
20 const yieldStarVisitor = {
21 Function(path) {
22 path.skip();
23 },
24
25 YieldExpression({
26 node
27 }, state) {
28 if (!node.delegate) return;
29 const callee = state.addHelper("asyncGeneratorDelegate");
30 node.argument = _core.types.callExpression(callee, [_core.types.callExpression(state.addHelper("asyncIterator"), [node.argument]), state.addHelper("awaitAsyncGenerator")]);
31 }
32
33 };
34 const forAwaitVisitor = {
35 Function(path) {
36 path.skip();
37 },
38
39 ForOfStatement(path, {
40 file
41 }) {
42 const {
43 node
44 } = path;
45 if (!node.await) return;
46 const build = (0, _forAwait.default)(path, {
47 getAsyncIterator: file.addHelper("asyncIterator")
48 });
49 const {
50 declar,
51 loop
52 } = build;
53 const block = loop.body;
54 path.ensureBlock();
55
56 if (declar) {
57 block.body.push(declar);
58 }
59
60 block.body = block.body.concat(node.body.body);
61
62 _core.types.inherits(loop, node);
63
64 _core.types.inherits(loop.body, node.body);
65
66 if (build.replaceParent) {
67 path.parentPath.replaceWithMultiple(build.node);
68 } else {
69 path.replaceWithMultiple(build.node);
70 }
71 }
72
73 };
74 const visitor = {
75 Function(path, state) {
76 if (!path.node.async) return;
77 path.traverse(forAwaitVisitor, state);
78 if (!path.node.generator) return;
79 path.traverse(yieldStarVisitor, state);
80 (0, _helperRemapAsyncToGenerator.default)(path, {
81 wrapAsync: state.addHelper("wrapAsyncGenerator"),
82 wrapAwait: state.addHelper("awaitAsyncGenerator")
83 });
84 }
85
86 };
87 return {
88 name: "proposal-async-generator-functions",
89 inherits: _pluginSyntaxAsyncGenerators.default,
90 visitor: {
91 Program(path, state) {
92 path.traverse(visitor, state);
93 }
94
95 }
96 };
97});
98
99exports.default = _default;
Note: See TracBrowser for help on using the repository browser.