My question is with regards to the ECMAScript specification.
I am currently following the specification to understand how a simple script is evaluated from start to end.
Following on from this question and answer, I am walking through the GlobalDeclarationInstantiation to see how a FunctionDeclaration gets instantiated (identifier added to the Global Environment Record (GER)) and initialized (value added to the identifier in the GER).
That leads me to step 5 of GlobalDeclarationInstantiation: Let varDeclarations be the VarScopedDeclarations of script.
.
Looking at VarScopedDeclarations, it seems to me that it never returns a Parse Node for FunctionDeclaration. In fact, it returns empty Lists for all syntactic grammar symbols, except for VarDeclarations. Which means that it only returns Parse Nodes for symbols following the var keyword. VarScopedDeclarations of var a = 5
would return a Parse Node containing a = 5
.
Questions
- Does VarScopedDeclarations ever return a Parse Node for FunctionDeclaration?
- If it does not, will step 8.1.i (
i. Assert: d is either a FunctionDeclaration...
) ever be a positive assertion? - If VarScopedDeclarations returns empty lists for most symbols, why have the spec creators bothered including them? Would it not be cleaner to only include the ones that actually return a Parse Node entry? It is the same in LexicallyScopedDeclarations and a few other operations.