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

Allow of in await using declarations in for-of loops #55558

Merged

Conversation

Andarist
Copy link
Contributor

fixes #55555

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Aug 29, 2023
@Andarist Andarist force-pushed the fix/allow-of-in-await-using-in-for-of branch from 7a75c09 to 7f15218 Compare August 29, 2023 08:23
@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 29, 2023
@sandersn sandersn added this to Not started in PR Backlog Sep 6, 2023
@sandersn sandersn moved this from Not started to Waiting on reviewers in PR Backlog Sep 7, 2023
Comment on lines 9 to 11
for await (await using of of of) {};
~~~~~
!!! error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this in an async context, like an async function so that we don't have this spurious error in errors.txt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just pushed out the requested change. Could you take another look at this?

PR Backlog automation moved this from Waiting on reviewers to Waiting on author Oct 30, 2023
PR Backlog automation moved this from Waiting on author to Needs merge Oct 31, 2023
@rbuckton rbuckton merged commit 3e12250 into microsoft:main Oct 31, 2023
19 checks passed
PR Backlog automation moved this from Needs merge to Done Oct 31, 2023
@jakebailey
Copy link
Member

Note that 5.3 is cut; not sure if you intended for this to be in 5.3 or not.

@rbuckton
Copy link
Member

rbuckton commented Nov 2, 2023

I did. This was a bugfix for a grammar error.

@rbuckton rbuckton changed the title Allow of in await using declarations in for-of loops Allow of in await using declarations in for-of loops Nov 2, 2023
@jakebailey
Copy link
Member

It was synced in after I commented, so nevermind!

@evanw
Copy link
Contributor

evanw commented Nov 18, 2023

With this change, for (await using of x) ; is an error but for await (await using of x) ; is now not an error (a change in behavior from TS 5.2). In addition, the emit for for await (await using of x) ; has an extra space in it which implies to me that TypeScript's internal AST contains an empty variable declaration list, which would be invalid. Babel treats both as a syntax error (see this and this), which also leads me to believe that this is a bug in TypeScript.

Was that an intentional aspect of this change or was that a regression?

@Andarist
Copy link
Contributor Author

@evanw thanks for this information - I'll take a look at this soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

Parsing error for for (await using of of of) {}
6 participants