diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:31:11 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 15:31:11 +0800 |
| commit | aa773172311dcada759dfbaac485f4bc6e00bc21 (patch) | |
| tree | ca6d9a5eff3ab8f689f9acb4f0df791d9486813d /node_modules/@babel/plugin-transform-async-generator-functions/lib/index.js | |
| parent | c5a5384e846f242e901e859fe600d695d8990a9a (diff) | |
added babel
Diffstat (limited to 'node_modules/@babel/plugin-transform-async-generator-functions/lib/index.js')
| -rw-r--r-- | node_modules/@babel/plugin-transform-async-generator-functions/lib/index.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/node_modules/@babel/plugin-transform-async-generator-functions/lib/index.js b/node_modules/@babel/plugin-transform-async-generator-functions/lib/index.js new file mode 100644 index 00000000..0d3d6b9b --- /dev/null +++ b/node_modules/@babel/plugin-transform-async-generator-functions/lib/index.js @@ -0,0 +1,85 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +var _helperPluginUtils = require("@babel/helper-plugin-utils"); +var _helperRemapAsyncToGenerator = require("@babel/helper-remap-async-to-generator"); +var _core = require("@babel/core"); +var _forAwait = require("./for-await.js"); +var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor"); +var _default = (0, _helperPluginUtils.declare)(api => { + api.assertVersion(7); + const yieldStarVisitor = _core.traverse.visitors.merge([{ + ArrowFunctionExpression(path) { + path.skip(); + }, + YieldExpression({ + node + }, state) { + if (!node.delegate) return; + const asyncIter = _core.types.callExpression(state.addHelper("asyncIterator"), [node.argument]); + node.argument = _core.types.callExpression(state.addHelper("asyncGeneratorDelegate"), [asyncIter, state.addHelper("awaitAsyncGenerator")]); + } + }, _helperEnvironmentVisitor.default]); + const forAwaitVisitor = _core.traverse.visitors.merge([{ + ArrowFunctionExpression(path) { + path.skip(); + }, + ForOfStatement(path, { + file + }) { + const { + node + } = path; + if (!node.await) return; + const build = (0, _forAwait.default)(path, { + getAsyncIterator: file.addHelper("asyncIterator") + }); + const { + declar, + loop + } = build; + const block = loop.body; + path.ensureBlock(); + if (declar) { + block.body.push(declar); + if (path.node.body.body.length) { + block.body.push(_core.types.blockStatement(path.node.body.body)); + } + } else { + block.body.push(...path.node.body.body); + } + _core.types.inherits(loop, node); + _core.types.inherits(loop.body, node.body); + const p = build.replaceParent ? path.parentPath : path; + p.replaceWithMultiple(build.node); + p.scope.parent.crawl(); + } + }, _helperEnvironmentVisitor.default]); + const visitor = { + Function(path, state) { + if (!path.node.async) return; + path.traverse(forAwaitVisitor, state); + if (!path.node.generator) return; + path.traverse(yieldStarVisitor, state); + (0, _helperRemapAsyncToGenerator.default)(path, { + wrapAsync: state.addHelper("wrapAsyncGenerator"), + wrapAwait: state.addHelper("awaitAsyncGenerator") + }); + } + }; + return { + name: "transform-async-generator-functions", + inherits: require("@babel/plugin-syntax-async-generators").default, + visitor: { + Program(path, state) { + path.traverse(visitor, state); + } + } + }; +}); +exports.default = _default; + +//# sourceMappingURL=index.js.map |
