`do` expression conflicting with `do ... while` grammar?
I'm interested in where the (stage 1?) proposal is as well.
current impl in v8 is to only parse do-expressions in expression contexts (as a PrimaryExpr, iirc). So it never gets mixed up with do-while loops, which is fine (imo).
I recall seeing discussion about this in tc39 notes at some point, afaik the conclusion was that do-expressions dont work in Statement contexts, because theres no use case
Does that mean the following would parse as a do expression?
function foo () {
return
do {
1;
}
while (true);
}
id have to check the ASI rules, but I expect that would parse as a do-while loop and result in a SyntaxError. Interesting test case, though. should add to v8's test suite.
Le 22 févr. 2016 à 17:47, Bradley Meck <bradley.meck at gmail.com> a écrit :
Does that mean the following would parse as a do expression?
function foo () { return do { 1; } while (true); }
No, because return
cannot be followed be a LineTerminator, so that ASI will introduce a semicolon after it.
This is the same issue as:
function foo() {
return // an implied semicolon is inserted here
{ bar: 1 }; // interpreted as a block, not as an object literal
}
oh, somehow I totally missed the 'while (true)' at the end of that snippet -- so I retract the SyntaxError thing. but yeah, would be a do-while loop
how will people distinguish
do ... while
fromdo
expressions? I tried to find the exact grammar but couldn't after a bit of searching.For example in current JS,
would cause infinite number of
console.log
s. But if thedo
is seen as an expression statement it would only log once.Any pointer to where the grammar is discussed would be quite helpful.