-
Notifications
You must be signed in to change notification settings - Fork 33
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
Is for (using of = obj;;);
valid syntax?
#248
Comments
It's valid in |
Just to make sure, here's my understanding and my intent. Those PRs looks related only to the C-style Is it correct that If that's the case, I think there should be some explicit note about that, given that all implementation misinterpreted it. |
@arai-a Oh, sorry, I misunderstood. Here's per the spec as it is:
Feels like a spec bug, to be honest. The spec should either reject both or allow both. IMHO it makes more sense to allow both. Allowing it is as simple as adding explicit productions for
|
Allowing If
In this case, tokenization (DIV vs RegExp) after the 2nd For example, if we have
Thus, if we're to match the behaviors of C-style |
Possible modification would be to first add the
and then split the
and then modify the other occurrences of Or maybe add another symbol that replaces |
Oh, whoops, that was the one case I missed. 🤦♀️ I knew it'd be possible with some grammar hackery, just was wrong about the specifics. I still stand by my opinion on either allowing both or prohibiting both, but to be clear, that's not what the current spec says. |
Also, misread the spec (again): |
(discovered in https://bugzilla.mozilla.org/show_bug.cgi?id=1934205 )
In the proposal,
ForInOfStatement
definition is modified and theusing
handling is added intoForDeclaration
with[Using]
parameter, where the parameter is set only after a negative lookahead forfor of
using of
:https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-for-in-and-for-of-statements&secAll=true
So,
for (using of
cannot become a prefix of the for-in/for-of with using declaration, but it can be a prefix of for-of with theusing
being an identifier inLeftHandSideExpression
.On the other hand, the proposal doesn't touch the
ForStatement
definition, and theusing
handling is added intoLexicalDeclaration
unconditionally.https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-for-statement&secAll=true
https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-let-const-using-and-await-using-declarations&secAll=true
https://arai-a.github.io/ecma262-compare/?pr=3000&id=sec-let-const-using-and-await-using-declarations
This means
ForStatement
matchesfor (using of = obj;;);
.Is this expected?
TypeScript doesn't recognize the syntax, and
Babel, esbuild, Chromium, and SpiderMonkey throw syntax error.
Apparently the negative lookahead is applied also to ForStatement in all of them.
If
for (using of = obj;;);
should throw SyntaxError, theForStatement
syntax should be modified to have a negative lookahead, with propagating the existence ofusing
toLexicalDeclaration
, or maybe replacing that part with something similar toForDeclaration
.The text was updated successfully, but these errors were encountered: