Skip to content

for await of syntax doesn't work with --experimental-repl-await #23836

Description

@RangerMauve
  • Version: v10.9.0
  • Platform: Windows 10 Pro 10.0.17134 x64
  • Subsystem: REPL

The REPL is working great with regular await, but doesn't seem to be able to handle the new for await of syntax that was introduced as part of the async-iteration spec.

for await of works when wrapping the call with an async function, it only fails if used at the top level.

This fails:

$ node --experimental-repl-await
> for await (let i of [1,2,3]) console.log(i)
for await (let i of [1,2,3]) console.log(i)
    ^^^^^

SyntaxError: Unexpected reserved word

This works:

> (async () => { for await(let i of [1,2,3]) console.log(i) })()
Promise {
  <pending>,
  domain: ...etc }
> 1
2
3

Activity

  1. added
    replIssues and PRs related to the REPL subsystem.
    promisesIssues and PRs related to ECMAScript promises.
    on Oct 23, 2018
  2. vsemozhetbyt commented on Oct 23, 2018

    @vsemozhetbyt
    Contributor

    сс @nodejs/repl

  3. antsmartian commented on Oct 24, 2018

    @antsmartian
    Contributor

    This is expected, await can be used only within async functions. Even from the link that you had shared, its says the following (below the code sample):

    Async for-of statements are only allowed within async functions and async generator functions (see below for the latter).

    That's the exact reason why it works perfectly fine, when you wrap with async.

    Edit: Looks like repl supports top level await.

  4. devsnek commented on Oct 24, 2018

    @devsnek
    Member
  5. devsnek commented on Oct 24, 2018

    @devsnek
    Member

    So the visitors don't check for a ForOfStatement with await: true, which means state.containsAwait ends up being false, and its not handled.

    fix looks like this nodejs/repl@2003bc5 if anyone wants to take it

  6. codebytere commented on Oct 24, 2018

    @codebytere
    Member

    @devsnek happy to handle this!

  7. self-assigned this
    on Oct 24, 2018
  8. RangerMauve commented on Oct 24, 2018

    @RangerMauve
    Author

    Oh snap! Thank you so much for addressing this so quickly! 🤩

  9. added a commit that references this issue on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

promisesIssues and PRs related to ECMAScript promises.replIssues and PRs related to the REPL subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions