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

Parse error when using in nested in a for initializer #59236

Open
nicolo-ribaudo opened this issue Jul 11, 2024 · 7 comments
Open

Parse error when using in nested in a for initializer #59236

nicolo-ribaudo opened this issue Jul 11, 2024 · 7 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@nicolo-ribaudo
Copy link

πŸ”Ž Search Terms

in for in init syntax error

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.5.3#code/GYewTgBAFAbghpOEC8EDaAjCBLAdhAYwF0BuEgShKA

πŸ’» Code

for (var a = [b in c];;);

πŸ™ Actual behavior

It says "',' expected." at the in

πŸ™‚ Expected behavior

It should parse it properly

Additional information about the issue

No response

@nicolo-ribaudo
Copy link
Author

Also

for (var a = (x = b in c) => {};;);

@Andarist
Copy link
Contributor

alone at a party meme: they don't know about for initializer bugs in all popular parsers

I love this content, keep it coming :P ❀️

@MartinJohns
Copy link
Contributor

Sounds like a duplicate of #9978. Or is there a reason to write code like that?

@nicolo-ribaudo
Copy link
Author

This is about a for loop, not a for-in loop.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jul 11, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jul 11, 2024
@jesus-diaz-rivero
Copy link

What would be the correct js output here? Writing this as pure javascript returns the same error

@Andarist
Copy link
Contributor

The correct JS output here is the same as the input. This code throws ReferenceError at runtime but it isn't a parse error.

@nicolo-ribaudo
Copy link
Author

@jesus-diaz-rivero If you want some code that does not throw at runtime:

var b = "";
var c = {};
for (var a = [b in c]; false;);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

5 participants