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

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

Closed
RangerMauve opened this issue Oct 23, 2018 · 6 comments
Closed

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

RangerMauve opened this issue Oct 23, 2018 · 6 comments
Assignees
Labels
promises Issues and PRs related to ECMAScript promises. repl Issues and PRs related to the REPL subsystem.

Comments

@RangerMauve
Copy link

RangerMauve commented Oct 23, 2018

  • 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
@vsemozhetbyt vsemozhetbyt added repl Issues and PRs related to the REPL subsystem. promises Issues and PRs related to ECMAScript promises. labels Oct 23, 2018
@vsemozhetbyt
Copy link
Contributor

сс @nodejs/repl

@antsmartian
Copy link
Contributor

antsmartian commented Oct 24, 2018

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.

@devsnek
Copy link
Member

devsnek commented Oct 24, 2018

its would seem to be a bug in https:/nodejs/node/blob/master/lib/internal/repl/await.js

@devsnek
Copy link
Member

devsnek commented Oct 24, 2018

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

@codebytere
Copy link
Member

@devsnek happy to handle this!

@RangerMauve
Copy link
Author

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

@targos targos closed this as completed in 35f9cd2 Oct 28, 2018
targos pushed a commit that referenced this issue Oct 28, 2018
PR-URL: #23841
Fixes: #23836
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: James M Snell <[email protected]>
targos pushed a commit that referenced this issue Nov 1, 2018
PR-URL: #23841
Fixes: #23836
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Mar 20, 2019
PR-URL: #23841
Fixes: #23836
Reviewed-By: John-David Dalton <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
promises Issues and PRs related to ECMAScript promises. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants