Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: isForAwaitStatement is broken #14932

Merged
merged 1 commit into from Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
},
);
});