Brendan Eich (2015-02-02T17:46:30.000Z)
Mark S. Miller wrote:
> On Mon, Feb 2, 2015 at 8:21 AM, Felix Kling <list at felix-kling.de 
> <mailto:list at felix-kling.de>> wrote:
>
>     With ES6 having a production rule "Declaration" and ES5 having
>     "FunctionDeclaration", I'm curious why a variable declaration (as
>     we say), officially "VariableStatement", has not been originally
>     defined as a declaration (back then).
>
>     Would you consider it to be a declaration today if we didn't need
>     backwards compatibility? Or is there another reason that requires
>     it to be a statement?
>
>
>
> If it wasn't for backward compatibility, "var" would disappear 
> entirely, leaving only lexical "let" "const" and "function", making 
> VariableStatement disappear as well.
>
>
> -- 
>     Cheers,
>     --MarkM
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


I took Felix's question to be about grammar naming and factoring 
conventions, not about `var` per se.

Since ES1 (ECMA-262 Edition 1, E262.pdf on the ecma-international.org 
site), the grammar called the nonterminal producing `var` declarations 
/VariableStatement/ (ES1 2.2). That was simply for consonance with the 
other productions reached directly from the Statement nonterminal. It 
was just a nominal choice, nothing was intended to contradict that `var` 
was a declaring form.

 From the start, /VariableStatement/ produced right-hand sides with 
/Declaration/-based names:


VariableStatement :
var VariableDeclarationList ;


to clue readers in just a bit. Arguably /VariableStatement/ was the 
better name from "above" in the grammar-structure sense, since it acts 
like a statement and may occur unbraced even as a sub-statement (e.g. 
consequent of an if (condition)).

(An even better name from the C family of languages than 
/VariableDeclarationList/ would be /VariableDeclaratorList/. The `var` 
introduces a list of declarators; the whole is a declaration (which may 
bind many names, either at top level or via destructuring). An ancient 
nit I failed to pick in ES1 days.)


ES5 didn't change things much, but ES6 did indeed add /Declaration/ as a 
new non-terminal produced from /StatementListItem/. IINM, Felix is 
asking why when this was done, /VariableStatement/ was not moved to the 
new /Declaration/ sub-grammar. Allen might want to comment.

/be


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150202/7e2a47ec/attachment.html>
d at domenic.me (2015-02-13T23:52:14.490Z)
I took Felix's question to be about grammar naming and factoring 
conventions, not about `var` per se.

Since ES1 (ECMA-262 Edition 1, E262.pdf on the ecma-international.org 
site), the grammar called the nonterminal producing `var` declarations 
_VariableStatement_ (ES1 2.2). That was simply for consonance with the 
other productions reached directly from the Statement nonterminal. It 
was just a nominal choice, nothing was intended to contradict that `var` 
was a declaring form.

 From the start, _VariableStatement_ produced right-hand sides with 
_Declaration_-based names:

```
VariableStatement :
var VariableDeclarationList ;
```

to clue readers in just a bit. Arguably _VariableStatement_ was the 
better name from "above" in the grammar-structure sense, since it acts 
like a statement and may occur unbraced even as a sub-statement (e.g. 
consequent of an if (condition)).

(An even better name from the C family of languages than 
_VariableDeclarationList_ would be _VariableDeclaratorList_. The `var` 
introduces a list of declarators; the whole is a declaration (which may 
bind many names, either at top level or via destructuring). An ancient 
nit I failed to pick in ES1 days.)


ES5 didn't change things much, but ES6 did indeed add _Declaration_ as a 
new non-terminal produced from _StatementListItem_. IINM, Felix is 
asking why when this was done, _VariableStatement_ was not moved to the 
new _Declaration_ sub-grammar. Allen might want to comment.