Skip to content

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

Closed

Description

πŸ”Ž 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

Activity

  1. fisker commented on Aug 29, 2023

    @fisker
  2. sosukesuzuki commented on Aug 29, 2023

    @sosukesuzuki
    Author
  3. MartinJohns commented on Aug 29, 2023

    @MartinJohns
    Contributor

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

  4. sosukesuzuki commented on Aug 29, 2023

    @sosukesuzuki
    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.

  5. DanielRosenwasser commented on Aug 29, 2023

    @DanielRosenwasser
    Member

    (congrats on issue #55555!)

  6. rbuckton commented on Oct 30, 2023

    @rbuckton
    Contributor

    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

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions