-
Notifications
You must be signed in to change notification settings - Fork 903
Handle incorrect destructuring in for loops at parse time #2190
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
Conversation
Code like this:
```js
for (var {};;) {}
```
was parsed correctly, but then failed during the code generation
with various exceptions because the destructuring expression after
`var` doesn't have a right-hand side.
This change implements a check at parse time, to throw a `SyntaxError`,
coherently with what `node` or `spidermonkey` or `quickjs` do.
I'm a bit surprised that this doesn't seem to show any improvement in
test262 coverage. Perhaps a test there might be warranted?
Fixes mozilla#1922
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks goodActually, seems to be causing some failures, and does make me wonder, are there other places that might need similar checks?
|
Ah, scratch that, it's a problem with a |
From what I can tell, this problem should only happen in |
|
Okay looking at the spec and MDN I agree that the only places that allow destructuring binding are loops, functions, and catch blocks. |
| public void errorOnInvalidDestructuringDeclaration() { | ||
| expectParseErrors( | ||
| "for(var {};;) {}", | ||
| new String[] {"Missing = in destructuring declaration", "syntax error"}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a reader of error messages i like this form more - not sure why the french version has the ' and the english not.
Missing '=' in destructuring declaration
|
Great, thanks! |
Code like this:
was parsed correctly, but then failed during the code generation with various exceptions because the destructuring expression after
vardoesn't have a right-hand side.This change implements a check at parse time, to throw a
SyntaxError, coherently with whatnodeorspidermonkeyorquickjsdo.I'm a bit surprised that this doesn't seem to show any improvement in test262 coverage. Perhaps a test there might be warranted?
Fixes #1922