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.
1 line
7.0 KiB
1 line
7.0 KiB
{"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 before the\n // async-to-generator plugin. This is because for-await is transpiled\n // using \"await\" expressions, which are then converted to \"yield\".\n //\n // This is bad for performance, but plugin ordering will allow as to\n // directly visit Function in the top level visitor.\n path.traverse(visitor, state);\n },\n },\n };\n});\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,4BAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAA6C,IAAAK,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE9B,I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