Skip to content

Commit

Permalink
merge packages/babel-plugin-proposal-async-generator-functions/src/in…
Browse files Browse the repository at this point in the history
…dex.ts
  • Loading branch information
Yokubjon-J committed Jun 22, 2022
2 parents a47fd8e + 0ac2611 commit 1c1202e
Showing 1 changed file with 63 additions and 0 deletions.
Expand Up @@ -2,28 +2,36 @@ import { declare } from "@babel/helper-plugin-utils";
import remapAsyncToGenerator from "@babel/helper-remap-async-to-generator";
import syntaxAsyncGenerators from "@babel/plugin-syntax-async-generators";
<<<<<<< HEAD
<<<<<<< HEAD
import { types as t } from "@babel/core";
import type { PluginPass } from "@babel/core";
import type { Visitor } from "@babel/traverse";
=======
import { traverse, types as t } from "@babel/core";
>>>>>>> 6548c38378 (environmentVisitor merged but issue still persists)
=======
import { traverse, types as t } from "@babel/core";
>>>>>>> 0ac261115a1fa1edea3e2adb7b21d401f8b5fdf6
import rewriteForAwait from "./for-await";
import environmentVisitor from "@babel/helper-environment-visitor";

export default declare(api => {
api.assertVersion(7);

<<<<<<< HEAD
<<<<<<< HEAD
const yieldStarVisitor: Visitor<PluginPass> = {
Function(path) {
path.skip();
=======
=======
>>>>>>> 0ac261115a1fa1edea3e2adb7b21d401f8b5fdf6
const yieldStarVisitor = traverse.visitors.merge([
{
Function(path) {
path.skip();
},
<<<<<<< HEAD

YieldExpression({ node }, state) {
if (!node.delegate) return;
Expand Down Expand Up @@ -120,6 +128,61 @@ export default declare(api => {
environmentVisitor,
]);
>>>>>>> 6548c38378 (environmentVisitor merged but issue still persists)
=======

YieldExpression({ node }, state) {
if (!node.delegate) return;
const callee = state.addHelper("asyncGeneratorDelegate");
node.argument = t.callExpression(callee, [
t.callExpression(state.addHelper("asyncIterator"), [node.argument]),
state.addHelper("awaitAsyncGenerator"),
]);
},
},
environmentVisitor,
]);

const forAwaitVisitor = traverse.visitors.merge([
{
Function(path) {
path.skip();
},

ForOfStatement(path, { file }) {
const { node } = path;
if (!node.await) return;

const build = rewriteForAwait(path, {
getAsyncIterator: file.addHelper("asyncIterator"),
});

const { declar, loop } = build;
const block = loop.body;

// ensure that it's a block so we can take all its statements
path.ensureBlock();

// add the value declaration to the new loop body
if (declar) {
block.body.push(declar);
}

// push the rest of the original loop body onto our new body
block.body.push(...node.body.body);

t.inherits(loop, node);
t.inherits(loop.body, node.body);

if (build.replaceParent) {
path.parentPath.replaceWithMultiple(build.node);
} else {
path.replaceWithMultiple(build.node);
}
},
},
environmentVisitor,
]);
>>>>>>> 0ac261115a1fa1edea3e2adb7b21d401f8b5fdf6

const visitor: Visitor<PluginPass> = {
Function(path, state) {
Expand Down

0 comments on commit 1c1202e

Please sign in to comment.