Multipage preference

8 语法制导操作

除本节中定义的操作外,本规范各处还定义了专门的语法制导操作。

8.1 Runtime Semantics: Evaluation

The syntax-directed operation Evaluation takes no arguments and returns a Completion Record.

Note
此操作的定义分布在本规范的“ECMAScript 语言”各节中。每个定义都出现在相关产生式的定义性出现之后。

8.2 作用域分析

8.2.1 Static Semantics: BoundNames

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

Note

"*default*" 在本规范中用作模块默认导出的合成名称,当该默认导出没有其他名称时使用。模块的 [[Environment]] 中会用该名称创建一个条目并保存对应的值,并且通过为该模块调用 ResolveExport ( exportName [ , resolveSet ] ) 来解析名为 "default" 的导出,将返回一个 [[BindingName]] 为 "*default*" 的 ResolvedBinding Record,随后它会在模块的 [[Environment]] 中解析为上述值。这样做只是为了方便规范表述,使匿名默认导出可以像任何其他导出一样被解析。这个 "*default*" 字符串永远不能被 ECMAScript 代码或模块链接算法访问。

It is defined piecewise over the following productions:

BindingIdentifier : Identifier
  1. 返回一个 List,其唯一元素是 Identifier 的 StringValue。
BindingIdentifier : yield
  1. 返回 « "yield" »。
BindingIdentifier : await
  1. 返回 « "await" »。
LexicalDeclaration : LetOrConst BindingList ;
  1. 返回 BindingList 的 BoundNames。
UsingDeclaration : using BindingList ; AwaitUsingDeclaration : CoverAwaitExpressionAndAwaitUsingDeclarationHead BindingList ;
  1. 返回 BindingList 的 BoundNames。
BindingList : BindingList , LexicalBinding
  1. 令 names1 为 BindingList 的 BoundNames。
  2. 令 names2 为 LexicalBinding 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
LexicalBinding : BindingIdentifier Initializeropt
  1. 返回 BindingIdentifier 的 BoundNames。
LexicalBinding : BindingPattern Initializer
  1. 返回 BindingPattern 的 BoundNames。
VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. 令 names1 为 VariableDeclarationList 的 BoundNames。
  2. 令 names2 为 VariableDeclaration 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
VariableDeclaration : BindingIdentifier Initializeropt
  1. 返回 BindingIdentifier 的 BoundNames。
VariableDeclaration : BindingPattern Initializer
  1. 返回 BindingPattern 的 BoundNames。
ObjectBindingPattern : { }
  1. 返回一个新的空 List。
ObjectBindingPattern : { BindingPropertyList , BindingRestProperty }
  1. 令 names1 为 BindingPropertyList 的 BoundNames。
  2. 令 names2 为 BindingRestProperty 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
ArrayBindingPattern : [ Elisionopt ]
  1. 返回一个新的空 List。
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. 返回 BindingRestElement 的 BoundNames。
ArrayBindingPattern : [ BindingElementList , Elisionopt ]
  1. 返回 BindingElementList 的 BoundNames。
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. 令 names1 为 BindingElementList 的 BoundNames。
  2. 令 names2 为 BindingRestElement 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
BindingPropertyList : BindingPropertyList , BindingProperty
  1. 令 names1 为 BindingPropertyList 的 BoundNames。
  2. 令 names2 为 BindingProperty 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
BindingElementList : BindingElementList , BindingElisionElement
  1. 令 names1 为 BindingElementList 的 BoundNames。
  2. 令 names2 为 BindingElisionElement 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
BindingElisionElement : Elisionopt BindingElement
  1. 返回 BindingElement 的 BoundNames。
BindingProperty : PropertyName : BindingElement
  1. 返回 BindingElement 的 BoundNames。
SingleNameBinding : BindingIdentifier Initializeropt
  1. 返回 BindingIdentifier 的 BoundNames。
BindingElement : BindingPattern Initializeropt
  1. 返回 BindingPattern 的 BoundNames。
ForDeclaration : LetOrConst ForBinding
  1. 返回 ForBinding 的 BoundNames。
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody }
  1. 返回 BindingIdentifier 的 BoundNames。
FunctionDeclaration : function ( FormalParameters ) { FunctionBody }
  1. 返回 « "*default*" »。
FormalParameters : [empty]
  1. 返回一个新的空 List。
FormalParameters : FormalParameterList , FunctionRestParameter
  1. 令 names1 为 FormalParameterList 的 BoundNames。
  2. 令 names2 为 FunctionRestParameter 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
FormalParameterList : FormalParameterList , FormalParameter
  1. 令 names1 为 FormalParameterList 的 BoundNames。
  2. 令 names2 为 FormalParameter 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. 令 formals 为 CoverParenthesizedExpressionAndArrowParameterList 所覆盖的 ArrowFormalParameters。
  2. 返回 formals 的 BoundNames。
GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody }
  1. 返回 BindingIdentifier 的 BoundNames。
GeneratorDeclaration : function * ( FormalParameters ) { GeneratorBody }
  1. 返回 « "*default*" »。
AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody }
  1. 返回 BindingIdentifier 的 BoundNames。
AsyncGeneratorDeclaration : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. 返回 « "*default*" »。
ClassDeclaration : class BindingIdentifier ClassTail
  1. 返回 BindingIdentifier 的 BoundNames。
ClassDeclaration : class ClassTail
  1. 返回 « "*default*" »。
AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
  1. 返回 BindingIdentifier 的 BoundNames。
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
  1. 返回 « "*default*" »。
CoverCallExpressionAndAsyncArrowHead : MemberExpression Arguments
  1. 令 head 为 CoverCallExpressionAndAsyncArrowHead 所覆盖的 AsyncArrowHead。
  2. 返回 head 的 BoundNames。
ImportDeclaration : import ImportClause FromClause WithClauseopt ;
  1. 返回 ImportClause 的 BoundNames。
ImportDeclaration : import ModuleSpecifier WithClauseopt ;
  1. 返回一个新的空 List。
ImportClause : ImportedDefaultBinding , NameSpaceImport
  1. 令 names1 为 ImportedDefaultBinding 的 BoundNames。
  2. 令 names2 为 NameSpaceImport 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
ImportClause : ImportedDefaultBinding , NamedImports
  1. 令 names1 为 ImportedDefaultBinding 的 BoundNames。
  2. 令 names2 为 NamedImports 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
NamedImports : { }
  1. 返回一个新的空 List。
ImportsList : ImportsList , ImportSpecifier
  1. 令 names1 为 ImportsList 的 BoundNames。
  2. 令 names2 为 ImportSpecifier 的 BoundNames。
  3. 返回 names1 和 names2 的列表连接。
ImportSpecifier : ModuleExportName as ImportedBinding
  1. 返回 ImportedBinding 的 BoundNames。
ExportDeclaration : export ExportFromClause FromClause WithClauseopt ; export NamedExports ;
  1. 返回一个新的空 List。
ExportDeclaration : export VariableStatement
  1. 返回 VariableStatement 的 BoundNames。
ExportDeclaration : export Declaration
  1. 返回 Declaration 的 BoundNames。
ExportDeclaration : export default HoistableDeclaration
  1. 令 declNames 为 HoistableDeclaration 的 BoundNames。
  2. 如果 declNames 不包含元素 "*default*",则将 "*default*" 追加到 declNames。
  3. 返回 declNames。
ExportDeclaration : export default ClassDeclaration
  1. 令 declNames 为 ClassDeclaration 的 BoundNames。
  2. 如果 declNames 不包含元素 "*default*",则将 "*default*" 追加到 declNames。
  3. 返回 declNames。
ExportDeclaration : export default AssignmentExpression ;
  1. 返回 « "*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. 返回 FunctionDeclaration。
HoistableDeclaration : GeneratorDeclaration
  1. 返回 GeneratorDeclaration。
HoistableDeclaration : AsyncFunctionDeclaration
  1. 返回 AsyncFunctionDeclaration。
HoistableDeclaration : AsyncGeneratorDeclaration
  1. 返回 AsyncGeneratorDeclaration。
Declaration : ClassDeclaration
  1. 返回 ClassDeclaration。
Declaration : LexicalDeclaration
  1. 返回 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. 返回 LetOrConst 的 IsConstantDeclaration。
LetOrConst : let
  1. 返回 false。
LetOrConst : const
  1. 返回 true。
UsingDeclaration : using BindingList ; AwaitUsingDeclaration : CoverAwaitExpressionAndAwaitUsingDeclarationHead BindingList ;
  1. 返回 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. 返回 false。
ClassDeclaration : class BindingIdentifier ClassTail class ClassTail
  1. 返回 false。
ExportDeclaration : export ExportFromClause FromClause ; export NamedExports ; export default AssignmentExpression ;
  1. 返回 false。
Note

无需将 export default AssignmentExpression 视为常量声明,因为没有语法允许对用于引用模块默认对象的内部绑定名称进行赋值。

8.2.4 Static Semantics: IsUsingDeclaration

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

LexicalDeclaration : LetOrConst BindingList ;
  1. 返回 false。
UsingDeclaration : using BindingList ;
  1. 返回 true。
AwaitUsingDeclaration : CoverAwaitExpressionAndAwaitUsingDeclarationHead BindingList ;
  1. 返回 false。
ForDeclaration : LetOrConst ForBinding
  1. 返回 false。
ForDeclaration : using ForBinding
  1. 返回 true。
ForDeclaration : await using ForBinding
  1. 返回 false。
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. 返回 false。
ClassDeclaration : class BindingIdentifier ClassTail class ClassTail
  1. 返回 false。

8.2.5 Static Semantics: IsAwaitUsingDeclaration

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

LexicalDeclaration : LetOrConst BindingList ;
  1. 返回 false。
UsingDeclaration : using BindingList ;
  1. 返回 false。
AwaitUsingDeclaration : CoverAwaitExpressionAndAwaitUsingDeclarationHead BindingList ;
  1. 返回 true。
ForDeclaration : LetOrConst ForBinding
  1. 返回 false。
ForDeclaration : using ForBinding
  1. 返回 false。
ForDeclaration : await using ForBinding
  1. 返回 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. 返回 false。
ClassDeclaration : class BindingIdentifier ClassTail class ClassTail
  1. 返回 false。

8.2.6 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. 返回一个新的空 List。
StatementList : StatementList StatementListItem
  1. 令 names1 为 StatementList 的 LexicallyDeclaredNames。
  2. 令 names2 为 StatementListItem 的 LexicallyDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
StatementListItem : Statement
  1. 如果 Statement 是 Statement : LabelledStatement ,则返回 LabelledStatement 的 LexicallyDeclaredNames。
  2. 返回一个新的空 List。
StatementListItem : Declaration
  1. 返回 Declaration 的 BoundNames。
CaseBlock : { }
  1. 返回一个新的空 List。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. 如果第一个 CaseClauses 存在,则令 names1 为第一个 CaseClauses 的 LexicallyDeclaredNames。
  2. 否则,令 names1 为一个新的空 List。
  3. 令 names2 为 DefaultClause 的 LexicallyDeclaredNames。
  4. 如果第二个 CaseClauses 存在,则令 names3 为第二个 CaseClauses 的 LexicallyDeclaredNames。
  5. 否则,令 names3 为一个新的空 List。
  6. 返回 names1、names2 和 names3 的列表连接。
CaseClauses : CaseClauses CaseClause
  1. 令 names1 为 CaseClauses 的 LexicallyDeclaredNames。
  2. 令 names2 为 CaseClause 的 LexicallyDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
CaseClause : case Expression : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 的 LexicallyDeclaredNames。
  2. 返回一个新的空 List。
DefaultClause : default : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 的 LexicallyDeclaredNames。
  2. 返回一个新的空 List。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 返回 LabelledItem 的 LexicallyDeclaredNames。
LabelledItem : Statement
  1. 返回一个新的空 List。
LabelledItem : FunctionDeclaration
  1. 返回 FunctionDeclaration 的 BoundNames。
FunctionStatementList : [empty]
  1. 返回一个新的空 List。
FunctionStatementList : StatementList
  1. 返回 StatementList 的 TopLevelLexicallyDeclaredNames。
ClassStaticBlockStatementList : [empty]
  1. 返回一个新的空 List。
ClassStaticBlockStatementList : StatementList
  1. 返回 StatementList 的 TopLevelLexicallyDeclaredNames。
ConciseBody : ExpressionBody
  1. 返回一个新的空 List。
AsyncConciseBody : ExpressionBody
  1. 返回一个新的空 List。
Script : [empty]
  1. 返回一个新的空 List。
ScriptBody : StatementList
  1. 返回 StatementList 的 TopLevelLexicallyDeclaredNames。
Note 1

在 Script 的顶层,函数声明会被像 var 声明一样处理,而不是像词法声明一样处理。

Note 2

Module 的 LexicallyDeclaredNames 包括其所有导入绑定的名称。

ModuleItemList : ModuleItemList ModuleItem
  1. 令 names1 为 ModuleItemList 的 LexicallyDeclaredNames。
  2. 令 names2 为 ModuleItem 的 LexicallyDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
ModuleItem : ImportDeclaration
  1. 返回 ImportDeclaration 的 BoundNames。
ModuleItem : ExportDeclaration
  1. 如果 ExportDeclaration 是 export VariableStatement,则返回一个新的空 List。
  2. 返回 ExportDeclaration 的 BoundNames。
ModuleItem : StatementListItem
  1. 返回 StatementListItem 的 LexicallyDeclaredNames。
Note 3

在 Module 的顶层,函数声明会被像词法声明一样处理,而不是像 var 声明一样处理。

8.2.7 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. 令 decls1 为 StatementList 的 LexicallyScopedDeclarations。
  2. 令 decls2 为 StatementListItem 的 LexicallyScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
StatementListItem : Statement
  1. 如果 Statement 是 Statement : LabelledStatement ,则返回 LabelledStatement 的 LexicallyScopedDeclarations。
  2. 返回一个新的空 List。
StatementListItem : Declaration
  1. 返回一个 List,其唯一元素是 Declaration 的 DeclarationPart。
CaseBlock : { }
  1. 返回一个新的空 List。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. 如果第一个 CaseClauses 存在,则令 decls1 为第一个 CaseClauses 的 LexicallyScopedDeclarations。
  2. 否则,令 decls1 为一个新的空 List。
  3. 令 decls2 为 DefaultClause 的 LexicallyScopedDeclarations。
  4. 如果第二个 CaseClauses 存在,则令 decls3 为第二个 CaseClauses 的 LexicallyScopedDeclarations。
  5. 否则,令 decls3 为一个新的空 List。
  6. 返回 decls1、decls2 和 decls3 的列表连接。
CaseClauses : CaseClauses CaseClause
  1. 令 decls1 为 CaseClauses 的 LexicallyScopedDeclarations。
  2. 令 decls2 为 CaseClause 的 LexicallyScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
CaseClause : case Expression : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 的 LexicallyScopedDeclarations。
  2. 返回一个新的空 List。
DefaultClause : default : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 的 LexicallyScopedDeclarations。
  2. 返回一个新的空 List。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 返回 LabelledItem 的 LexicallyScopedDeclarations。
LabelledItem : Statement
  1. 返回一个新的空 List。
LabelledItem : FunctionDeclaration
  1. 返回 « FunctionDeclaration »。
FunctionStatementList : [empty]
  1. 返回一个新的空 List。
FunctionStatementList : StatementList
  1. 返回 StatementList 的 TopLevelLexicallyScopedDeclarations。
ClassStaticBlockStatementList : [empty]
  1. 返回一个新的空 List。
ClassStaticBlockStatementList : StatementList
  1. 返回 StatementList 的 TopLevelLexicallyScopedDeclarations。
ConciseBody : ExpressionBody
  1. 返回一个新的空 List。
AsyncConciseBody : ExpressionBody
  1. 返回一个新的空 List。
Script : [empty]
  1. 返回一个新的空 List。
ScriptBody : StatementList
  1. 返回 StatementList 的 TopLevelLexicallyScopedDeclarations。
Module : [empty]
  1. 返回一个新的空 List。
ModuleItemList : ModuleItemList ModuleItem
  1. 令 decls1 为 ModuleItemList 的 LexicallyScopedDeclarations。
  2. 令 decls2 为 ModuleItem 的 LexicallyScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
ModuleItem : ImportDeclaration
  1. 返回一个新的空 List。
ExportDeclaration : export ExportFromClause FromClause WithClauseopt ; export NamedExports ; export VariableStatement
  1. 返回一个新的空 List。
ExportDeclaration : export Declaration
  1. 返回一个 List,其唯一元素是 Declaration 的 DeclarationPart。
ExportDeclaration : export default HoistableDeclaration
  1. 返回一个 List,其唯一元素是 HoistableDeclaration 的 DeclarationPart。
ExportDeclaration : export default ClassDeclaration
  1. 返回一个 List,其唯一元素是 ClassDeclaration。
ExportDeclaration : export default AssignmentExpression ;
  1. 返回一个 List,其唯一元素是此 ExportDeclaration。

8.2.8 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. 返回一个新的空 List。
Block : { }
  1. 返回一个新的空 List。
StatementList : StatementList StatementListItem
  1. 令 names1 为 StatementList 的 VarDeclaredNames。
  2. 令 names2 为 StatementListItem 的 VarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
StatementListItem : Declaration
  1. 返回一个新的空 List。
VariableStatement : var VariableDeclarationList ;
  1. 返回 VariableDeclarationList 的 BoundNames。
IfStatement : if ( Expression ) Statement else Statement
  1. 令 names1 为第一个 Statement 的 VarDeclaredNames。
  2. 令 names2 为第二个 Statement 的 VarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
IfStatement : if ( Expression ) Statement
  1. 返回 Statement 的 VarDeclaredNames。
DoWhileStatement : do Statement while ( Expression ) ;
  1. 返回 Statement 的 VarDeclaredNames。
WhileStatement : while ( Expression ) Statement
  1. 返回 Statement 的 VarDeclaredNames。
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. 返回 Statement 的 VarDeclaredNames。
ForStatement : for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
  1. 令 names1 为 VariableDeclarationList 的 BoundNames。
  2. 令 names2 为 Statement 的 VarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
ForStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. 返回 Statement 的 VarDeclaredNames。
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. 返回 Statement 的 VarDeclaredNames。
ForInOfStatement : for ( var ForBinding in Expression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement
  1. 令 names1 为 ForBinding 的 BoundNames。
  2. 令 names2 为 Statement 的 VarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
Note

本节由附录 B.3.5 扩展。

WithStatement : with ( Expression ) Statement
  1. 返回 Statement 的 VarDeclaredNames。
SwitchStatement : switch ( Expression ) CaseBlock
  1. 返回 CaseBlock 的 VarDeclaredNames。
CaseBlock : { }
  1. 返回一个新的空 List。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. 如果第一个 CaseClauses 存在,则令 names1 为第一个 CaseClauses 的 VarDeclaredNames。
  2. 否则,令 names1 为一个新的空 List。
  3. 令 names2 为 DefaultClause 的 VarDeclaredNames。
  4. 如果第二个 CaseClauses 存在,则令 names3 为第二个 CaseClauses 的 VarDeclaredNames。
  5. 否则,令 names3 为一个新的空 List。
  6. 返回 names1、names2 和 names3 的列表连接。
CaseClauses : CaseClauses CaseClause
  1. 令 names1 为 CaseClauses 的 VarDeclaredNames。
  2. 令 names2 为 CaseClause 的 VarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
CaseClause : case Expression : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 的 VarDeclaredNames。
  2. 返回一个新的空 List。
DefaultClause : default : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 的 VarDeclaredNames。
  2. 返回一个新的空 List。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 返回 LabelledItem 的 VarDeclaredNames。
LabelledItem : FunctionDeclaration
  1. 返回一个新的空 List。
TryStatement : try Block Catch
  1. 令 names1 为 Block 的 VarDeclaredNames。
  2. 令 names2 为 Catch 的 VarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
TryStatement : try Block Finally
  1. 令 names1 为 Block 的 VarDeclaredNames。
  2. 令 names2 为 Finally 的 VarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
TryStatement : try Block Catch Finally
  1. 令 names1 为 Block 的 VarDeclaredNames。
  2. 令 names2 为 Catch 的 VarDeclaredNames。
  3. 令 names3 为 Finally 的 VarDeclaredNames。
  4. 返回 names1、names2 和 names3 的列表连接。
Catch : catch ( CatchParameter ) Block
  1. 返回 Block 的 VarDeclaredNames。
FunctionStatementList : [empty]
  1. 返回一个新的空 List。
FunctionStatementList : StatementList
  1. 返回 StatementList 的 TopLevelVarDeclaredNames。
ClassStaticBlockStatementList : [empty]
  1. 返回一个新的空 List。
ClassStaticBlockStatementList : StatementList
  1. 返回 StatementList 的 TopLevelVarDeclaredNames。
ConciseBody : ExpressionBody
  1. 返回一个新的空 List。
AsyncConciseBody : ExpressionBody
  1. 返回一个新的空 List。
Script : [empty]
  1. 返回一个新的空 List。
ScriptBody : StatementList
  1. 返回 StatementList 的 TopLevelVarDeclaredNames。
ModuleItemList : ModuleItemList ModuleItem
  1. 令 names1 为 ModuleItemList 的 VarDeclaredNames。
  2. 令 names2 为 ModuleItem 的 VarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
ModuleItem : ImportDeclaration
  1. 返回一个新的空 List。
ModuleItem : ExportDeclaration
  1. 如果 ExportDeclaration 是 export VariableStatement,则返回 ExportDeclaration 的 BoundNames。
  2. 返回一个新的空 List。

8.2.9 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. 返回一个新的空 List。
Block : { }
  1. 返回一个新的空 List。
StatementList : StatementList StatementListItem
  1. 令 decls1 为 StatementList 的 VarScopedDeclarations。
  2. 令 decls2 为 StatementListItem 的 VarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
StatementListItem : Declaration
  1. 返回一个新的空 List。
VariableDeclarationList : VariableDeclaration
  1. 返回 « VariableDeclaration »。
VariableDeclarationList : VariableDeclarationList , VariableDeclaration
  1. 令 decls1 为 VariableDeclarationList 的 VarScopedDeclarations。
  2. 返回 decls1 与 « VariableDeclaration » 的列表连接。
IfStatement : if ( Expression ) Statement else Statement
  1. 令 decls1 为第一个 Statement 的 VarScopedDeclarations。
  2. 令 decls2 为第二个 Statement 的 VarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
IfStatement : if ( Expression ) Statement
  1. 返回 Statement 的 VarScopedDeclarations。
DoWhileStatement : do Statement while ( Expression ) ;
  1. 返回 Statement 的 VarScopedDeclarations。
WhileStatement : while ( Expression ) Statement
  1. 返回 Statement 的 VarScopedDeclarations。
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement
  1. 返回 Statement 的 VarScopedDeclarations。
ForStatement : for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement
  1. 令 decls1 为 VariableDeclarationList 的 VarScopedDeclarations。
  2. 令 decls2 为 Statement 的 VarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
ForStatement : for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. 返回 Statement 的 VarScopedDeclarations。
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. 返回 Statement 的 VarScopedDeclarations。
ForInOfStatement : for ( var ForBinding in Expression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement
  1. 令 decls1 为 « ForBinding »。
  2. 令 decls2 为 Statement 的 VarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
Note

本节由附录 B.3.5 扩展。

WithStatement : with ( Expression ) Statement
  1. 返回 Statement 的 VarScopedDeclarations。
SwitchStatement : switch ( Expression ) CaseBlock
  1. 返回 CaseBlock 的 VarScopedDeclarations。
CaseBlock : { }
  1. 返回一个新的空 List。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. 如果第一个 CaseClauses 存在,则令 decls1 为第一个 CaseClauses 的 VarScopedDeclarations。
  2. 否则,令 decls1 为一个新的空 List。
  3. 令 decls2 为 DefaultClause 的 VarScopedDeclarations。
  4. 如果第二个 CaseClauses 存在,则令 decls3 为第二个 CaseClauses 的 VarScopedDeclarations。
  5. 否则,令 decls3 为一个新的空 List。
  6. 返回 decls1、decls2 和 decls3 的列表连接。
CaseClauses : CaseClauses CaseClause
  1. 令 decls1 为 CaseClauses 的 VarScopedDeclarations。
  2. 令 decls2 为 CaseClause 的 VarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
CaseClause : case Expression : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 的 VarScopedDeclarations。
  2. 返回一个新的空 List。
DefaultClause : default : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 的 VarScopedDeclarations。
  2. 返回一个新的空 List。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 返回 LabelledItem 的 VarScopedDeclarations。
LabelledItem : FunctionDeclaration
  1. 返回一个新的空 List。
TryStatement : try Block Catch
  1. 令 decls1 为 Block 的 VarScopedDeclarations。
  2. 令 decls2 为 Catch 的 VarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
TryStatement : try Block Finally
  1. 令 decls1 为 Block 的 VarScopedDeclarations。
  2. 令 decls2 为 Finally 的 VarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
TryStatement : try Block Catch Finally
  1. 令 decls1 为 Block 的 VarScopedDeclarations。
  2. 令 decls2 为 Catch 的 VarScopedDeclarations。
  3. 令 decls3 为 Finally 的 VarScopedDeclarations。
  4. 返回 decls1、decls2 和 decls3 的列表连接。
Catch : catch ( CatchParameter ) Block
  1. 返回 Block 的 VarScopedDeclarations。
FunctionStatementList : [empty]
  1. 返回一个新的空 List。
FunctionStatementList : StatementList
  1. 返回 StatementList 的 TopLevelVarScopedDeclarations。
ClassStaticBlockStatementList : [empty]
  1. 返回一个新的空 List。
ClassStaticBlockStatementList : StatementList
  1. 返回 StatementList 的 TopLevelVarScopedDeclarations。
ConciseBody : ExpressionBody
  1. 返回一个新的空 List。
AsyncConciseBody : ExpressionBody
  1. 返回一个新的空 List。
Script : [empty]
  1. 返回一个新的空 List。
ScriptBody : StatementList
  1. 返回 StatementList 的 TopLevelVarScopedDeclarations。
Module : [empty]
  1. 返回一个新的空 List。
ModuleItemList : ModuleItemList ModuleItem
  1. 令 decls1 为 ModuleItemList 的 VarScopedDeclarations。
  2. 令 decls2 为 ModuleItem 的 VarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
ModuleItem : ImportDeclaration
  1. 返回一个新的空 List。
ModuleItem : ExportDeclaration
  1. 如果 ExportDeclaration 是 export VariableStatement,则返回 VariableStatement 的 VarScopedDeclarations。
  2. 返回一个新的空 List。

8.2.10 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. 令 names1 为 StatementList 的 TopLevelLexicallyDeclaredNames。
  2. 令 names2 为 StatementListItem 的 TopLevelLexicallyDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
StatementListItem : Statement
  1. 返回一个新的空 List。
StatementListItem : Declaration
  1. 如果 Declaration 是 Declaration : HoistableDeclaration ,则
    1. 返回一个新的空 List。
  2. 返回 Declaration 的 BoundNames。
Note

在函数或脚本的顶层,函数声明会被像 var 声明一样处理,而不是像词法声明一样处理。

8.2.11 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. 令 decls1 为 StatementList 的 TopLevelLexicallyScopedDeclarations。
  2. 令 decls2 为 StatementListItem 的 TopLevelLexicallyScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
StatementListItem : Statement
  1. 返回一个新的空 List。
StatementListItem : Declaration
  1. 如果 Declaration 是 Declaration : HoistableDeclaration ,则
    1. 返回一个新的空 List。
  2. 返回 « Declaration »。

8.2.12 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. 令 names1 为 StatementList 的 TopLevelVarDeclaredNames。
  2. 令 names2 为 StatementListItem 的 TopLevelVarDeclaredNames。
  3. 返回 names1 和 names2 的列表连接。
StatementListItem : Declaration
  1. 如果 Declaration 是 Declaration : HoistableDeclaration ,则
    1. 返回 HoistableDeclaration 的 BoundNames。
  2. 返回一个新的空 List。
StatementListItem : Statement
  1. 如果 Statement 是 Statement : LabelledStatement ,则返回 Statement 的 TopLevelVarDeclaredNames。
  2. 返回 Statement 的 VarDeclaredNames。
Note

在函数或脚本的顶层,内部函数声明会被像 var 声明一样处理。

LabelledStatement : LabelIdentifier : LabelledItem
  1. 返回 LabelledItem 的 TopLevelVarDeclaredNames。
LabelledItem : Statement
  1. 如果 Statement 是 Statement : LabelledStatement ,则返回 Statement 的 TopLevelVarDeclaredNames。
  2. 返回 Statement 的 VarDeclaredNames。
LabelledItem : FunctionDeclaration
  1. 返回 FunctionDeclaration 的 BoundNames。

8.2.13 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. 令 decls1 为 StatementList 的 TopLevelVarScopedDeclarations。
  2. 令 decls2 为 StatementListItem 的 TopLevelVarScopedDeclarations。
  3. 返回 decls1 和 decls2 的列表连接。
StatementListItem : Statement
  1. 如果 Statement 是 Statement : LabelledStatement ,则返回 Statement 的 TopLevelVarScopedDeclarations。
  2. 返回 Statement 的 VarScopedDeclarations。
StatementListItem : Declaration
  1. 如果 Declaration 是 Declaration : HoistableDeclaration ,则
    1. 令 decl 为 HoistableDeclaration 的 DeclarationPart。
    2. 返回 « decl »。
  2. 返回一个新的空 List。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 返回 LabelledItem 的 TopLevelVarScopedDeclarations。
LabelledItem : Statement
  1. 如果 Statement 是 Statement : LabelledStatement ,则返回 Statement 的 TopLevelVarScopedDeclarations。
  2. 返回 Statement 的 VarScopedDeclarations。
LabelledItem : FunctionDeclaration
  1. 返回 « FunctionDeclaration »。

8.3 标签

8.3.1 Static Semantics: ContainsDuplicateLabels

The syntax-directed operation ContainsDuplicateLabels takes argument labelSet (a List of Strings) and returns a Boolean. It is defined piecewise over the following productions:

Statement : VariableStatement EmptyStatement ExpressionStatement ContinueStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement Block : { } StatementListItem : Declaration
  1. 返回 false。
StatementList : StatementList StatementListItem
  1. 令 hasDuplicates 为 StatementList 带实参 labelSet 的 ContainsDuplicateLabels。
  2. 如果 hasDuplicates 是 true,则返回 true。
  3. 返回 StatementListItem 带实参 labelSet 的 ContainsDuplicateLabels。
IfStatement : if ( Expression ) Statement else Statement
  1. 令 hasDuplicate 为第一个 Statement 带实参 labelSet 的 ContainsDuplicateLabels。
  2. 如果 hasDuplicate 是 true,则返回 true。
  3. 返回第二个 Statement 带实参 labelSet 的 ContainsDuplicateLabels。
IfStatement : if ( Expression ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsDuplicateLabels。
DoWhileStatement : do Statement while ( Expression ) ;
  1. 返回 Statement 带实参 labelSet 的 ContainsDuplicateLabels。
WhileStatement : while ( Expression ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsDuplicateLabels。
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsDuplicateLabels。
ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( var ForBinding in Expression ) Statement for ( ForDeclaration in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsDuplicateLabels。
Note

本节由附录 B.3.5 扩展。

WithStatement : with ( Expression ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsDuplicateLabels。
SwitchStatement : switch ( Expression ) CaseBlock
  1. 返回 CaseBlock 带实参 labelSet 的 ContainsDuplicateLabels。
CaseBlock : { }
  1. 返回 false。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. 如果第一个 CaseClauses 存在,则
    1. 如果第一个 CaseClauses 带实参 labelSet 的 ContainsDuplicateLabels 是 true,则返回 true。
  2. 如果 DefaultClause 带实参 labelSet 的 ContainsDuplicateLabels 是 true,则返回 true。
  3. 如果第二个 CaseClauses 不存在,则返回 false。
  4. 返回第二个 CaseClauses 带实参 labelSet 的 ContainsDuplicateLabels。
CaseClauses : CaseClauses CaseClause
  1. 令 hasDuplicates 为 CaseClauses 带实参 labelSet 的 ContainsDuplicateLabels。
  2. 如果 hasDuplicates 是 true,则返回 true。
  3. 返回 CaseClause 带实参 labelSet 的 ContainsDuplicateLabels。
CaseClause : case Expression : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 带实参 labelSet 的 ContainsDuplicateLabels。
  2. 返回 false。
DefaultClause : default : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 带实参 labelSet 的 ContainsDuplicateLabels。
  2. 返回 false。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 令 label 为 LabelIdentifier 的 StringValue。
  2. 如果 labelSet 包含 label,则返回 true。
  3. 令 newLabelSet 为 labelSet 与 « label » 的列表连接。
  4. 返回 LabelledItem 带实参 newLabelSet 的 ContainsDuplicateLabels。
LabelledItem : FunctionDeclaration
  1. 返回 false。
TryStatement : try Block Catch
  1. 令 hasDuplicates 为 Block 带实参 labelSet 的 ContainsDuplicateLabels。
  2. 如果 hasDuplicates 是 true,则返回 true。
  3. 返回 Catch 带实参 labelSet 的 ContainsDuplicateLabels。
TryStatement : try Block Finally
  1. 令 hasDuplicates 为 Block 带实参 labelSet 的 ContainsDuplicateLabels。
  2. 如果 hasDuplicates 是 true,则返回 true。
  3. 返回 Finally 带实参 labelSet 的 ContainsDuplicateLabels。
TryStatement : try Block Catch Finally
  1. 如果 Block 带实参 labelSet 的 ContainsDuplicateLabels 是 true,则返回 true。
  2. 如果 Catch 带实参 labelSet 的 ContainsDuplicateLabels 是 true,则返回 true。
  3. 返回 Finally 带实参 labelSet 的 ContainsDuplicateLabels。
Catch : catch ( CatchParameter ) Block
  1. 返回 Block 带实参 labelSet 的 ContainsDuplicateLabels。
FunctionStatementList : [empty]
  1. 返回 false。
ClassStaticBlockStatementList : [empty]
  1. 返回 false。
ModuleItemList : ModuleItemList ModuleItem
  1. 令 hasDuplicates 为 ModuleItemList 带实参 labelSet 的 ContainsDuplicateLabels。
  2. 如果 hasDuplicates 是 true,则返回 true。
  3. 返回 ModuleItem 带实参 labelSet 的 ContainsDuplicateLabels。
ModuleItem : ImportDeclaration ExportDeclaration
  1. 返回 false。

8.3.2 Static Semantics: ContainsUndefinedBreakTarget

The syntax-directed operation ContainsUndefinedBreakTarget takes argument labelSet (a List of Strings) and returns a Boolean. It is defined piecewise over the following productions:

Statement : VariableStatement EmptyStatement ExpressionStatement ContinueStatement ReturnStatement ThrowStatement DebuggerStatement Block : { } StatementListItem : Declaration
  1. 返回 false。
StatementList : StatementList StatementListItem
  1. 令 hasUndefinedLabels 为 StatementList 带实参 labelSet 的 ContainsUndefinedBreakTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 StatementListItem 带实参 labelSet 的 ContainsUndefinedBreakTarget。
IfStatement : if ( Expression ) Statement else Statement
  1. 令 hasUndefinedLabels 为第一个 Statement 带实参 labelSet 的 ContainsUndefinedBreakTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回第二个 Statement 带实参 labelSet 的 ContainsUndefinedBreakTarget。
IfStatement : if ( Expression ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsUndefinedBreakTarget。
DoWhileStatement : do Statement while ( Expression ) ;
  1. 返回 Statement 带实参 labelSet 的 ContainsUndefinedBreakTarget。
WhileStatement : while ( Expression ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsUndefinedBreakTarget。
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsUndefinedBreakTarget。
ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( var ForBinding in Expression ) Statement for ( ForDeclaration in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsUndefinedBreakTarget。
Note

本节由附录 B.3.5 扩展。

BreakStatement : break ;
  1. 返回 false。
BreakStatement : break LabelIdentifier ;
  1. 如果 labelSet 包含 LabelIdentifier 的 StringValue,则返回 false。
  2. 返回 true。
WithStatement : with ( Expression ) Statement
  1. 返回 Statement 带实参 labelSet 的 ContainsUndefinedBreakTarget。
SwitchStatement : switch ( Expression ) CaseBlock
  1. 返回 CaseBlock 带实参 labelSet 的 ContainsUndefinedBreakTarget。
CaseBlock : { }
  1. 返回 false。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. 如果第一个 CaseClauses 存在,则
    1. 如果第一个 CaseClauses 带实参 labelSet 的 ContainsUndefinedBreakTarget 是 true,则返回 true。
  2. 如果 DefaultClause 带实参 labelSet 的 ContainsUndefinedBreakTarget 是 true,则返回 true。
  3. 如果第二个 CaseClauses 不存在,则返回 false。
  4. 返回第二个 CaseClauses 带实参 labelSet 的 ContainsUndefinedBreakTarget。
CaseClauses : CaseClauses CaseClause
  1. 令 hasUndefinedLabels 为 CaseClauses 带实参 labelSet 的 ContainsUndefinedBreakTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 CaseClause 带实参 labelSet 的 ContainsUndefinedBreakTarget。
CaseClause : case Expression : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 带实参 labelSet 的 ContainsUndefinedBreakTarget。
  2. 返回 false。
DefaultClause : default : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 带实参 labelSet 的 ContainsUndefinedBreakTarget。
  2. 返回 false。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 令 label 为 LabelIdentifier 的 StringValue。
  2. 令 newLabelSet 为 labelSet 与 « label » 的列表连接。
  3. 返回 LabelledItem 带实参 newLabelSet 的 ContainsUndefinedBreakTarget。
LabelledItem : FunctionDeclaration
  1. 返回 false。
TryStatement : try Block Catch
  1. 令 hasUndefinedLabels 为 Block 带实参 labelSet 的 ContainsUndefinedBreakTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 Catch 带实参 labelSet 的 ContainsUndefinedBreakTarget。
TryStatement : try Block Finally
  1. 令 hasUndefinedLabels 为 Block 带实参 labelSet 的 ContainsUndefinedBreakTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 Finally 带实参 labelSet 的 ContainsUndefinedBreakTarget。
TryStatement : try Block Catch Finally
  1. 如果 Block 带实参 labelSet 的 ContainsUndefinedBreakTarget 是 true,则返回 true。
  2. 如果 Catch 带实参 labelSet 的 ContainsUndefinedBreakTarget 是 true,则返回 true。
  3. 返回 Finally 带实参 labelSet 的 ContainsUndefinedBreakTarget。
Catch : catch ( CatchParameter ) Block
  1. 返回 Block 带实参 labelSet 的 ContainsUndefinedBreakTarget。
FunctionStatementList : [empty]
  1. 返回 false。
ClassStaticBlockStatementList : [empty]
  1. 返回 false。
ModuleItemList : ModuleItemList ModuleItem
  1. 令 hasUndefinedLabels 为 ModuleItemList 带实参 labelSet 的 ContainsUndefinedBreakTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 ModuleItem 带实参 labelSet 的 ContainsUndefinedBreakTarget。
ModuleItem : ImportDeclaration ExportDeclaration
  1. 返回 false。

8.3.3 Static Semantics: ContainsUndefinedContinueTarget

The syntax-directed operation ContainsUndefinedContinueTarget takes arguments iterationSet (a List of Strings) and labelSet (a List of Strings) and returns a Boolean. It is defined piecewise over the following productions:

Statement : VariableStatement EmptyStatement ExpressionStatement BreakStatement ReturnStatement ThrowStatement DebuggerStatement Block : { } StatementListItem : Declaration
  1. 返回 false。
Statement : BlockStatement
  1. 返回 BlockStatement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
BreakableStatement : IterationStatement
  1. 令 newIterationSet 为 iterationSet 和 labelSet 的列表连接。
  2. 返回 IterationStatement 带实参 newIterationSet 和 « » 的 ContainsUndefinedContinueTarget。
StatementList : StatementList StatementListItem
  1. 令 hasUndefinedLabels 为 StatementList 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 StatementListItem 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
IfStatement : if ( Expression ) Statement else Statement
  1. 令 hasUndefinedLabels 为第一个 Statement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回第二个 Statement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
IfStatement : if ( Expression ) Statement
  1. 返回 Statement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
DoWhileStatement : do Statement while ( Expression ) ;
  1. 返回 Statement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
WhileStatement : while ( Expression ) Statement
  1. 返回 Statement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
ForStatement : for ( Expressionopt ; Expressionopt ; Expressionopt ) Statement for ( var VariableDeclarationList ; Expressionopt ; Expressionopt ) Statement for ( LexicalDeclaration Expressionopt ; Expressionopt ) Statement
  1. 返回 Statement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
ForInOfStatement : for ( LeftHandSideExpression in Expression ) Statement for ( var ForBinding in Expression ) Statement for ( ForDeclaration in Expression ) Statement for ( LeftHandSideExpression of AssignmentExpression ) Statement for ( var ForBinding of AssignmentExpression ) Statement for ( ForDeclaration of AssignmentExpression ) Statement for await ( LeftHandSideExpression of AssignmentExpression ) Statement for await ( var ForBinding of AssignmentExpression ) Statement for await ( ForDeclaration of AssignmentExpression ) Statement
  1. 返回 Statement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
Note

本节由附录 B.3.5 扩展。

ContinueStatement : continue ;
  1. 返回 false。
ContinueStatement : continue LabelIdentifier ;
  1. 如果 iterationSet 包含 LabelIdentifier 的 StringValue,则返回 false。
  2. 返回 true。
WithStatement : with ( Expression ) Statement
  1. 返回 Statement 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
SwitchStatement : switch ( Expression ) CaseBlock
  1. 返回 CaseBlock 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
CaseBlock : { }
  1. 返回 false。
CaseBlock : { CaseClausesopt DefaultClause CaseClausesopt }
  1. 如果第一个 CaseClauses 存在,则
    1. 如果第一个 CaseClauses 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget 是 true,则返回 true。
  2. 如果 DefaultClause 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget 是 true,则返回 true。
  3. 如果第二个 CaseClauses 不存在,则返回 false。
  4. 返回第二个 CaseClauses 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
CaseClauses : CaseClauses CaseClause
  1. 令 hasUndefinedLabels 为 CaseClauses 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 CaseClause 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
CaseClause : case Expression : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
  2. 返回 false。
DefaultClause : default : StatementListopt
  1. 如果 StatementList 存在,则返回 StatementList 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
  2. 返回 false。
LabelledStatement : LabelIdentifier : LabelledItem
  1. 令 label 为 LabelIdentifier 的 StringValue。
  2. 令 newLabelSet 为 labelSet 与 « label » 的列表连接。
  3. 返回 LabelledItem 带实参 iterationSet 和 newLabelSet 的 ContainsUndefinedContinueTarget。
LabelledItem : FunctionDeclaration
  1. 返回 false。
TryStatement : try Block Catch
  1. 令 hasUndefinedLabels 为 Block 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 Catch 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
TryStatement : try Block Finally
  1. 令 hasUndefinedLabels 为 Block 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 Finally 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
TryStatement : try Block Catch Finally
  1. 如果 Block 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget 是 true,则返回 true。
  2. 如果 Catch 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget 是 true,则返回 true。
  3. 返回 Finally 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
Catch : catch ( CatchParameter ) Block
  1. 返回 Block 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
FunctionStatementList : [empty]
  1. 返回 false。
ClassStaticBlockStatementList : [empty]
  1. 返回 false。
ModuleItemList : ModuleItemList ModuleItem
  1. 令 hasUndefinedLabels 为 ModuleItemList 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
  2. 如果 hasUndefinedLabels 是 true,则返回 true。
  3. 返回 ModuleItem 带实参 iterationSet 和 « » 的 ContainsUndefinedContinueTarget。
ModuleItem : ImportDeclaration ExportDeclaration
  1. 返回 false。

8.4 函数名称推断

8.4.1 Static Semantics: HasName

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

PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. 令 expr 为 CoverParenthesizedExpressionAndArrowParameterList 所覆盖的 ParenthesizedExpression。
  2. 如果 expr 的 IsFunctionDefinition 是 false,则返回 false。
  3. 返回 expr 的 HasName。
FunctionExpression : function ( FormalParameters ) { FunctionBody } GeneratorExpression : function * ( FormalParameters ) { GeneratorBody } AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody } ArrowFunction : ArrowParameters => ConciseBody AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody ClassExpression : class ClassTail
  1. 返回 false。
FunctionExpression : function BindingIdentifier ( FormalParameters ) { FunctionBody } GeneratorExpression : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionExpression : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } ClassExpression : class BindingIdentifier ClassTail
  1. 返回 true。

8.4.2 Static Semantics: IsFunctionDefinition

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

PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. 令 expr 为 CoverParenthesizedExpressionAndArrowParameterList 所覆盖的 ParenthesizedExpression。
  2. 返回 expr 的 IsFunctionDefinition。
PrimaryExpression : this IdentifierReference Literal ArrayLiteral ObjectLiteral RegularExpressionLiteral TemplateLiteral MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName MemberExpression TemplateLiteral SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier NewExpression : new NewExpression LeftHandSideExpression : CallExpression OptionalExpression UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- ++ UnaryExpression -- UnaryExpression UnaryExpression : delete UnaryExpression void UnaryExpression typeof UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression CoverAwaitExpressionAndAwaitUsingDeclarationHead ExponentiationExpression : UpdateExpression ** ExponentiationExpression MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression AdditiveExpression : AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression ShiftExpression : ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression RelationalExpression : RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression PrivateIdentifier in ShiftExpression EqualityExpression : EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression BitwiseANDExpression : BitwiseANDExpression & EqualityExpression BitwiseXORExpression : BitwiseXORExpression ^ BitwiseANDExpression BitwiseORExpression : BitwiseORExpression | BitwiseXORExpression LogicalANDExpression : LogicalANDExpression && BitwiseORExpression LogicalORExpression : LogicalORExpression || LogicalANDExpression CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression AssignmentExpression : YieldExpression LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpression LeftHandSideExpression &&= AssignmentExpression LeftHandSideExpression ||= AssignmentExpression LeftHandSideExpression ??= AssignmentExpression Expression : Expression , AssignmentExpression
  1. 返回 false。
AssignmentExpression : ArrowFunction AsyncArrowFunction FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody } ClassExpression : class BindingIdentifieropt ClassTail
  1. 返回 true。

8.4.3 Static Semantics: IsAnonymousFunctionDefinition ( expr )

The abstract operation IsAnonymousFunctionDefinition takes argument expr (an AssignmentExpression Parse Node, an Initializer Parse Node, or an Expression Parse Node) and returns a Boolean. 它确定其实参是否为不绑定名称的函数定义。 It performs the following steps when called:

  1. 如果 expr 的 IsFunctionDefinition 是 false,则返回 false。
  2. 令 hasName 为 expr 的 HasName。
  3. 如果 hasName 是 true,则返回 false。
  4. 返回 true。

8.4.4 Static Semantics: IsIdentifierRef

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

PrimaryExpression : IdentifierReference
  1. 返回 true。
PrimaryExpression : this Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral CoverParenthesizedExpressionAndArrowParameterList MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName MemberExpression TemplateLiteral SuperProperty MetaProperty new MemberExpression Arguments MemberExpression . PrivateIdentifier NewExpression : new NewExpression LeftHandSideExpression : CallExpression OptionalExpression
  1. 返回 false。

8.4.5 Runtime Semantics: NamedEvaluation

The syntax-directed operation NamedEvaluation takes argument name (a property key or a Private Name) and returns either a normal completion containing a function object or an abrupt completion. It is defined piecewise over the following productions:

PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. 令 expr 为 CoverParenthesizedExpressionAndArrowParameterList 所覆盖的 ParenthesizedExpression。
  2. 返回 ? expr 带实参 name 的 NamedEvaluation。
ParenthesizedExpression : ( Expression )
  1. 断言:IsAnonymousFunctionDefinition(Expression) 是 true。
  2. 返回 ? Expression 带实参 name 的 NamedEvaluation。
FunctionExpression : function ( FormalParameters ) { FunctionBody }
  1. 返回 FunctionExpression 带实参 name 的 InstantiateOrdinaryFunctionExpression。
GeneratorExpression : function * ( FormalParameters ) { GeneratorBody }
  1. 返回 GeneratorExpression 带实参 name 的 InstantiateGeneratorFunctionExpression。
AsyncGeneratorExpression : async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. 返回 AsyncGeneratorExpression 带实参 name 的 InstantiateAsyncGeneratorFunctionExpression。
AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
  1. 返回 AsyncFunctionExpression 带实参 name 的 InstantiateAsyncFunctionExpression。
ArrowFunction : ArrowParameters => ConciseBody
  1. 返回 ArrowFunction 带实参 name 的 InstantiateArrowFunctionExpression。
AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. 返回 AsyncArrowFunction 带实参 name 的 InstantiateAsyncArrowFunctionExpression。
ClassExpression : class ClassTail
  1. 令 sourceText 为 ClassExpression 所匹配的源文本。
  2. 返回 ? ClassTail 带实参 undefined、name 和 sourceText 的 ClassDefinitionEvaluation。

8.5 Contains

8.5.1 Static Semantics: Contains

The syntax-directed operation Contains takes argument symbol (a grammar symbol) and returns a Boolean.

本规范中未在下方列出的每个文法产生式替代项,都隐式具有以下 Contains 的默认定义:

  1. 对此 Parse Node 的每个子节点 child,执行:
    1. 如果 child 是 symbol 的实例,则返回 true。
    2. 如果 child 是非终结符的实例,则
      1. 令 contained 为 child Contains symbol 的结果。
      2. 如果 contained 是 true,则返回 true。
  2. 返回 false。
FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody } FunctionExpression : function BindingIdentifieropt ( FormalParameters ) { FunctionBody } GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody } GeneratorExpression : function * BindingIdentifieropt ( FormalParameters ) { GeneratorBody } AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody } AsyncGeneratorExpression : async function * BindingIdentifieropt ( FormalParameters ) { AsyncGeneratorBody } AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody } AsyncFunctionExpression : async function BindingIdentifieropt ( FormalParameters ) { AsyncFunctionBody }
  1. 返回 false。
Note 1

依赖子结构的静态语义规则通常不会查看函数定义内部。

ClassTail : ClassHeritageopt { ClassBody }
  1. 如果 symbol 是 ClassBody,则返回 true。
  2. 如果 symbol 是 ClassHeritage,则
    1. 如果 ClassHeritage 存在,则返回 true。
    2. 返回 false。
  3. 如果 ClassHeritage 存在,则
    1. 如果 ClassHeritage Contains symbol 是 true,则返回 true。
  4. 返回 ClassBody 带实参 symbol 的 ComputedPropertyContains 的结果。
Note 2

依赖子结构的静态语义规则通常不会查看类体内部,除 PropertyName 外。

ClassStaticBlock : static { ClassStaticBlockBody }
  1. 返回 false。
Note 3

依赖子结构的静态语义规则通常不会查看 static 初始化块内部。

ArrowFunction : ArrowParameters => ConciseBody
  1. 如果 symbol 不是 NewTarget、SuperProperty、SuperCall、super 或 this 之一,则返回 false。
  2. 如果 ArrowParameters Contains symbol 是 true,则返回 true。
  3. 返回 ConciseBody Contains symbol。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. 令 formals 为 CoverParenthesizedExpressionAndArrowParameterList 所覆盖的 ArrowFormalParameters。
  2. 返回 formals Contains symbol。
AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. 如果 symbol 不是 NewTarget、SuperProperty、SuperCall、super 或 this 之一,则返回 false。
  2. 返回 AsyncConciseBody Contains symbol。
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. 如果 symbol 不是 NewTarget、SuperProperty、SuperCall、super 或 this 之一,则返回 false。
  2. 令 head 为 CoverCallExpressionAndAsyncArrowHead 所覆盖的 AsyncArrowHead。
  3. 如果 head Contains symbol 是 true,则返回 true。
  4. 返回 AsyncConciseBody Contains symbol。
Note 4

Contains 用于检测 ArrowFunction 或 AsyncArrowFunction 中的 new.target、this 和 super 用法。

PropertyDefinition : MethodDefinition
  1. 如果 symbol 是 MethodDefinition,则返回 true。
  2. 返回 MethodDefinition 带实参 symbol 的 ComputedPropertyContains 的结果。
LiteralPropertyName : IdentifierName
  1. 返回 false。
MemberExpression : MemberExpression . IdentifierName
  1. 如果 MemberExpression Contains symbol 是 true,则返回 true。
  2. 返回 false。
SuperProperty : super . IdentifierName
  1. 如果 symbol 是 ReservedWord super,则返回 true。
  2. 返回 false。
CallExpression : CallExpression . IdentifierName
  1. 如果 CallExpression Contains symbol 是 true,则返回 true。
  2. 返回 false。
OptionalChain : ?. IdentifierName
  1. 返回 false。
OptionalChain : OptionalChain . IdentifierName
  1. 如果 OptionalChain Contains symbol 是 true,则返回 true。
  2. 返回 false。

8.5.2 Static Semantics: ComputedPropertyContains

The syntax-directed operation ComputedPropertyContains takes argument symbol (a grammar symbol) and returns a Boolean. It is defined piecewise over the following productions:

ClassElementName : PrivateIdentifier PropertyName : LiteralPropertyName
  1. 返回 false。
PropertyName : ComputedPropertyName
  1. 返回 ComputedPropertyName Contains symbol 的结果。
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 返回 ClassElementName 带实参 symbol 的 ComputedPropertyContains 的结果。
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. 返回 ClassElementName 带实参 symbol 的 ComputedPropertyContains 的结果。
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. 返回 ClassElementName 带实参 symbol 的 ComputedPropertyContains 的结果。
ClassElementList : ClassElementList ClassElement
  1. 令 inList 为 ClassElementList 带实参 symbol 的 ComputedPropertyContains。
  2. 如果 inList 是 true,则返回 true。
  3. 返回 ClassElement 带实参 symbol 的 ComputedPropertyContains 的结果。
ClassElement : ClassStaticBlock
  1. 返回 false。
ClassElement : ;
  1. 返回 false。
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. 返回 ClassElementName 带实参 symbol 的 ComputedPropertyContains 的结果。
FieldDefinition : ClassElementName Initializeropt
  1. 返回 ClassElementName 带实参 symbol 的 ComputedPropertyContains 的结果。

8.6 杂项

这些操作在整个规范的多个地方使用。

8.6.1 Runtime Semantics: InstantiateFunctionObject

The syntax-directed operation InstantiateFunctionObject takes arguments envRecord (an Environment Record) and privateEnv (a PrivateEnvironment Record or null) and returns an ECMAScript function object. It is defined piecewise over the following productions:

FunctionDeclaration : function BindingIdentifier ( FormalParameters ) { FunctionBody } function ( FormalParameters ) { FunctionBody }
  1. 返回 FunctionDeclaration 带实参 envRecord 和 privateEnv 的 InstantiateOrdinaryFunctionObject。
GeneratorDeclaration : function * BindingIdentifier ( FormalParameters ) { GeneratorBody } function * ( FormalParameters ) { GeneratorBody }
  1. 返回 GeneratorDeclaration 带实参 envRecord 和 privateEnv 的 InstantiateGeneratorFunctionObject。
AsyncGeneratorDeclaration : async function * BindingIdentifier ( FormalParameters ) { AsyncGeneratorBody } async function * ( FormalParameters ) { AsyncGeneratorBody }
  1. 返回 AsyncGeneratorDeclaration 带实参 envRecord 和 privateEnv 的 InstantiateAsyncGeneratorFunctionObject。
AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody } async function ( FormalParameters ) { AsyncFunctionBody }
  1. 返回 AsyncFunctionDeclaration 带实参 envRecord 和 privateEnv 的 InstantiateAsyncFunctionObject。

8.6.2 Runtime Semantics: BindingInitialization

The syntax-directed operation BindingInitialization takes arguments value (an ECMAScript language value) and envRecord (an Environment Record or undefined) and returns either a normal completion containing unused or an abrupt completion.

Note

为 envRecord 传递 undefined 表示应使用 PutValue 操作来赋予初始化值。这适用于 var 语句和某些非严格函数的形式参数列表(参见 10.2.11)。在这些情况下,词法绑定会在其初始化器求值之前被提升并预初始化。

It is defined piecewise over the following productions:

BindingIdentifier : Identifier
  1. 令 name 为 Identifier 的 StringValue。
  2. 返回 ? InitializeBoundName(name, value, envRecord)。
BindingIdentifier : yield
  1. 返回 ? InitializeBoundName("yield", value, envRecord)。
BindingIdentifier : await
  1. 返回 ? InitializeBoundName("await", value, envRecord)。
BindingPattern : ObjectBindingPattern
  1. 执行 ? RequireObjectCoercible(value)。
  2. 返回 ? ObjectBindingPattern 带实参 value 和 envRecord 的 BindingInitialization。
BindingPattern : ArrayBindingPattern
  1. 令 iteratorRecord 为 ? GetIterator(value, sync)。
  2. 令 result 为 Completion(ArrayBindingPattern 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization)。
  3. 如果 iteratorRecord.[[Done]] 是 false,则返回 ? IteratorClose(iteratorRecord, result)。
  4. 返回 ? result。
ObjectBindingPattern : { }
  1. 返回 unused。
ObjectBindingPattern : { BindingPropertyList } { BindingPropertyList , }
  1. 执行 ? BindingPropertyList 带实参 value 和 envRecord 的 PropertyBindingInitialization。
  2. 返回 unused。
ObjectBindingPattern : { BindingRestProperty }
  1. 令 excludedNames 为新的空 List。
  2. 返回 ? BindingRestProperty 带实参 value、envRecord 和 excludedNames 的 RestBindingInitialization。
ObjectBindingPattern : { BindingPropertyList , BindingRestProperty }
  1. 令 excludedNames 为 ? BindingPropertyList 带实参 value 和 envRecord 的 PropertyBindingInitialization。
  2. 返回 ? BindingRestProperty 带实参 value、envRecord 和 excludedNames 的 RestBindingInitialization。

8.6.2.1 InitializeBoundName ( name, value, envRecord )

The abstract operation InitializeBoundName takes arguments name (a String), value (an ECMAScript language value), and envRecord (an Environment Record or undefined) and returns either a normal completion containing unused or an abrupt completion. It performs the following steps when called:

  1. 如果 envRecord 不是 undefined,则
    1. 执行 ! envRecord.InitializeBinding(name, value)。
    2. 返回 unused。
  2. 令 lhs 为 ? ResolveBinding(name)。
  3. 返回 ? PutValue(lhs, value)。

8.6.3 Runtime Semantics: IteratorBindingInitialization

The syntax-directed operation IteratorBindingInitialization takes arguments iteratorRecord (an Iterator Record) and envRecord (an Environment Record or undefined) and returns either a normal completion containing unused or an abrupt completion.

Note

当为 envRecord 传递 undefined 时,表示应使用 PutValue 操作来赋予初始化值。这适用于非严格函数的形式参数列表。在这种情况下,为了处理可能存在多个同名参数的情形,形式参数绑定会被预初始化。

It is defined piecewise over the following productions:

ArrayBindingPattern : [ ]
  1. 返回 unused。
ArrayBindingPattern : [ Elision ]
  1. 返回 ? Elision 带实参 iteratorRecord 的 IteratorDestructuringAssignmentEvaluation。
ArrayBindingPattern : [ Elisionopt BindingRestElement ]
  1. 如果 Elision 存在,则
    1. 执行 ? Elision 带实参 iteratorRecord 的 IteratorDestructuringAssignmentEvaluation。
  2. 返回 ? BindingRestElement 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
ArrayBindingPattern : [ BindingElementList , Elision ]
  1. 执行 ? BindingElementList 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
  2. 返回 ? Elision 带实参 iteratorRecord 的 IteratorDestructuringAssignmentEvaluation。
ArrayBindingPattern : [ BindingElementList , Elisionopt BindingRestElement ]
  1. 执行 ? BindingElementList 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
  2. 如果 Elision 存在,则
    1. 执行 ? Elision 带实参 iteratorRecord 的 IteratorDestructuringAssignmentEvaluation。
  3. 返回 ? BindingRestElement 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
BindingElementList : BindingElementList , BindingElisionElement
  1. 执行 ? BindingElementList 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
  2. 返回 ? BindingElisionElement 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
BindingElisionElement : Elision BindingElement
  1. 执行 ? Elision 带实参 iteratorRecord 的 IteratorDestructuringAssignmentEvaluation。
  2. 返回 ? BindingElement 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
SingleNameBinding : BindingIdentifier Initializeropt
  1. 令 bindingId 为 BindingIdentifier 的 StringValue。
  2. 令 lhs 为 ? ResolveBinding(bindingId, envRecord)。
  3. 令 v 为 undefined。
  4. 如果 iteratorRecord.[[Done]] 是 false,则
    1. 令 next 为 ? IteratorStepValue(iteratorRecord)。
    2. 如果 next 不是 done,则
      1. 将 v 设置为 next。
  5. 如果 Initializer 存在且 v 是 undefined,则
    1. 如果 IsAnonymousFunctionDefinition(Initializer) 是 true,则
      1. 将 v 设置为 ? Initializer 带实参 bindingId 的 NamedEvaluation。
    2. 否则,
      1. 令 defaultValue 为 ? Initializer 的 Evaluation。
      2. 将 v 设置为 ? GetValue(defaultValue)。
  6. 如果 envRecord 是 undefined,则返回 ? PutValue(lhs, v)。
  7. 返回 ? InitializeReferencedBinding(lhs, v)。
BindingElement : BindingPattern Initializeropt
  1. 令 v 为 undefined。
  2. 如果 iteratorRecord.[[Done]] 是 false,则
    1. 令 next 为 ? IteratorStepValue(iteratorRecord)。
    2. 如果 next 不是 done,则
      1. 将 v 设置为 next。
  3. 如果 Initializer 存在且 v 是 undefined,则
    1. 令 defaultValue 为 ? Initializer 的 Evaluation。
    2. 将 v 设置为 ? GetValue(defaultValue)。
  4. 返回 ? BindingPattern 带实参 v 和 envRecord 的 BindingInitialization。
BindingRestElement : ... BindingIdentifier
  1. 令 lhs 为 ? ResolveBinding(BindingIdentifier 的 StringValue, envRecord)。
  2. 令 array 为 ! ArrayCreate(0)。
  3. 令 n 为 0。
  4. 重复,
    1. 令 next 为 done。
    2. 如果 iteratorRecord.[[Done]] 是 false,则
      1. 将 next 设置为 ? IteratorStepValue(iteratorRecord)。
    3. 如果 next 是 done,则
      1. 如果 envRecord 是 undefined,则返回 ? PutValue(lhs, array)。
      2. 返回 ? InitializeReferencedBinding(lhs, array)。
    4. 执行 ! CreateDataPropertyOrThrow(array, ! ToString(𝔽(n)), next)。
    5. 将 n 设置为 n + 1。
BindingRestElement : ... BindingPattern
  1. 令 array 为 ! ArrayCreate(0)。
  2. 令 n 为 0。
  3. 重复,
    1. 令 next 为 done。
    2. 如果 iteratorRecord.[[Done]] 是 false,则
      1. 将 next 设置为 ? IteratorStepValue(iteratorRecord)。
    3. 如果 next 是 done,则
      1. 返回 ? BindingPattern 带实参 array 和 envRecord 的 BindingInitialization。
    4. 执行 ! CreateDataPropertyOrThrow(array, ! ToString(𝔽(n)), next)。
    5. 将 n 设置为 n + 1。
FormalParameters : [empty]
  1. 返回 unused。
FormalParameters : FormalParameterList , FunctionRestParameter
  1. 执行 ? FormalParameterList 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
  2. 返回 ? FunctionRestParameter 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
FormalParameterList : FormalParameterList , FormalParameter
  1. 执行 ? FormalParameterList 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
  2. 返回 ? FormalParameter 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
ArrowParameters : BindingIdentifier
  1. 令 v 为 undefined。
  2. 断言:iteratorRecord.[[Done]] 是 false。
  3. 令 next 为 ? IteratorStepValue(iteratorRecord)。
  4. 如果 next 不是 done,则
    1. 将 v 设置为 next。
  5. 返回 ? BindingIdentifier 带实参 v 和 envRecord 的 BindingInitialization。
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. 令 formals 为 CoverParenthesizedExpressionAndArrowParameterList 所覆盖的 ArrowFormalParameters。
  2. 返回 ? formals 带实参 iteratorRecord 和 envRecord 的 IteratorBindingInitialization。
AsyncArrowBindingIdentifier : BindingIdentifier
  1. 令 v 为 undefined。
  2. 断言:iteratorRecord.[[Done]] 是 false。
  3. 令 next 为 ? IteratorStepValue(iteratorRecord)。
  4. 如果 next 不是 done,则
    1. 将 v 设置为 next。
  5. 返回 ? BindingIdentifier 带实参 v 和 envRecord 的 BindingInitialization。

8.6.4 Static Semantics: AssignmentTargetType

The syntax-directed operation AssignmentTargetType takes no arguments and returns simple, web-compat, or invalid. It is defined piecewise over the following productions:

IdentifierReference : Identifier
  1. 如果 IsStrict(this IdentifierReference) 是 true 且 Identifier 的 StringValue 是 "eval" 或 "arguments",则返回 invalid。
  2. 返回 simple。
IdentifierReference : yield await CallExpression : CallExpression [ Expression ] CallExpression . IdentifierName CallExpression . PrivateIdentifier MemberExpression : MemberExpression [ Expression ] MemberExpression . IdentifierName SuperProperty MemberExpression . PrivateIdentifier
  1. 返回 simple。
PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList
  1. 令 expr 为 CoverParenthesizedExpressionAndArrowParameterList 所覆盖的 ParenthesizedExpression。
  2. 返回 expr 的 AssignmentTargetType。
CallExpression : CoverCallExpressionAndAsyncArrowHead CallExpression Arguments
  1. 如果宿主是 Web 浏览器,或以其他方式支持 函数调用赋值目标的运行时错误,且 IsStrict(this CallExpression) 是 false,则
    1. 返回 web-compat。
  2. 返回 invalid。
PrimaryExpression : this Literal ArrayLiteral ObjectLiteral FunctionExpression ClassExpression GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression RegularExpressionLiteral TemplateLiteral CallExpression : SuperCall ImportCall CallExpression TemplateLiteral NewExpression : new NewExpression MemberExpression : MemberExpression TemplateLiteral new MemberExpression Arguments NewTarget : new . target ImportMeta : import . meta LeftHandSideExpression : OptionalExpression UpdateExpression : LeftHandSideExpression ++ LeftHandSideExpression -- ++ UnaryExpression -- UnaryExpression UnaryExpression : delete UnaryExpression void UnaryExpression typeof UnaryExpression + UnaryExpression - UnaryExpression ~ UnaryExpression ! UnaryExpression CoverAwaitExpressionAndAwaitUsingDeclarationHead ExponentiationExpression : UpdateExpression ** ExponentiationExpression MultiplicativeExpression : MultiplicativeExpression MultiplicativeOperator ExponentiationExpression AdditiveExpression : AdditiveExpression + MultiplicativeExpression AdditiveExpression - MultiplicativeExpression ShiftExpression : ShiftExpression << AdditiveExpression ShiftExpression >> AdditiveExpression ShiftExpression >>> AdditiveExpression RelationalExpression : RelationalExpression < ShiftExpression RelationalExpression > ShiftExpression RelationalExpression <= ShiftExpression RelationalExpression >= ShiftExpression RelationalExpression instanceof ShiftExpression RelationalExpression in ShiftExpression PrivateIdentifier in ShiftExpression EqualityExpression : EqualityExpression == RelationalExpression EqualityExpression != RelationalExpression EqualityExpression === RelationalExpression EqualityExpression !== RelationalExpression BitwiseANDExpression : BitwiseANDExpression & EqualityExpression BitwiseXORExpression : BitwiseXORExpression ^ BitwiseANDExpression BitwiseORExpression : BitwiseORExpression | BitwiseXORExpression LogicalANDExpression : LogicalANDExpression && BitwiseORExpression LogicalORExpression : LogicalORExpression || LogicalANDExpression CoalesceExpression : CoalesceExpressionHead ?? BitwiseORExpression ConditionalExpression : ShortCircuitExpression ? AssignmentExpression : AssignmentExpression AssignmentExpression : YieldExpression ArrowFunction AsyncArrowFunction LeftHandSideExpression = AssignmentExpression LeftHandSideExpression AssignmentOperator AssignmentExpression LeftHandSideExpression &&= AssignmentExpression LeftHandSideExpression ||= AssignmentExpression LeftHandSideExpression ??= AssignmentExpression Expression : Expression , AssignmentExpression
  1. 返回 invalid。

8.6.5 Static Semantics: PropName

The syntax-directed operation PropName takes no arguments and returns a String or empty. It is defined piecewise over the following productions:

PropertyDefinition : IdentifierReference
  1. 返回 IdentifierReference 的 StringValue。
PropertyDefinition : ... AssignmentExpression
  1. 返回 empty。
PropertyDefinition : PropertyName : AssignmentExpression
  1. 返回 PropertyName 的 PropName。
LiteralPropertyName : IdentifierName AttributeKey : IdentifierName
  1. 返回 IdentifierName 的 StringValue。
LiteralPropertyName : StringLiteral AttributeKey : StringLiteral
  1. 返回 StringLiteral 的 SV。
LiteralPropertyName : NumericLiteral
  1. 令 number 为 NumericLiteral 的 NumericValue。
  2. 返回 ! ToString(number)。
ComputedPropertyName : [ AssignmentExpression ]
  1. 返回 empty。
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. 返回 ClassElementName 的 PropName。
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. 返回 ClassElementName 的 PropName。
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. 返回 ClassElementName 的 PropName。
ClassElement : ClassStaticBlock
  1. 返回 empty。
ClassElement : ;
  1. 返回 empty。
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. 返回 ClassElementName 的 PropName。
FieldDefinition : ClassElementName Initializeropt
  1. 返回 ClassElementName 的 PropName。
ClassElementName : PrivateIdentifier
  1. 返回 empty。

8.6.6 Static Semantics: ContainsUsing

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

StatementList : StatementList StatementListItem
  1. 如果派生的 StatementList 的 ContainsUsing 是 true,则返回 true。
  2. 如果 StatementListItem 的 ContainsUsing 是 true,则返回 true。
  3. 返回 false。
StatementListItem : Statement
  1. 返回 false。
StatementListItem : Declaration
  1. 如果 Declaration 的 IsUsingDeclaration 是 true,则返回 true。
  2. 如果 Declaration 的 IsAwaitUsingDeclaration 是 true,则返回 true。
  3. 返回 false。