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

Parsing error for for (await using of of of) {} #55555

Closed
sosukesuzuki opened this issue Aug 29, 2023 · 6 comments Β· Fixed by #55558
Closed

Parsing error for for (await using of of of) {} #55555

sosukesuzuki opened this issue Aug 29, 2023 · 6 comments Β· Fixed by #55558
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@sosukesuzuki
Copy link

sosukesuzuki commented Aug 29, 2023

πŸ”Ž Search Terms

"using of"

πŸ•— Version & Regression Information

  • This changed between versions 5.1 and 5.2_

⏯ Playground Link

https://www.typescriptlang.org/play?#code/N4KABGBmD2BOYAoCGB3JBLALmArgZ3QDsBzMaSMi8gSgG5wo4xUNtk0tcCTLeb6AviCA

πŸ’» Code

{
  for (await using of of of);
}

πŸ™ Actual behavior

Parsing error The left-hand side of a 'for...of' statement must be a variable or a property access.

πŸ™‚ Expected behavior

Parse successful.

Additional information about the issue

Context: https://github.com/prettier/prettier/pull/15321/files#r1308180336
Spec: https://tc39.es/proposal-explicit-resource-management/#sec-for-in-and-for-of-statements

Babel can parse for (await using of of of) {}. ref: https://github.com/babel/babel/blob/b804bb08912d262133213dcd7f40d81645f97489/packages/babel-parser/test/fixtures/experimental/async-explicit-resource-management/valid-for-using-binding-of-of/input.js

@fisker

This comment was marked as outdated.

@sosukesuzuki

This comment was marked as resolved.

@MartinJohns
Copy link
Contributor

Does this ever happen with real code, or is it just an attempt to intentionally break the parser?

@sosukesuzuki
Copy link
Author

I didn't see this with real code but I didn't intentionally break the parser, I just noticed it while developing the code formatter.

@andrewbranch andrewbranch added the Needs Investigation This issue needs a team member to investigate its status. label Aug 29, 2023
@andrewbranch andrewbranch added this to the TypeScript 5.3.0 milestone Aug 29, 2023
@DanielRosenwasser
Copy link
Member

(congrats on issue #55555!)

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Aug 29, 2023
@rbuckton
Copy link
Member

Does this ever happen with real code, or is it just an attempt to intentionally break the parser?

It's a spec conformance issue. The spec specifically forbids for (using of of since that can be ambiguous (using could be an identifier like x in for (x of of, or of could be either an identifier or a keyword), while for (await using of of is unambiguous (await using can only imply the declaration, thus await using of must declare an identifier).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants