aboutsummaryrefslogtreecommitdiff
path: root/node_modules/@babel/plugin-proposal-async-generator-functions/lib/for-await.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/@babel/plugin-proposal-async-generator-functions/lib/for-await.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/@babel/plugin-proposal-async-generator-functions/lib/for-await.js')
-rw-r--r--node_modules/@babel/plugin-proposal-async-generator-functions/lib/for-await.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/node_modules/@babel/plugin-proposal-async-generator-functions/lib/for-await.js b/node_modules/@babel/plugin-proposal-async-generator-functions/lib/for-await.js
new file mode 100644
index 00000000..54571bc3
--- /dev/null
+++ b/node_modules/@babel/plugin-proposal-async-generator-functions/lib/for-await.js
@@ -0,0 +1,95 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = _default;
+
+function _core() {
+ const data = require("@babel/core");
+
+ _core = function _core() {
+ return data;
+ };
+
+ return data;
+}
+
+const buildForAwait = (0, _core().template)(`
+ async function wrapper() {
+ var ITERATOR_COMPLETION = true;
+ var ITERATOR_HAD_ERROR_KEY = false;
+ var ITERATOR_ERROR_KEY;
+ try {
+ for (
+ var ITERATOR_KEY = GET_ITERATOR(OBJECT), STEP_KEY, STEP_VALUE;
+ (
+ STEP_KEY = await ITERATOR_KEY.next(),
+ ITERATOR_COMPLETION = STEP_KEY.done,
+ STEP_VALUE = await STEP_KEY.value,
+ !ITERATOR_COMPLETION
+ );
+ ITERATOR_COMPLETION = true) {
+ }
+ } catch (err) {
+ ITERATOR_HAD_ERROR_KEY = true;
+ ITERATOR_ERROR_KEY = err;
+ } finally {
+ try {
+ if (!ITERATOR_COMPLETION && ITERATOR_KEY.return != null) {
+ await ITERATOR_KEY.return();
+ }
+ } finally {
+ if (ITERATOR_HAD_ERROR_KEY) {
+ throw ITERATOR_ERROR_KEY;
+ }
+ }
+ }
+ }
+`);
+
+function _default(path, {
+ getAsyncIterator
+}) {
+ const node = path.node,
+ scope = path.scope,
+ parent = path.parent;
+ const stepKey = scope.generateUidIdentifier("step");
+ const stepValue = scope.generateUidIdentifier("value");
+ const left = node.left;
+ let declar;
+
+ if (_core().types.isIdentifier(left) || _core().types.isPattern(left) || _core().types.isMemberExpression(left)) {
+ declar = _core().types.expressionStatement(_core().types.assignmentExpression("=", left, stepValue));
+ } else if (_core().types.isVariableDeclaration(left)) {
+ declar = _core().types.variableDeclaration(left.kind, [_core().types.variableDeclarator(left.declarations[0].id, stepValue)]);
+ }
+
+ let template = buildForAwait({
+ ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),
+ ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),
+ ITERATOR_ERROR_KEY: scope.generateUidIdentifier("iteratorError"),
+ ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
+ GET_ITERATOR: getAsyncIterator,
+ OBJECT: node.right,
+ STEP_VALUE: stepValue,
+ STEP_KEY: stepKey
+ });
+ template = template.body.body;
+
+ const isLabeledParent = _core().types.isLabeledStatement(parent);
+
+ const tryBody = template[3].block.body;
+ const loop = tryBody[0];
+
+ if (isLabeledParent) {
+ tryBody[0] = _core().types.labeledStatement(parent.label, loop);
+ }
+
+ return {
+ replaceParent: isLabeledParent,
+ node: template,
+ declar,
+ loop
+ };
+} \ No newline at end of file