Why does for ([] in object); work fine but [void 0 for ([] in object)] or (void 0 for ([] in object)) throw a syntax error for invalid left-hand assignment?
For example, I would expect the following code to work, but it doesn’t (the assertion isn’t even done due to the syntax error):
let (
i = 0,
iterable = {__iterator__:function() { var i = 5; while (i--) yield i; } }
) {
for ([] in iterable) i++;
console.assertEquals([void 0 for ([] in iterable)].length, i);
}
I did a little digging in
jsparse.cof SpiderMonkey (which I assume is the JS parser you’re using for 1.8 features?)The
[code for (... in ...)]format or generator expression uses a different parse function than the standardfor ([] in obj)uses.Your LHS error is being created here:
(jsparse.c line 4200)
When it sees the
[it finds the Destructuring Expression, and ensures the count of the parser node is at 2.Interestingly enough
[void 0 for ([a,b] in iterator)]should work, although for reasons I don’t care to go digging for, thebfrom[a,b]is always undefined:For reference – The standard
for([] in {})uses the following logic to determine the LHS validity:Which seems to mean that versions other than 1.7 don’t require 2 left hand values for this syntax. The generator expression might be using older parsing logic. This might be worth submitting as a report to the SpiderMonkey maintainers.