-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Possible parsing error with destructuring assignment #23142
Comments
This is a language-level issue and not node-specific. The problem is that without braces, there is some ambiguity, since if you add them it is parsed just fine. The parser doesn't know whether the FWIW this is why I personally always use braces (and semicolons to avoid that class of issues) to avoid such tricky behavior with the language. |
Minimal repro: @ArnauldChevallier |
It does appear that Firefox does not have this issue. /cc @nodejs/v8 ? |
@mscdex The intended behavior is that Now, this does indeed look like a V8 issue rather than a Node.js one. |
Filed https://bugs.chromium.org/p/v8/issues/detail?id=8241 to track this |
Seems to be fixed in v8/v8@cd21f71 |
Should we float v8/v8@cd21f71? @nodejs/v8-update |
Original commit message: [parser] Validate destructuring assignment pattern in correct classifier Previously we'd first accumulate errors to the parent and validate the destructuring pattern in the parent. In the case of ParseArguments this will invalidly propagate binding pattern errors from one argument to the next. The reason why ParseArguments keeps track of binding pattern errors is because it could also be used to parse async arrow function parameters. If we see async(a,b) we don't yet know whether this is the head of an async arrow function, or a call to async with arguments a and b. Bug: v8:8241 Change-Id: I670ab9a9c6f2e0bee399808b02a465ae1afa7c3f Reviewed-on: https://chromium-review.googlesource.com/c/1296229 Commit-Queue: Toon Verwaest <[email protected]> Reviewed-by: Marja Hölttä <[email protected]> Cr-Commit-Position: refs/heads/master@{#56887} Refs: v8/v8@cd21f71 Fixes: nodejs#23142
Original commit message: [parser] Validate destructuring assignment pattern in correct classifier Previously we'd first accumulate errors to the parent and validate the destructuring pattern in the parent. In the case of ParseArguments this will invalidly propagate binding pattern errors from one argument to the next. The reason why ParseArguments keeps track of binding pattern errors is because it could also be used to parse async arrow function parameters. If we see async(a,b) we don't yet know whether this is the head of an async arrow function, or a call to async with arguments a and b. Bug: v8:8241 Change-Id: I670ab9a9c6f2e0bee399808b02a465ae1afa7c3f Reviewed-on: https://chromium-review.googlesource.com/c/1296229 Commit-Queue: Toon Verwaest <[email protected]> Reviewed-by: Marja Hölttä <[email protected]> Cr-Commit-Position: refs/heads/master@{#56887} Refs: v8/v8@cd21f71 Fixes: #23142 PR-URL: #33862 Reviewed-By: Richard Lau <[email protected]>
Fixed in v10.22.0 by #33862. |
Summary
Passing an arrow function and a destructuring assignment as two consecutive parameters of a function causes a syntax error.
Description
The following piece of code does not make much sense (and putting the initialization of
[x, y]
in the 2nd parameter ofmap()
is definitely not a good idea), but I'd expect it to work anyway:In fact, this does work on both SpiderMonkey and Chakra which are returning
[[5, 5]]
.In Node (and Chrome), however, we get the following error:
Worst yet, with the following code:
We now get the following error:
This message is inconsistent, and that's why I suspect some kind of parsing error here.
Some more examples
This works:
This also works:
But this fails with "SyntaxError: Unexpected token =>":
The text was updated successfully, but these errors were encountered: