let's assume we have a function and inside that function, we have a let declaration at the topmost level of the function.
now we run FunctionDeclarationInstantiation, but here comes the weird part, take a look at step 33.
Let lexDeclarations be the LexicallyScopedDeclarations of code.
so we invoked the LexicallyScopedDeclarations operation with the parse node FunctionBody.
therefore we run the implicit algorithm definition(because there is no algorithm for the FunctionBody production)
FunctionBody:FunctionStatementList
Return LexicallyScopedDeclarations of FunctionStatementList
so we get to this algorithm
FunctionStatementList:StatementList
Return the TopLevelLexicallyScopedDeclarations of StatementList.
and that's where my confusion begins, because now when we invoke TopLevelLexicallyScopedDeclarations with StatementList
and we will get here
StatementList : StatementList StatementListItem
1. Let declarations1 be TopLevelLexicallyScopedDeclarations of StatementList.
2. Let declarations2 be TopLevelLexicallyScopedDeclarations of StatementListItem.
3. Return the list-concatenation of declarations1 and declarations2.
finally, that will bring us to this algorithm
StatementListItem : Declaration
1. If Declaration is Declaration : HoistableDeclaration , then
a. Return a new empty List.
2. Return « Declaration ».
now, how are we supposed to obtain the let variable that I've mentioned above, if step 1 says that if that Declaration is a Declaration: HoistableDeclaration then we return an empty list
it doesn't make any sense to me.