Hello. I am not 100% certain that this is an appropriate place to bring this 
up, and I'm likewise not 100% certain that this is the kind of feedback that is 
even warranted, nor am I 100% certain that this hasn't already been discussed. 
However, I am at least fairly confident about all of these things (sadly, the 
least confidence is in the latter, as I found this difficult to search for due 
to terms like "in" and "of" ;P).

(For context: I have a JavaScript compiler and REPL that I use to desugar some 
syntax extensions down to ECMAScript3 syntax to be run on JavaScriptCore. It is 
not currently used much in the world of web development, but is used by many 
developers doing jailbroken iPhone development. I tend to like experimenting 
with the latest features of various specifications, and this week have been 
adding ECMA6 features.)

http://gitweb.saurik.com/cycript.git

First, in the ECMA6 draft (I'm looking at the one from May 4th, for reference), 
an ArrayComprehension can be used in the same place that an ArrayLiteral can be 
used; however, ArrayComprehensions start with an arbitrary Expression while 
ArrayLiteral is defined to be its own (as in, not sharing productions with 
Expression) list of AssignmentExpressions.

This means that a lot of lookahead is required of the form that ECMAScript's 
grammar seems to purposely avoid (based on previous conversations I've seen on 
this mailing list; I might, however, be mistaken on this point). Even if this 
is not the case, though, I will also argue that the resulting syntax is fairly 
confusing to look at ;P.

[a, b, c, d for x of q]

Is the intention that the above syntax is to be allowed? I would presume that 
if it were, the result would be roughly equivalent (modulo side-effects of a, 
b, and c) to just using "d" for that expression, but I can also see people 
finding that confusing (and instead expecting to get an array that starts with 
a, b, and c, or an array with four times as many elements as q).

(Of course, it could also be said that this feedback is quite "too early" and 
this is already known and obvious, given that the semantics for array 
comprehensions hasn't even been added to the specification yet. ;P I'm sorry if 
this is a bother, then.)

The same syntax choice has been used for the list to iterate over. In this 
position it does not cause any grammar issues, but it still causes some syntax 
that I have a difficult time imagining that people will make the right 
assumptions about.

[a, b, c, d for x of 1, 2, 3, 4]

Finally, I have a user who is currently using JS1.7 array comprehension syntax 
(which I also currently support), but his use case isn't actually solved by the 
current syntax for ECMA6 array comprehensions as he's using for-in iteration, 
not for-of iteration (filtering the keys of an object for purposes of a 
reflection browser).

I realize that he could have a helper function that took an object and returned 
an array of its keys, but is there a reason to not make the syntax for array 
comprehensions match the possibilities of normal iteration? I can see many 
people being surprised that for-in does not work in this context (and it does 
not seem to cause any in-related grammar issues).

Sincerely,
Jay Freeman (saurik)
[email protected]
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to