source: trip-planner-front/node_modules/@babel/plugin-proposal-async-generator-functions/lib/for-await.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = _default;
7
8var _core = require("@babel/core");
9
10const buildForAwait = (0, _core.template)(`
11 async function wrapper() {
12 var ITERATOR_COMPLETION = true;
13 var ITERATOR_HAD_ERROR_KEY = false;
14 var ITERATOR_ERROR_KEY;
15 try {
16 for (
17 var ITERATOR_KEY = GET_ITERATOR(OBJECT), STEP_KEY, STEP_VALUE;
18 (
19 STEP_KEY = await ITERATOR_KEY.next(),
20 ITERATOR_COMPLETION = STEP_KEY.done,
21 STEP_VALUE = await STEP_KEY.value,
22 !ITERATOR_COMPLETION
23 );
24 ITERATOR_COMPLETION = true) {
25 }
26 } catch (err) {
27 ITERATOR_HAD_ERROR_KEY = true;
28 ITERATOR_ERROR_KEY = err;
29 } finally {
30 try {
31 if (!ITERATOR_COMPLETION && ITERATOR_KEY.return != null) {
32 await ITERATOR_KEY.return();
33 }
34 } finally {
35 if (ITERATOR_HAD_ERROR_KEY) {
36 throw ITERATOR_ERROR_KEY;
37 }
38 }
39 }
40 }
41`);
42
43function _default(path, {
44 getAsyncIterator
45}) {
46 const {
47 node,
48 scope,
49 parent
50 } = path;
51 const stepKey = scope.generateUidIdentifier("step");
52 const stepValue = scope.generateUidIdentifier("value");
53 const left = node.left;
54 let declar;
55
56 if (_core.types.isIdentifier(left) || _core.types.isPattern(left) || _core.types.isMemberExpression(left)) {
57 declar = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, stepValue));
58 } else if (_core.types.isVariableDeclaration(left)) {
59 declar = _core.types.variableDeclaration(left.kind, [_core.types.variableDeclarator(left.declarations[0].id, stepValue)]);
60 }
61
62 let template = buildForAwait({
63 ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
64 ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
65 ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
66 ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
67 GET_ITERATOR: getAsyncIterator,
68 OBJECT: node.right,
69 STEP_VALUE: _core.types.cloneNode(stepValue),
70 STEP_KEY: stepKey
71 });
72 template = template.body.body;
73
74 const isLabeledParent = _core.types.isLabeledStatement(parent);
75
76 const tryBody = template[3].block.body;
77 const loop = tryBody[0];
78
79 if (isLabeledParent) {
80 tryBody[0] = _core.types.labeledStatement(parent.label, loop);
81 }
82
83 return {
84 replaceParent: isLabeledParent,
85 node: template,
86 declar,
87 loop
88 };
89}
Note: See TracBrowser for help on using the repository browser.