Skip to content

Commit

Permalink
fix: isForAwaitStatement is broken (#14932)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 14, 2022
1 parent c9d0c40 commit d0a923f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -20,6 +20,7 @@ import {
isVar as nodeIsVar,
isVariableDeclaration,
react,
isForOfStatement,
} from "@babel/types";
import type * as t from "@babel/types";
const { isCompatTag } = react;
Expand Down Expand Up @@ -197,7 +198,7 @@ export function isSpreadProperty(this: NodePath): boolean {
}

export function isForAwaitStatement(this: NodePath): boolean {
return isForStatement(this.node, { await: true });
return isForOfStatement(this.node, { await: true });
}

export function isExistentialTypeParam(this: NodePath): void {
Expand Down
27 changes: 27 additions & 0 deletions packages/babel-traverse/test/path/virtual-validators.js
@@ -0,0 +1,27 @@
import { parse } from "@babel/parser";

import _traverse from "../../lib/index.js";
const traverse = _traverse.default || _traverse;

function getPath(code) {
const ast = parse(code, { sourceType: "module" });
let path;
traverse(ast, {
Program: function (_path) {
path = _path;
_path.stop();
},
});
return path;
}

describe("path.isForAwaitStatement", () => {
it.each(["for await (const x of []);"])(
`NodePath(%p).get("body.0").isForAwaitStatement() should be true`,
input => {
const path = getPath(input).get("body.0");
expect(path.node).toBeTruthy();
expect(path.isForAwaitStatement()).toBe(true);
},
);
});

0 comments on commit d0a923f

Please sign in to comment.