Skip to content

[Bug]: babel-traverse path.isForAwaitStatement is broken #14929

@ROpdebee

Description

@ROpdebee

💻

  • Would you like to work on a fix?

How are you using Babel?

Programmatic API (babel.transform, babel.parse)

Input code

async function x() {
    for await (const i of [1, 2, 3]) {
        console.log(i);
    }
}

x();

Configuration file name

No response

Configuration

No response

Current and expected behavior

isForAwaitStatement on the node for the for await statement should return true. It returns false instead, since @babel/traverse@7.19.0.

Environment

System:
OS: macOS 11.5.2
Binaries:
Node: 18.8.0 - /usr/local/bin/node
npm: 8.18.0 - /usr/local/bin/npm
npmPackages:
@babel/core: 7.19.0 => 7.19.0
@babel/plugin-syntax-jsx: 7.18.6 => 7.18.6
@babel/plugin-transform-runtime: 7.18.10 => 7.18.10
@babel/preset-env: 7.19.0 => 7.19.0
@babel/preset-typescript: 7.18.6 => 7.18.6
babel-plugin-transform-async-to-promises: 0.8.16 => 0.8.16
eslint: 8.23.1 => 8.23.1
jest: 28.1.3 => 28.1.3

Possible solution

It seems that it got broken in the refactoring of #14799. I think

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

Additional context

No response

Metadata

Metadata

Assignees

Labels

i: regressionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: traverse

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions