You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
parttimejob/node_modules/@babel/plugin-transform-async-gene.../lib/index.js.map

1 line
7.0 KiB

4 weeks ago
{"version":3,"names":["_helperPluginUtils","require","_helperRemapAsyncToGenerator","_core","_traverse","_forAwait","_default","exports","default","declare","api","assertVersion","yieldStarVisitor","visitors","environmentVisitor","ArrowFunctionExpression","path","skip","YieldExpression","node","state","delegate","asyncIter","t","callExpression","addHelper","argument","forAwaitVisitor","ForOfStatement","file","await","build","rewriteForAwait","getAsyncIterator","declar","loop","block","body","ensureBlock","push","length","blockStatement","inherits","p","replaceParent","parentPath","replaceWithMultiple","scope","parent","crawl","visitor","Function","async","traverse","generator","setData","remapAsyncToGenerator","wrapAsync","wrapAwait","name","manipulateOptions","_","parser","plugins","Program"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport remapAsyncToGenerator from \"@babel/helper-remap-async-to-generator\";\nimport type { NodePath, Visitor, PluginPass } from \"@babel/core\";\nimport { types as t } from \"@babel/core\";\nimport { visitors } from \"@babel/traverse\";\nimport rewriteForAwait from \"./for-await.ts\";\n\nexport default declare(api => {\n api.assertVersion(REQUIRED_VERSION(7));\n\n const yieldStarVisitor = visitors.environmentVisitor<PluginPass>({\n ArrowFunctionExpression(path) {\n path.skip();\n },\n\n YieldExpression({ node }, state) {\n if (!node.delegate) return;\n const asyncIter = t.callExpression(state.addHelper(\"asyncIterator\"), [\n node.argument,\n ]);\n node.argument = t.callExpression(\n state.addHelper(\"asyncGeneratorDelegate\"),\n process.env.BABEL_8_BREAKING\n ? [asyncIter]\n : [asyncIter, state.addHelper(\"awaitAsyncGenerator\")],\n );\n },\n });\n\n const forAwaitVisitor = visitors.environmentVisitor<PluginPass>({\n ArrowFunctionExpression(path) {\n path.skip();\n },\n\n ForOfStatement(path: NodePath<t.ForOfStatement>, { file }) {\n const { node } = path;\n if (!node.await) return;\n\n const build = rewriteForAwait(path, {\n getAsyncIterator: file.addHelper(\"asyncIterator\"),\n });\n\n const { declar, loop } = build;\n const block = loop.body as t.BlockStatement;\n\n // ensure that it's a block so we can take all its statements\n path.ensureBlock();\n\n // add the value declaration to the new loop body\n if (declar) {\n block.body.push(declar);\n if (path.node.body.body.length) {\n block.body.push(t.blockStatement(path.node.body.body));\n }\n } else {\n block.body.push(...path.node.body.body);\n }\n\n t.inherits(loop, node);\n t.inherits(loop.body, node.body);\n\n const p = build.replaceParent ? path.parentPath : path;\n p.replaceWithMultiple(build.node);\n\n // TODO: Avoid crawl\n p.scope.parent.crawl();\n },\n });\n\n const visitor: Visitor<PluginPass> = {\n Function(path, state) {\n if (!path.node.async) return;\n\n path.traverse(forAwaitVisitor, state);\n\n if (!path.node.generator) return;\n\n path.traverse(yieldStarVisitor, state);\n\n path.setData(\n \"@babel/plugin-transform-async-generator-functions/async_generator_function\",\n true,\n );\n\n // We don't need to pass the noNewArrows assumption, since\n // async generators are never arrow functions.\n remapAsyncToGenerator(path, {\n wrapAsync: state.addHelper(\"wrapAsyncGenerator\"),\n wrapAwait: state.addHelper(\"awaitAsyncGenerator\"),\n });\n },\n };\n\n return {\n name: \"transform-async-generator-functions\",\n\n manipulateOptions: process.env.BABEL_8_BREAKING\n ? undefined\n : (_, parser) => parser.plugins.push(\"asyncGenerators\"),\n\n visitor: {\n Program(path, state) {\n // We need to traverse the ast here (instead of just vising Function\n // in the top level visitor) because for-await needs to run