1

I'm reading EcmaScript specification.

At 9.2.12, there are:

11.Let varNames be the VarDeclaredNames of code. 
12.Let varDeclarations be the VarScopedDeclarations of code.

And at 13.1.5 and 13.1.6:

13.1.5 Static Semantics: VarDeclaredNames

Statement :

EmptyStatement
ExpressionStatement
ContinueStatement
BreakStatement
ReturnStatement
ThrowStatement
DebuggerStatement
Return a new empty List.

13.1.6 Static Semantics: VarScopedDeclarations

Statement :

EmptyStatement
ExpressionStatement
ContinueStatement
BreakStatement
ReturnStatement
ThrowStatement
DebuggerStatement
Return a new empty List.

They look like the same.So I want to know what's the difference between VarDeclaredNames and VarScopedDeclarations ? Can you give me some examples?

Thanks.

SmallTown NE
  • 543
  • 1
  • 7
  • 25
  • 1
    §13.1 is not the only section detailing these static semantics – Bergi Nov 15 '16 at 13:56
  • @Bergi sorry,I know there are "See also: 13.1.5, 13.2.11, 13.3.2.2, 13.6.5, 13.7.2.4, 13.7.3.4, 13.7.4.5, 13.7.5.7, 13.11.5, 13.12.7, 13.13.12, 13.15.5, 14.2.12, 15.1.5, 15.2.1.13". But I don't find any other explanation describles the problem more detailedly than 13.1 – SmallTown NE Nov 15 '16 at 14:03
  • Well, in those sections for the other kinds of statements the `VarDeclaredNames` differ from the `VarScopedDeclarations`. – Bergi Nov 15 '16 at 14:08
  • 1
    They return different data types, so that seems like a big difference? – loganfsmyth Nov 15 '16 at 17:28
  • @Bergi I checked all other kinds of statements in those sections, they are really the same – SmallTown NE Nov 16 '16 at 01:57
  • @loganfsmyth Really?Can you tell me what you say in which section?Thanks – SmallTown NE Nov 16 '16 at 01:58

1 Answers1

3

Those two static semantic rules search the AST for the same kinds of things: VariableDeclarations, ForBindings, FunctionDeclarations and GeneratorDeclarations. There's a lot of duplication (especially in methodology) indeed.

However, as @loganfsmyth mentions in the comments, they do return different data - different types of lists. While VarDeclaredNames returns a list of names (strings), VarScopedDeclarations does return a list of declarations (i.e. AST nodes).

This is apparent in the sections where something is actually appended to the lists: §13.3.2.2, §13.7.4.5, §13.7.5.7, and §13.2.9 all do refer to the BoundNames of the respective element, while §13.3.2.3, §13.7.4.6, §13.7.5.8, and §13.2.10 do refer to the respective declaration itself.

Why is this distinction needed? The VarDeclaredNames are used to create the bindings in the scope, while the VarScopedDeclarations are used to find the function declarations to create (and initialise the bindings with those values).

Could it have been simpler? Yes, surely - for lexical declarations, the scope initialisation description just iterates the declarations and gets the BoundNames of each. You might want to submit a bug to spec authors to use this approach for function-level declarations as well. See issue 1203 discussing this.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • thanks for your answer! By the way, can you give me some suggestions on reading the spec?Because sometimes there are a few terms or discriptions that I can't understand. Thanks again! @Bergi – SmallTown NE Nov 17 '16 at 06:48