ECMAScript® 2024 Language Specification

Draft ECMA-262 / February 15, 2024

8.2 Scope Analysis

8.2.1 Static Semantics: BoundNames

The syntax-directed operation BoundNames takes no arguments and returns a List of Strings.

Note

"*default*" is used within this specification as a synthetic name for a module's default export when it does not have another name. An entry in the module's [[Environment]] is created with that name and holds the corresponding value, and resolving the export named "default" by calling ResolveExport ( exportName [ , resolveSet ] ) for the module will return a ResolvedBinding Record whose [[BindingName]] is "*default*", which will then resolve in the module's [[Environment]] to the above-mentioned value. This is done only for ease of specification, so that anonymous default exports can be resolved like any other export. This "*default*" string is never accessible to ECMAScript code or to the module linking algorithm.

It is defined piecewise over the following productions:

BindingIdentifier : Identifier
  1. Return a List whose sole element is the StringValue of Identifier.
BindingIdentifier : yield
  1. Return « "yield" ».
BindingIdentifier : await
  1. Return « "await" ».
LexicalDeclaration : LetOrConst BindingList ;
  1. Return the BoundNames of BindingList.
BindingList : BindingList , LexicalBinding
  1. Let names1 be the BoundNames of BindingList.
  2. Let names2 be the BoundNames of LexicalBinding.
  3. Return the list-concatenation of names1 and names2.
LexicalBinding : BindingIdentifier Initializeropt
  1. Return the BoundNames of BindingIdentifier.
LexicalBinding : BindingPattern Initializer
  1. Return the BoundNames of BindingPattern.
VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. Let names1 be BoundNames of VariableDeclarationList.
  2. Let names2 be BoundNames of VariableDeclaration.
  3. Return the list-concatenation of names1 and names2.
VariableDeclaration : BindingIdentifier Initializeropt
  1. Return the BoundNames of BindingIdentifier.
VariableDeclaration : BindingPattern Initializer
  1. Return the BoundNames of BindingPattern.
ObjectBindingPattern : { }
  1. Return a new empty List.
ObjectBindingPattern : { BindingPropertyList , BindingRestProperty }
  1. Let names1 be BoundNames of BindingPropertyList.
  2. Let names2 be BoundNames of BindingRestProperty.
  3. Return the list-concatenation of names1 and names2.
ArrayBindingPattern : [ Elisionopt ]
  1. Return a new empty List.
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. Return the BoundNames of BindingRestElement.
ArrayBindingPattern : [ BindingElementList , Elisionopt ]
  1. Return the BoundNames of BindingElementList.
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. Let names1 be BoundNames of BindingElementList.
  2. Let names2 be BoundNames of BindingRestElement.
  3. Return the list-concatenation of names1 and names2.
BindingPropertyList : BindingPropertyList , BindingProperty
  1. Let names1 be BoundNames of BindingPropertyList.
  2. Let names2 be BoundNames of BindingProperty.
  3. Return the list-concatenation of names1 and names2.
BindingElementList : BindingElementList , BindingElisionElement
  1. Let names1 be BoundNames of BindingElementList.
  2. Let names2 be BoundNames of BindingElisionElement.
  3. Return the list-concatenation of names1 and names2.
BindingElisionElement : Elisionopt BindingElement
  1. Return BoundNames of BindingElement.
BindingProperty : PropertyName : BindingElement
  1. Return the BoundNames of BindingElement.
SingleNameBinding : BindingIdentifier Initializeropt
  1. Return the BoundNames of BindingIdentifier.
BindingElement : BindingPattern Initializeropt
  1. Return the BoundNames of BindingPattern.
ForDeclaration : LetOrConst ForBinding
  1. Return the BoundNames of ForBinding.
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. Return the BoundNames of BindingIdentifier.
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. Return « "*default*" ».
FormalParameters : [empty]
  1. Return a new empty List.
FormalParameters : FormalParameterList , FunctionRestParameter
  1. Let names1 be BoundNames of FormalParameterList.
  2. Let names2 be BoundNames of FunctionRestParameter.
  3. Return the list-concatenation of names1 and names2.
FormalParameterList : FormalParameterList , FormalParameter
  1. Let names1 be BoundNames of FormalParameterList.
  2. Let names2 be BoundNames of FormalParameter.
  3. Return the list-concatenation of names1 and names2.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be the ArrowFormalParameters that is covered by CoverParenthesizedExpressionAndArrowParameterList.
  2. Return the BoundNames of formals.
GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. Return the BoundNames of BindingIdentifier.
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. Return « "*default*" ».
AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. Return the BoundNames of BindingIdentifier.
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. Return « "*default*" ».
ClassDeclaration : class BindingIdentifier ClassTail
  1. Return the BoundNames of BindingIdentifier.
ClassDeclaration : class ClassTail
  1. Return « "*default*" ».
AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. Return the BoundNames of BindingIdentifier.
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. Return « "*default*" ».
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. Let head be the AsyncArrowHead that is covered by CoverCallExpressionAndAsyncArrowHead.
  2. Return the BoundNames of head.
ImportDeclaration : import ImportClause FromClause ;
  1. Return the BoundNames of ImportClause.
ImportDeclaration : import ModuleSpecifier ;
  1. Return a new empty List.
ImportClause : ImportedDefaultBinding , NameSpaceImport
  1. Let names1 be the BoundNames of ImportedDefaultBinding.
  2. Let names2 be the BoundNames of NameSpaceImport.
  3. Return the list-concatenation of names1 and names2.
ImportClause : ImportedDefaultBinding , NamedImports
  1. Let names1 be the BoundNames of ImportedDefaultBinding.
  2. Let names2 be the BoundNames of NamedImports.
  3. Return the list-concatenation of names1 and names2.
NamedImports : { }
  1. Return a new empty List.
ImportsList : ImportsList , ImportSpecifier
  1. Let names1 be the BoundNames of ImportsList.
  2. Let names2 be the BoundNames of ImportSpecifier.
  3. Return the list-concatenation of names1 and names2.
ImportSpecifier : ModuleExportName as ImportedBinding
  1. Return the BoundNames of ImportedBinding.
ExportDeclaration : export ExportFromClause FromClause ; export NamedExports ;
  1. Return a new empty List.
ExportDeclaration : export VariableStatement
  1. Return the BoundNames of VariableStatement.
ExportDeclaration : export Declaration
  1. Return the BoundNames of Declaration.
ExportDeclaration : export default HoistableDeclaration
  1. Let declarationNames be the BoundNames of HoistableDeclaration.
  2. If declarationNames does not include the element "*default*", append "*default*" to declarationNames.
  3. Return declarationNames.
ExportDeclaration : export default ClassDeclaration
  1. Let declarationNames be the BoundNames of ClassDeclaration.
  2. If declarationNames does not include the element "*default*", append "*default*" to declarationNames.
  3. Return declarationNames.
ExportDeclaration : export default AssignmentExpression ;
  1. Return « "*default*" ».

8.2.2 Static Semantics: DeclarationPart

The syntax-directed operation DeclarationPart takes no arguments and returns a Parse Node. It is defined piecewise over the following productions:

HoistableDeclaration : FunctionDeclaration
  1. Return FunctionDeclaration.
HoistableDeclaration : GeneratorDeclaration
  1. Return GeneratorDeclaration.
HoistableDeclaration : AsyncFunctionDeclaration
  1. Return AsyncFunctionDeclaration.
HoistableDeclaration : AsyncGeneratorDeclaration
  1. Return AsyncGeneratorDeclaration.
Declaration : ClassDeclaration
  1. Return ClassDeclaration.
Declaration : LexicalDeclaration
  1. Return LexicalDeclaration.

8.2.3 Static Semantics: IsConstantDeclaration

The syntax-directed operation IsConstantDeclaration takes no arguments and returns a Boolean. It is defined piecewise over the following productions:

LexicalDeclaration : LetOrConst BindingList ;
  1. Return IsConstantDeclaration of LetOrConst.
LetOrConst : let
  1. Return false.
LetOrConst : const
  1. Return true.
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody } GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody } AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody }
  1. Return false.
ClassDeclaration : class BindingIdentifier ClassTail class ClassTail
  1. Return false.
ExportDeclaration : export ExportFromClause FromClause ; export NamedExports ; export default AssignmentExpression ;
  1. Return false.
Note

It is not necessary to treat export default AssignmentExpression as a constant declaration because there is no syntax that permits assignment to the internal bound name used to reference a module's default object.

8.2.4 Static Semantics: LexicallyDeclaredNames

The syntax-directed operation LexicallyDeclaredNames takes no arguments and returns a List of Strings. It is defined piecewise over the following productions:

Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let names1 be LexicallyDeclaredNames of StatementList.
  2. Let names2 be LexicallyDeclaredNames of StatementListItem.
  3. Return the list-concatenation of names1 and names2.
StatementListItem : Statement
  1. If Statement is Statement : LabelledStatement , return LexicallyDeclaredNames of LabelledStatement.
  2. Return a new empty List.
StatementListItem : Declaration
  1. Return the BoundNames of Declaration.
CaseBlock : { }
  1. Return a new empty List.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, let names1 be the LexicallyDeclaredNames of the first CaseClauses.
  2. Else, let names1 be a new empty List.
  3. Let names2 be LexicallyDeclaredNames of DefaultClause.
  4. If the second CaseClauses is present, let names3 be the LexicallyDeclaredNames of the second CaseClauses.
  5. Else, let names3 be a new empty List.
  6. Return the list-concatenation of names1, names2, and names3.
CaseClauses : CaseClauses CaseClause
  1. Let names1 be LexicallyDeclaredNames of CaseClauses.
  2. Let names2 be LexicallyDeclaredNames of CaseClause.
  3. Return the list-concatenation of names1 and names2.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return the LexicallyDeclaredNames of StatementList.
  2. Return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the LexicallyDeclaredNames of StatementList.
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the LexicallyDeclaredNames of LabelledItem.
LabelledItem : Statement
  1. Return a new empty List.
LabelledItem : FunctionDeclaration
  1. Return BoundNames of FunctionDeclaration.
FunctionStatementList : [empty]
  1. Return a new empty List.
FunctionStatementList : StatementList
  1. Return TopLevelLexicallyDeclaredNames of StatementList.
ClassStaticBlockStatementList : [empty]
  1. Return a new empty List.
ClassStaticBlockStatementList : StatementList
  1. Return the TopLevelLexicallyDeclaredNames of StatementList.
ConciseBody : ExpressionBody
  1. Return a new empty List.
AsyncConciseBody : ExpressionBody
  1. Return a new empty List.
Script : [empty]
  1. Return a new empty List.
ScriptBody : StatementList
  1. Return TopLevelLexicallyDeclaredNames of StatementList.
Note 1

At the top level of a Script, function declarations are treated like var declarations rather than like lexical declarations.

Note 2

The LexicallyDeclaredNames of a Module includes the names of all of its imported bindings.

ModuleItemList : ModuleItemList ModuleItem
  1. Let names1 be LexicallyDeclaredNames of ModuleItemList.
  2. Let names2 be LexicallyDeclaredNames of ModuleItem.
  3. Return the list-concatenation of names1 and names2.
ModuleItem : ImportDeclaration
  1. Return the BoundNames of ImportDeclaration.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return a new empty List.
  2. Return the BoundNames of ExportDeclaration.
ModuleItem : StatementListItem
  1. Return LexicallyDeclaredNames of StatementListItem.
Note 3

At the top level of a Module, function declarations are treated like lexical declarations rather than like var declarations.

8.2.5 Static Semantics: LexicallyScopedDeclarations

The syntax-directed operation LexicallyScopedDeclarations takes no arguments and returns a List of Parse Nodes. It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. Let declarations1 be LexicallyScopedDeclarations of StatementList.
  2. Let declarations2 be LexicallyScopedDeclarations of StatementListItem.
  3. Return the list-concatenation of declarations1 and declarations2.
StatementListItem : Statement
  1. If Statement is Statement : LabelledStatement , return LexicallyScopedDeclarations of LabelledStatement.
  2. Return a new empty List.
StatementListItem : Declaration
  1. Return a List whose sole element is DeclarationPart of Declaration.
CaseBlock : { }
  1. Return a new empty List.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, let declarations1 be the LexicallyScopedDeclarations of the first CaseClauses.
  2. Else, let declarations1 be a new empty List.
  3. Let declarations2 be LexicallyScopedDeclarations of DefaultClause.
  4. If the second CaseClauses is present, let declarations3 be the LexicallyScopedDeclarations of the second CaseClauses.
  5. Else, let declarations3 be a new empty List.
  6. Return the list-concatenation of declarations1, declarations2, and declarations3.
CaseClauses : CaseClauses CaseClause
  1. Let declarations1 be LexicallyScopedDeclarations of CaseClauses.
  2. Let declarations2 be LexicallyScopedDeclarations of CaseClause.
  3. Return the list-concatenation of declarations1 and declarations2.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return the LexicallyScopedDeclarations of StatementList.
  2. Return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the LexicallyScopedDeclarations of StatementList.
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the LexicallyScopedDeclarations of LabelledItem.
LabelledItem : Statement
  1. Return a new empty List.
LabelledItem : FunctionDeclaration
  1. Return « FunctionDeclaration ».
FunctionStatementList : [empty]
  1. Return a new empty List.
FunctionStatementList : StatementList
  1. Return the TopLevelLexicallyScopedDeclarations of StatementList.
ClassStaticBlockStatementList : [empty]
  1. Return a new empty List.
ClassStaticBlockStatementList : StatementList
  1. Return the TopLevelLexicallyScopedDeclarations of StatementList.
ConciseBody : ExpressionBody
  1. Return a new empty List.
AsyncConciseBody : ExpressionBody
  1. Return a new empty List.
Script : [empty]
  1. Return a new empty List.
ScriptBody : StatementList
  1. Return TopLevelLexicallyScopedDeclarations of StatementList.
Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let declarations1 be LexicallyScopedDeclarations of ModuleItemList.
  2. Let declarations2 be LexicallyScopedDeclarations of ModuleItem.
  3. Return the list-concatenation of declarations1 and declarations2.
ModuleItem : ImportDeclaration
  1. Return a new empty List.
ExportDeclaration : export ExportFromClause FromClause ; export NamedExports ; export VariableStatement
  1. Return a new empty List.
ExportDeclaration : export Declaration
  1. Return a List whose sole element is DeclarationPart of Declaration.
ExportDeclaration : export default HoistableDeclaration
  1. Return a List whose sole element is DeclarationPart of HoistableDeclaration.
ExportDeclaration : export default ClassDeclaration
  1. Return a List whose sole element is ClassDeclaration.
ExportDeclaration : export default AssignmentExpression ;
  1. Return a List whose sole element is this ExportDeclaration.

8.2.6 Static Semantics: VarDeclaredNames

The syntax-directed operation VarDeclaredNames takes no arguments and returns a List of Strings. It is defined piecewise over the following productions:

Statement : EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement
  1. Return a new empty List.
Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let names1 be VarDeclaredNames of StatementList.
  2. Let names2 be VarDeclaredNames of StatementListItem.
  3. Return the list-concatenation of names1 and names2.
StatementListItem : Declaration
  1. Return a new empty List.
VariableStatement : var VariableDeclarationList ;
  1. Return BoundNames of VariableDeclarationList.
IfStatement : if ( Expression ) Statement else Statement
  1. Let names1 be VarDeclaredNames of the first Statement.
  2. Let names2 be VarDeclaredNames of the second Statement.
  3. Return the list-concatenation of names1 and names2.
IfStatement : if ( Expression ) Statement
  1. Return the VarDeclaredNames of Statement.
DoWhileStatement : do Statement while ( Expression ) ;
  1. Return the VarDeclaredNames of Statement.
WhileStatement : while ( Expression ) Statement
  1. Return the VarDeclaredNames of Statement.
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. Return the VarDeclaredNames of Statement.
ForStatement : for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
  1. Let names1 be BoundNames of VariableDeclarationList.
  2. Let names2 be VarDeclaredNames of Statement.
  3. Return the list-concatenation of names1 and names2.
ForStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return the VarDeclaredNames of Statement.
ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( ForDeclaration in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement
  1. Return the VarDeclaredNames of Statement.
ForInOfStatement : for ( var ForBinding in Expression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement
  1. Let names1 be the BoundNames of ForBinding.
  2. Let names2 be the VarDeclaredNames of Statement.
  3. Return the list-concatenation of names1 and names2.
Note

This section is extended by Annex B.3.5.

WithStatement : with ( Expression ) Statement
  1. Return the VarDeclaredNames of Statement.
SwitchStatement : switch ( Expression ) CaseBlock
  1. Return the VarDeclaredNames of CaseBlock.
CaseBlock : { }
  1. Return a new empty List.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, let names1 be the VarDeclaredNames of the first CaseClauses.
  2. Else, let names1 be a new empty List.
  3. Let names2 be VarDeclaredNames of DefaultClause.
  4. If the second CaseClauses is present, let names3 be the VarDeclaredNames of the second CaseClauses.
  5. Else, let names3 be a new empty List.
  6. Return the list-concatenation of names1, names2, and names3.
CaseClauses : CaseClauses CaseClause
  1. Let names1 be VarDeclaredNames of CaseClauses.
  2. Let names2 be VarDeclaredNames of CaseClause.
  3. Return the list-concatenation of names1 and names2.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return the VarDeclaredNames of StatementList.
  2. Return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the VarDeclaredNames of StatementList.
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the VarDeclaredNames of LabelledItem.
LabelledItem : FunctionDeclaration
  1. Return a new empty List.
TryStatement : try Block Catch
  1. Let names1 be VarDeclaredNames of Block.
  2. Let names2 be VarDeclaredNames of Catch.
  3. Return the list-concatenation of names1 and names2.
TryStatement : try Block Finally
  1. Let names1 be VarDeclaredNames of Block.
  2. Let names2 be VarDeclaredNames of Finally.
  3. Return the list-concatenation of names1 and names2.
TryStatement : try Block Catch Finally
  1. Let names1 be VarDeclaredNames of Block.
  2. Let names2 be VarDeclaredNames of Catch.
  3. Let names3 be VarDeclaredNames of Finally.
  4. Return the list-concatenation of names1, names2, and names3.
Catch : catch ( CatchParameter ) Block
  1. Return the VarDeclaredNames of Block.
FunctionStatementList : [empty]
  1. Return a new empty List.
FunctionStatementList : StatementList
  1. Return TopLevelVarDeclaredNames of StatementList.
ClassStaticBlockStatementList : [empty]
  1. Return a new empty List.
ClassStaticBlockStatementList : StatementList
  1. Return the TopLevelVarDeclaredNames of StatementList.
ConciseBody : ExpressionBody
  1. Return a new empty List.
AsyncConciseBody : ExpressionBody
  1. Return a new empty List.
Script : [empty]
  1. Return a new empty List.
ScriptBody : StatementList
  1. Return TopLevelVarDeclaredNames of StatementList.
ModuleItemList : ModuleItemList ModuleItem
  1. Let names1 be VarDeclaredNames of ModuleItemList.
  2. Let names2 be VarDeclaredNames of ModuleItem.
  3. Return the list-concatenation of names1 and names2.
ModuleItem : ImportDeclaration
  1. Return a new empty List.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return BoundNames of ExportDeclaration.
  2. Return a new empty List.

8.2.7 Static Semantics: VarScopedDeclarations

The syntax-directed operation VarScopedDeclarations takes no arguments and returns a List of Parse Nodes. It is defined piecewise over the following productions:

Statement : EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement
  1. Return a new empty List.
Block : { }
  1. Return a new empty List.
StatementList : StatementList StatementListItem
  1. Let declarations1 be VarScopedDeclarations of StatementList.
  2. Let declarations2 be VarScopedDeclarations of StatementListItem.
  3. Return the list-concatenation of declarations1 and declarations2.
StatementListItem : Declaration
  1. Return a new empty List.
VariableDeclarationList : VariableDeclaration
  1. Return « VariableDeclaration ».
VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. Let declarations1 be VarScopedDeclarations of VariableDeclarationList.
  2. Return the list-concatenation of declarations1 and « VariableDeclaration ».
IfStatement : if ( Expression ) Statement else Statement
  1. Let declarations1 be VarScopedDeclarations of the first Statement.
  2. Let declarations2 be VarScopedDeclarations of the second Statement.
  3. Return the list-concatenation of declarations1 and declarations2.
IfStatement : if ( Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.
DoWhileStatement : do Statement while ( Expression ) ;
  1. Return the VarScopedDeclarations of Statement.
WhileStatement : while ( Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. Return the VarScopedDeclarations of Statement.
ForStatement : for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
  1. Let declarations1 be VarScopedDeclarations of VariableDeclarationList.
  2. Let declarations2 be VarScopedDeclarations of Statement.
  3. Return the list-concatenation of declarations1 and declarations2.
ForStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. Return the VarScopedDeclarations of Statement.
ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( ForDeclaration in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement
  1. Return the VarScopedDeclarations of Statement.
ForInOfStatement : for ( var ForBinding in Expression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement
  1. Let declarations1 be « ForBinding ».
  2. Let declarations2 be VarScopedDeclarations of Statement.
  3. Return the list-concatenation of declarations1 and declarations2.
Note

This section is extended by Annex B.3.5.

WithStatement : with ( Expression ) Statement
  1. Return the VarScopedDeclarations of Statement.
SwitchStatement : switch ( Expression ) CaseBlock
  1. Return the VarScopedDeclarations of CaseBlock.
CaseBlock : { }
  1. Return a new empty List.
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. If the first CaseClauses is present, let declarations1 be the VarScopedDeclarations of the first CaseClauses.
  2. Else, let declarations1 be a new empty List.
  3. Let declarations2 be VarScopedDeclarations of DefaultClause.
  4. If the second CaseClauses is present, let declarations3 be the VarScopedDeclarations of the second CaseClauses.
  5. Else, let declarations3 be a new empty List.
  6. Return the list-concatenation of declarations1, declarations2, and declarations3.
CaseClauses : CaseClauses CaseClause
  1. Let declarations1 be VarScopedDeclarations of CaseClauses.
  2. Let declarations2 be VarScopedDeclarations of CaseClause.
  3. Return the list-concatenation of declarations1 and declarations2.
CaseClause : case Expression : StatementListopt
  1. If the StatementList is present, return the VarScopedDeclarations of StatementList.
  2. Return a new empty List.
DefaultClause : default : StatementListopt
  1. If the StatementList is present, return the VarScopedDeclarations of StatementList.
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the VarScopedDeclarations of LabelledItem.
LabelledItem : FunctionDeclaration
  1. Return a new empty List.
TryStatement : try Block Catch
  1. Let declarations1 be VarScopedDeclarations of Block.
  2. Let declarations2 be VarScopedDeclarations of Catch.
  3. Return the list-concatenation of declarations1 and declarations2.
TryStatement : try Block Finally
  1. Let declarations1 be VarScopedDeclarations of Block.
  2. Let declarations2 be VarScopedDeclarations of Finally.
  3. Return the list-concatenation of declarations1 and declarations2.
TryStatement : try Block Catch Finally
  1. Let declarations1 be VarScopedDeclarations of Block.
  2. Let declarations2 be VarScopedDeclarations of Catch.
  3. Let declarations3 be VarScopedDeclarations of Finally.
  4. Return the list-concatenation of declarations1, declarations2, and declarations3.
Catch : catch ( CatchParameter ) Block
  1. Return the VarScopedDeclarations of Block.
FunctionStatementList : [empty]
  1. Return a new empty List.
FunctionStatementList : StatementList
  1. Return the TopLevelVarScopedDeclarations of StatementList.
ClassStaticBlockStatementList : [empty]
  1. Return a new empty List.
ClassStaticBlockStatementList : StatementList
  1. Return the TopLevelVarScopedDeclarations of StatementList.
ConciseBody : ExpressionBody
  1. Return a new empty List.
AsyncConciseBody : ExpressionBody
  1. Return a new empty List.
Script : [empty]
  1. Return a new empty List.
ScriptBody : StatementList
  1. Return TopLevelVarScopedDeclarations of StatementList.
Module : [empty]
  1. Return a new empty List.
ModuleItemList : ModuleItemList ModuleItem
  1. Let declarations1 be VarScopedDeclarations of ModuleItemList.
  2. Let declarations2 be VarScopedDeclarations of ModuleItem.
  3. Return the list-concatenation of declarations1 and declarations2.
ModuleItem : ImportDeclaration
  1. Return a new empty List.
ModuleItem : ExportDeclaration
  1. If ExportDeclaration is export VariableStatement, return VarScopedDeclarations of VariableStatement.
  2. Return a new empty List.

8.2.8 Static Semantics: TopLevelLexicallyDeclaredNames

The syntax-directed operation TopLevelLexicallyDeclaredNames takes no arguments and returns a List of Strings. It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. Let names1 be TopLevelLexicallyDeclaredNames of StatementList.
  2. Let names2 be TopLevelLexicallyDeclaredNames of StatementListItem.
  3. Return the list-concatenation of names1 and names2.
StatementListItem : Statement
  1. Return a new empty List.
StatementListItem : Declaration
  1. If Declaration is Declaration : HoistableDeclaration , then
    1. Return a new empty List.
  2. Return the BoundNames of Declaration.
Note

At the top level of a function, or script, function declarations are treated like var declarations rather than like lexical declarations.

8.2.9 Static Semantics: TopLevelLexicallyScopedDeclarations

The syntax-directed operation TopLevelLexicallyScopedDeclarations takes no arguments and returns a List of Parse Nodes. It is defined piecewise over the following productions:

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.
StatementListItem : Statement
  1. Return a new empty List.
StatementListItem : Declaration
  1. If Declaration is Declaration : HoistableDeclaration , then
    1. Return a new empty List.
  2. Return « Declaration ».

8.2.10 Static Semantics: TopLevelVarDeclaredNames

The syntax-directed operation TopLevelVarDeclaredNames takes no arguments and returns a List of Strings. It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. Let names1 be TopLevelVarDeclaredNames of StatementList.
  2. Let names2 be TopLevelVarDeclaredNames of StatementListItem.
  3. Return the list-concatenation of names1 and names2.
StatementListItem : Declaration
  1. If Declaration is Declaration : HoistableDeclaration , then
    1. Return the BoundNames of HoistableDeclaration.
  2. Return a new empty List.
StatementListItem : Statement
  1. If Statement is Statement : LabelledStatement , return TopLevelVarDeclaredNames of Statement.
  2. Return VarDeclaredNames of Statement.
Note

At the top level of a function or script, inner function declarations are treated like var declarations.

LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the TopLevelVarDeclaredNames of LabelledItem.
LabelledItem : Statement
  1. If Statement is Statement : LabelledStatement , return TopLevelVarDeclaredNames of Statement.
  2. Return VarDeclaredNames of Statement.
LabelledItem : FunctionDeclaration
  1. Return BoundNames of FunctionDeclaration.

8.2.11 Static Semantics: TopLevelVarScopedDeclarations

The syntax-directed operation TopLevelVarScopedDeclarations takes no arguments and returns a List of Parse Nodes. It is defined piecewise over the following productions:

StatementList : StatementList StatementListItem
  1. Let declarations1 be TopLevelVarScopedDeclarations of StatementList.
  2. Let declarations2 be TopLevelVarScopedDeclarations of StatementListItem.
  3. Return the list-concatenation of declarations1 and declarations2.
StatementListItem : Statement
  1. If Statement is Statement : LabelledStatement , return TopLevelVarScopedDeclarations of Statement.
  2. Return VarScopedDeclarations of Statement.
StatementListItem : Declaration
  1. If Declaration is Declaration : HoistableDeclaration , then
    1. Let declaration be DeclarationPart of HoistableDeclaration.
    2. Return « declaration ».
  2. Return a new empty List.
LabelledStatement : LabelIdentifier : LabelledItem
  1. Return the TopLevelVarScopedDeclarations of LabelledItem.
LabelledItem : Statement
  1. If Statement is Statement : LabelledStatement , return TopLevelVarScopedDeclarations of Statement.
  2. Return VarScopedDeclarations of Statement.
LabelledItem : FunctionDeclaration
  1. Return « FunctionDeclaration ».