Intentional breaking change in ES6 draft spec?
Luke Hoban wrote:
The ES6 draft grammar no longer allows the following, which was legal ES5:
for(var i = 1 in []) {}
Was that an intentional breaking change? If so, why?
Yes, to simplify and tighten up grammar (and engines). We reckoned that only testsuites counted on this. This was recorded in some meeting notes but I'm not free to dig them up right now.
(Of course, there are exceedingly limited practical uses of this, but that alone doesn't seem to justify a breaking change).
We had some web crawling help, IIRC. We also figured we had time to test and put it back, if needed. Did you find web content using it?
This was from back in the days when Google code search was still available and the only hits we found were from test suites.
From: Erik Arvidsson [mailto:erik.arvidsson at gmail.com] This was from back in the days when Google code search was still available and the only hits we found were from test suites.
On Jun 13, 2013 8:54 PM, "Brendan Eich" <brendan at mozilla.com> wrote: We had some web crawling help, IIRC. We also figured we had time to test and put it back, if needed. Did you find web content using it?
We haven't done a run yet to look for content using this. Promising to hear that Google code search didn't hit anything. I'll see if we can get some data here.
Was that an intentional breaking change? If so, why?
Yes, to simplify and tighten up grammar (and engines). We reckoned that only testsuites counted on this. This was recorded in some meeting notes but I'm not free to dig them up right now.
Must have missed that discussion. Doesn't seem a big win for engines or the grammar, as it reduces orthogonality in the grammar wrt variable declarations (I believe this introduces the only place that "var x" is allowed but cannot have an initializer?).
On Jun 13, 2013, at 7:24 PM, Luke Hoban <lukeh at microsoft.com> wrote:
We haven't done a run yet to look for content using this. Promising to hear that Google code search didn't hit anything. I'll see if we can get some data here.
Thanks.
Must have missed that discussion. Doesn't seem a big win for engines or the grammar, as it reduces orthogonality in the grammar wrt variable declarations (I believe this introduces the only place that "var x" is allowed but cannot have an initializer?).
Sure, but note the screwy one-declarator-only restriction. The semantics are too string out too in the existing specs prior to ES6. Inlining is better on both syntactic and semantic grounds.
On Fri 14 Jun 2013 04:24, Luke Hoban <lukeh at microsoft.com> writes:
(I believe this introduces the only place that "var x" is allowed but cannot have an initializer?).
FWIW, there are similar situations in the same spot of the grammar: let x
can't have an initializer in for-of or for-in, and neither can var x
in for-of.
On Jun 14, 2013, at 12:01 AM, Andy Wingo wrote:
On Fri 14 Jun 2013 04:24, Luke Hoban <lukeh at microsoft.com> writes:
(I believe this introduces the only place that "var x" is allowed but cannot have an initializer?).
FWIW, there are similar situations in the same spot of the grammar:
let x
can't have an initializer in for-of or for-in, and neither canvar x
in for-of.
Yes, and this was one of the consistency motivation to the var change.
for (const x = c of foo) ...
for (const x = c in foo) ...
simply woundn't work if x could have an initializer because a const can't be initialized twice.
for (let x of foo) ...
for (let x in foo) ...
with an initializer would suggest that the per iteration binding of x is initialized with the initialization expression. Is the initialization expression evaluated once or at the beginning of each iteration?
It is a simpler overall story to just not allow pointless initializers on declarations in for-in/for-of statements. The fact that we could find no dependencies upon for-in var initializers gave us confidence about introduce the breaking change for var.
Andy Wingo wrote:
On Fri 14 Jun 2013 04:24, Luke Hoban<lukeh at microsoft.com> writes:
(I believe this introduces the only place that "var x" is allowed but cannot have an initializer?).
FWIW, there are similar situations in the same spot of the grammar: "let x" can't have an initializer in for-of or for-in, and neither can "var x" in for-of.
Right. Again inlining and specializing can win. One may be tempted to over-share sub-parsers in JS. That bites back (and indeed did in ES1 days -- I believe the only reason we allowed an initializer in for(var/in) was because JScript did it that way, and Shon wrote the grammar down for the spec).
The ES6 draft grammar no longer allows the following, which was legal ES5:
for(var i = 1 in []) {}
Was that an intentional breaking change? If so, why? (Of course, there are exceedingly limited practical uses of this, but that alone doesn't seem to justify a breaking change).