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

Disallow 'for (using of of ...)' #108

Merged
merged 1 commit into from Nov 14, 2022
Merged

Disallow 'for (using of of ...)' #108

merged 1 commit into from Nov 14, 2022

Conversation

rbuckton
Copy link
Collaborator

@rbuckton rbuckton commented Oct 4, 2022

This was first noticed in the Babel PR for using: babel/babel#14968 (review). Rather than introduce additional complexity with a cover grammar, this instead prevents of from being considered as a BindingIdentifier in a for (using ...).

The intent is that the source:

for (using of of [x]) 

will be parsed as:

for ( using of of [x] )
      ^^^^^ ^^ ^^ ^^^
      |     |  |
      |     |  AssignmentExpression->MemberExpression (`of[x]`)
      |     |
      |     `of` keyword
      |
      LeftHandSideExpression->Identifier `using`

This is to preserve backwards compatibility with existing JS.

Fixes #107

@github-actions
Copy link

github-actions bot commented Oct 4, 2022

A preview of this PR can be found at https://tc39.es/proposal-explicit-resource-management/pr/108.

@bakkot
Copy link

bakkot commented Oct 5, 2022

As currently written I believe this also makes for (using of foo) illegal (because using of is the lookahead after the (), so that production can't be used.

I think you can instead put lookahead ≠ of inside of the new RHS of ForDeclaration, as in ForDeclaration : using [no LineTerminator here] [lookahead != of] ForBinding. That should just rule out the using of of case.

@rbuckton
Copy link
Collaborator Author

rbuckton commented Oct 5, 2022

As currently written I believe this also makes for (using of foo) illegal (because using of is the lookahead after the (), so that production can't be used.

I think you can instead put lookahead ≠ of inside of the new RHS of ForDeclaration, as in ForDeclaration : using [no LineTerminator here] [lookahead != of] ForBinding. That should just rule out the using of of case.

It shouldn't, since for (using of foo) would be parsed under this RHS:

for ( [lookahead ∉ { let, async of }] LeftHandSideExpression[?Yield, ?Await] of AssignmentExpression[+In, ?Yield, ?Await] ) Statement[?Yield, ?Await, ?Return]

@bakkot
Copy link

bakkot commented Oct 5, 2022

Oh, quite right, I was looking at the wrong production.

@rbuckton
Copy link
Collaborator Author

@syg, @waldemarhorwat: Since this is a fairly small change, I'm planning to merge this later today. If you have any feedback after that, please feel free to file it here and I can put up a separate PR.

@rbuckton rbuckton merged commit a412e9c into main Nov 14, 2022
@rbuckton rbuckton deleted the disallow-for-using-of-of branch November 14, 2022 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

for-of using declaration can collide with for-lhs-of
2 participants