source: imaps-frontend/node_modules/@babel/plugin-transform-async-generator-functions/lib/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _helperPluginUtils = require("@babel/helper-plugin-utils");
8var _helperRemapAsyncToGenerator = require("@babel/helper-remap-async-to-generator");
9var _core = require("@babel/core");
10var _traverse = require("@babel/traverse");
11var _forAwait = require("./for-await.js");
12var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
13 api.assertVersion("^7.0.0-0 || >8.0.0-alpha <8.0.0-beta");
14 const yieldStarVisitor = _traverse.visitors.environmentVisitor({
15 ArrowFunctionExpression(path) {
16 path.skip();
17 },
18 YieldExpression({
19 node
20 }, state) {
21 if (!node.delegate) return;
22 const asyncIter = _core.types.callExpression(state.addHelper("asyncIterator"), [node.argument]);
23 node.argument = _core.types.callExpression(state.addHelper("asyncGeneratorDelegate"), [asyncIter, state.addHelper("awaitAsyncGenerator")]);
24 }
25 });
26 const forAwaitVisitor = _traverse.visitors.environmentVisitor({
27 ArrowFunctionExpression(path) {
28 path.skip();
29 },
30 ForOfStatement(path, {
31 file
32 }) {
33 const {
34 node
35 } = path;
36 if (!node.await) return;
37 const build = (0, _forAwait.default)(path, {
38 getAsyncIterator: file.addHelper("asyncIterator")
39 });
40 const {
41 declar,
42 loop
43 } = build;
44 const block = loop.body;
45 path.ensureBlock();
46 if (declar) {
47 block.body.push(declar);
48 if (path.node.body.body.length) {
49 block.body.push(_core.types.blockStatement(path.node.body.body));
50 }
51 } else {
52 block.body.push(...path.node.body.body);
53 }
54 _core.types.inherits(loop, node);
55 _core.types.inherits(loop.body, node.body);
56 const p = build.replaceParent ? path.parentPath : path;
57 p.replaceWithMultiple(build.node);
58 p.scope.parent.crawl();
59 }
60 });
61 const visitor = {
62 Function(path, state) {
63 if (!path.node.async) return;
64 path.traverse(forAwaitVisitor, state);
65 if (!path.node.generator) return;
66 path.traverse(yieldStarVisitor, state);
67 path.setData("@babel/plugin-transform-async-generator-functions/async_generator_function", true);
68 (0, _helperRemapAsyncToGenerator.default)(path, {
69 wrapAsync: state.addHelper("wrapAsyncGenerator"),
70 wrapAwait: state.addHelper("awaitAsyncGenerator")
71 });
72 }
73 };
74 return {
75 name: "transform-async-generator-functions",
76 manipulateOptions: (_, parser) => parser.plugins.push("asyncGenerators"),
77 visitor: {
78 Program(path, state) {
79 path.traverse(visitor, state);
80 }
81 }
82 };
83});
84
85//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.