ECMAScript® 2024 Language Specification

Draft ECMA-262 / February 15, 2024

8.5 Contains

8.5.1 Static Semantics: Contains

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

Every grammar production alternative in this specification which is not listed below implicitly has the following default definition of Contains:

  1. For each child node child of this Parse Node, do
    1. If child is an instance of symbol, return true.
    2. If child is an instance of a nonterminal, then
      1. Let contained be the result of child Contains symbol.
      2. If contained is true, return true.
  2. Return 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. Return false.
Note 1

Static semantic rules that depend upon substructure generally do not look into function definitions.

ClassTail : ClassHeritageopt { ClassBody }
  1. If symbol is ClassBody, return true.
  2. If symbol is ClassHeritage, then
    1. If ClassHeritage is present, return true; otherwise return false.
  3. If ClassHeritage is present, then
    1. If ClassHeritage Contains symbol is true, return true.
  4. Return the result of ComputedPropertyContains of ClassBody with argument symbol.
Note 2

Static semantic rules that depend upon substructure generally do not look into class bodies except for PropertyNames.

ClassStaticBlock : static { ClassStaticBlockBody }
  1. Return false.
Note 3

Static semantic rules that depend upon substructure generally do not look into static initialization blocks.

ArrowFunction : ArrowParameters => ConciseBody
  1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super, or this, return false.
  2. If ArrowParameters Contains symbol is true, return true.
  3. Return ConciseBody Contains symbol.
ArrowParameters : CoverParenthesizedExpressionAndArrowParameterList
  1. Let formals be the ArrowFormalParameters that is covered by CoverParenthesizedExpressionAndArrowParameterList.
  2. Return formals Contains symbol.
AsyncArrowFunction : async AsyncArrowBindingIdentifier => AsyncConciseBody
  1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super, or this, return false.
  2. Return AsyncConciseBody Contains symbol.
AsyncArrowFunction : CoverCallExpressionAndAsyncArrowHead => AsyncConciseBody
  1. If symbol is not one of NewTarget, SuperProperty, SuperCall, super, or this, return false.
  2. Let head be the AsyncArrowHead that is covered by CoverCallExpressionAndAsyncArrowHead.
  3. If head Contains symbol is true, return true.
  4. Return AsyncConciseBody Contains symbol.
Note 4

Contains is used to detect new.target, this, and super usage within an ArrowFunction or AsyncArrowFunction.

PropertyDefinition : MethodDefinition
  1. If symbol is MethodDefinition, return true.
  2. Return the result of ComputedPropertyContains of MethodDefinition with argument symbol.
LiteralPropertyName : IdentifierName
  1. Return false.
MemberExpression : MemberExpression . IdentifierName
  1. If MemberExpression Contains symbol is true, return true.
  2. Return false.
SuperProperty : super . IdentifierName
  1. If symbol is the ReservedWord super, return true.
  2. Return false.
CallExpression : CallExpression . IdentifierName
  1. If CallExpression Contains symbol is true, return true.
  2. Return false.
OptionalChain : ?. IdentifierName
  1. Return false.
OptionalChain : OptionalChain . IdentifierName
  1. If OptionalChain Contains symbol is true, return true.
  2. Return 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. Return false.
PropertyName : ComputedPropertyName
  1. Return the result of ComputedPropertyName Contains symbol.
MethodDefinition : ClassElementName ( UniqueFormalParameters ) { FunctionBody } get ClassElementName ( ) { FunctionBody } set ClassElementName ( PropertySetParameterList ) { FunctionBody }
  1. Return the result of ComputedPropertyContains of ClassElementName with argument symbol.
GeneratorMethod : * ClassElementName ( UniqueFormalParameters ) { GeneratorBody }
  1. Return the result of ComputedPropertyContains of ClassElementName with argument symbol.
AsyncGeneratorMethod : async * ClassElementName ( UniqueFormalParameters ) { AsyncGeneratorBody }
  1. Return the result of ComputedPropertyContains of ClassElementName with argument symbol.
ClassElementList : ClassElementList ClassElement
  1. Let inList be ComputedPropertyContains of ClassElementList with argument symbol.
  2. If inList is true, return true.
  3. Return the result of ComputedPropertyContains of ClassElement with argument symbol.
ClassElement : ClassStaticBlock
  1. Return false.
ClassElement : ;
  1. Return false.
AsyncMethod : async ClassElementName ( UniqueFormalParameters ) { AsyncFunctionBody }
  1. Return the result of ComputedPropertyContains of ClassElementName with argument symbol.
FieldDefinition : ClassElementName Initializeropt
  1. Return the result of ComputedPropertyContains of ClassElementName with argument symbol.