FunctionDeclaration as an element of a Block statement's StatementList

Allen Wirfs-Brock allen at wirfs-brock.com
Tue May 20 14:03:13 PDT 2014


On May 20, 2014, at 12:58 PM, Garrett Smith wrote:

> "Prior to the Sixth Edition, the ECMAScript specification did not
> define the occurrence of a FunctionDeclaration as an element of a
> Block statement's StatementList."
> 
> The problem is not necessarily that FunctionDeclaration appears in a
> Block, that FunctionDeclatation appears  in places in a program where
> a Statement is permitted but a FunctionDeclaration is not.
> 
> ES5 mentioned it:
> 
> "Several widely used implementations of ECMAScript are known to
> support the use of FunctionDeclaration as a Statement."
> 
> I don't have a concrete proposal, but I wonder why specifying as ES6
> does makes less sense to take the text that ES5 had in s 12 and
> attempt to codify, as ES6 does, except using Statement instead of
> StatementList.
> 
> http://ecma-international.org/ecma-262/5.1/#sec-12
> https://people.mozilla.org/~jorendorff/es6-draft.html#sec-web-legacy-compatibility-for-block-level-function-declarations

Because we don't know what an apparent conditional declaration, eg:

   if (predicate) function foo() { };

should mean in the context of ES6's declaration rules.  While on the other hand, it is really clear what the meaning of

  if (predicate) {function foo() {}}

should if you apply the ES6 declaration rules.

So the only issue is what hacks do we have to provide to keep currently interoperable (among multiple browsers) code working that has some sort of legacy use of FunctionDeclaration in a Statement context.  It turns out that T39 conclude that a naked FunctionDeclaration in a conditional statement context is not in the current interoperable intersection semantics and hence we don't need special hacks to support it.

Allen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140520/13b04894/attachment-0001.html>


More information about the es-discuss mailing list