13.3 Left-Hand-Side Expressions
Syntax
Supplemental Syntax
When processing an instance of the production
the interpretation of
13.3.1 Static Semantics
13.3.1.1 Static Semantics: Early Errors
- It is a Syntax Error if any source text is matched by this production.
This production exists in order to prevent automatic semicolon insertion rules (
a?.b
`c`
so that it would be interpreted as two valid statements. The purpose is to maintain consistency with similar code without optional chaining:
a.b
`c`
which is a valid statement and where automatic semicolon insertion does not apply.
-
It is a Syntax Error if the syntactic
goal symbol is notModule .
13.3.2 Property Accessors
Properties are accessed by name, using either the dot notation:
or the bracket notation:
The dot notation is explained by the following syntactic conversion:
is identical in its behaviour to
and similarly
is identical in its behaviour to
where <identifier-name-string> is the result of evaluating
13.3.2.1 Runtime Semantics: Evaluation
- Let baseReference be ?
Evaluation ofMemberExpression . - Let baseValue be ?
GetValue (baseReference). - If the
source text matched by thisMemberExpression isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- Let baseReference be ?
Evaluation ofMemberExpression . - Let baseValue be ?
GetValue (baseReference). - If the
source text matched by thisMemberExpression isstrict mode code , let strict betrue ; else let strict befalse . - Return
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
- Let baseReference be ?
Evaluation ofMemberExpression . - Let baseValue be ?
GetValue (baseReference). - Let fieldNameString be the
StringValue ofPrivateIdentifier . - Return
MakePrivateReference (baseValue, fieldNameString).
- Let baseReference be ?
Evaluation ofCallExpression . - Let baseValue be ?
GetValue (baseReference). - If the
source text matched by thisCallExpression isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- Let baseReference be ?
Evaluation ofCallExpression . - Let baseValue be ?
GetValue (baseReference). - If the
source text matched by thisCallExpression isstrict mode code , let strict betrue ; else let strict befalse . - Return
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
- Let baseReference be ?
Evaluation ofCallExpression . - Let baseValue be ?
GetValue (baseReference). - Let fieldNameString be the
StringValue ofPrivateIdentifier . - Return
MakePrivateReference (baseValue, fieldNameString).
13.3.3 EvaluatePropertyAccessWithExpressionKey ( baseValue, expression, strict )
The abstract operation EvaluatePropertyAccessWithExpressionKey takes arguments baseValue (an
- Let propertyNameReference be ?
Evaluation of expression. - Let propertyNameValue be ?
GetValue (propertyNameReference). - Let propertyKey be ?
ToPropertyKey (propertyNameValue). - Return the
Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]:empty }.
13.3.4 EvaluatePropertyAccessWithIdentifierKey ( baseValue, identifierName, strict )
The abstract operation EvaluatePropertyAccessWithIdentifierKey takes arguments baseValue (an
- Let propertyNameString be
StringValue of identifierName. - Return the
Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyNameString, [[Strict]]: strict, [[ThisValue]]:empty }.
13.3.5 The new
Operator
13.3.5.1 Runtime Semantics: Evaluation
- Return ?
EvaluateNew (NewExpression ,empty ).
- Return ?
EvaluateNew (MemberExpression ,Arguments ).
13.3.5.1.1 EvaluateNew ( constructExpr, arguments )
The abstract operation EvaluateNew takes arguments constructExpr (a
- Let ref be ?
Evaluation of constructExpr. - Let constructor be ?
GetValue (ref). - If arguments is
empty , then- Let argList be a new empty
List .
- Let argList be a new empty
- Else,
- Let argList be ?
ArgumentListEvaluation of arguments.
- Let argList be ?
- If
IsConstructor (constructor) isfalse , throw aTypeError exception. - Return ?
Construct (constructor, argList).
13.3.6 Function Calls
13.3.6.1 Runtime Semantics: Evaluation
- Let expr be the
CallMemberExpression that iscovered byCoverCallExpressionAndAsyncArrowHead . - Let memberExpr be the
MemberExpression of expr. - Let arguments be the
Arguments of expr. - Let ref be ?
Evaluation of memberExpr. - Let func be ?
GetValue (ref). - If ref is a
Reference Record ,IsPropertyReference (ref) isfalse , and ref.[[ReferencedName]] is"eval" , then- If
SameValue (func,%eval% ) istrue , then- Let argList be ?
ArgumentListEvaluation of arguments. - If argList has no elements, return
undefined . - Let evalArg be the first element of argList.
- If the
source text matched by thisCallExpression isstrict mode code , let strictCaller betrue . Otherwise let strictCaller befalse . - Return ?
PerformEval (evalArg, strictCaller,true ).
- Let argList be ?
- If
- Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (func, ref, arguments, tailCall).
A
- Let ref be ?
Evaluation ofCallExpression . - Let func be ?
GetValue (ref). - Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (func, ref,Arguments , tailCall).
13.3.6.2 EvaluateCall ( func, ref, arguments, tailPosition )
The abstract operation EvaluateCall takes arguments func (an
- If ref is a
Reference Record , then- If
IsPropertyReference (ref) istrue , then- Let thisValue be
GetThisValue (ref).
- Let thisValue be
- Else,
- Let refEnv be ref.[[Base]].
Assert : refEnv is anEnvironment Record .- Let thisValue be refEnv.WithBaseObject().
- If
- Else,
- Let thisValue be
undefined .
- Let thisValue be
- Let argList be ?
ArgumentListEvaluation of arguments. - If func
is not an Object , throw aTypeError exception. - If
IsCallable (func) isfalse , throw aTypeError exception. - If tailPosition is
true , performPrepareForTailCall (). - Return ?
Call (func, thisValue, argList).
13.3.7 The super
Keyword
13.3.7.1 Runtime Semantics: Evaluation
- Let env be
GetThisEnvironment (). - Let actualThis be ? env.GetThisBinding().
- Let propertyNameReference be ?
Evaluation ofExpression . - Let propertyNameValue be ?
GetValue (propertyNameReference). - Let propertyKey be ?
ToPropertyKey (propertyNameValue). - If the
source text matched by thisSuperProperty isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
MakeSuperPropertyReference (actualThis, propertyKey, strict).
- Let env be
GetThisEnvironment (). - Let actualThis be ? env.GetThisBinding().
- Let propertyKey be
StringValue ofIdentifierName . - If the
source text matched by thisSuperProperty isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
MakeSuperPropertyReference (actualThis, propertyKey, strict).
- Let newTarget be
GetNewTarget (). Assert : newTargetis an Object .- Let func be
GetSuperConstructor (). - Let argList be ?
ArgumentListEvaluation ofArguments . - If
IsConstructor (func) isfalse , throw aTypeError exception. - Let result be ?
Construct (func, argList, newTarget). - Let thisER be
GetThisEnvironment (). - Perform ? thisER.BindThisValue(result).
- Let F be thisER.[[FunctionObject]].
Assert : F is an ECMAScriptfunction object .- Perform ?
InitializeInstanceElements (result, F). - Return result.
13.3.7.2 GetSuperConstructor ( )
The abstract operation GetSuperConstructor takes no arguments and returns an
- Let envRec be
GetThisEnvironment (). Assert : envRec is aFunction Environment Record .- Let activeFunction be envRec.[[FunctionObject]].
Assert : activeFunction is an ECMAScriptfunction object .- Let superConstructor be ! activeFunction.[[GetPrototypeOf]]().
- Return superConstructor.
13.3.7.3 MakeSuperPropertyReference ( actualThis, propertyKey, strict )
The abstract operation MakeSuperPropertyReference takes arguments actualThis (an
- Let env be
GetThisEnvironment (). Assert : env.HasSuperBinding() istrue .- Let baseValue be ? env.GetSuperBase().
- Return the
Reference Record { [[Base]]: baseValue, [[ReferencedName]]: propertyKey, [[Strict]]: strict, [[ThisValue]]: actualThis }.
13.3.8 Argument Lists
The evaluation of an argument list produces a
13.3.8.1 Runtime Semantics: ArgumentListEvaluation
The
- Return a new empty
List .
- Let ref be ?
Evaluation ofAssignmentExpression . - Let arg be ?
GetValue (ref). - Return « arg ».
- Let list be a new empty
List . - Let spreadRef be ?
Evaluation ofAssignmentExpression . - Let spreadObj be ?
GetValue (spreadRef). - Let iteratorRecord be ?
GetIterator (spreadObj,sync ). - Repeat,
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , return list. - Append next to list.
- Let next be ?
- Let precedingArgs be ?
ArgumentListEvaluation ofArgumentList . - Let ref be ?
Evaluation ofAssignmentExpression . - Let arg be ?
GetValue (ref). - Return the
list-concatenation of precedingArgs and « arg ».
- Let precedingArgs be ?
ArgumentListEvaluation ofArgumentList . - Let spreadRef be ?
Evaluation ofAssignmentExpression . - Let iteratorRecord be ?
GetIterator (?GetValue (spreadRef),sync ). - Repeat,
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , return precedingArgs. - Append next to precedingArgs.
- Let next be ?
- Let templateLiteral be this
TemplateLiteral . - Let siteObj be
GetTemplateObject (templateLiteral). - Return « siteObj ».
- Let templateLiteral be this
TemplateLiteral . - Let siteObj be
GetTemplateObject (templateLiteral). - Let remaining be ?
ArgumentListEvaluation ofSubstitutionTemplate . - Return the
list-concatenation of « siteObj » and remaining.
- Let firstSubRef be ?
Evaluation ofExpression . - Let firstSub be ?
GetValue (firstSubRef). - Let restSub be ?
SubstitutionEvaluation ofTemplateSpans . Assert : restSub is a possibly emptyList .- Return the
list-concatenation of « firstSub » and restSub.
13.3.9 Optional Chains
?.
.13.3.9.1 Runtime Semantics: Evaluation
- Let baseReference be ?
Evaluation ofMemberExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is either
undefined ornull , then- Return
undefined .
- Return
- Return ?
ChainEvaluation ofOptionalChain with arguments baseValue and baseReference.
- Let baseReference be ?
Evaluation ofCallExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is either
undefined ornull , then- Return
undefined .
- Return
- Return ?
ChainEvaluation ofOptionalChain with arguments baseValue and baseReference.
- Let baseReference be ?
Evaluation ofOptionalExpression . - Let baseValue be ?
GetValue (baseReference). - If baseValue is either
undefined ornull , then- Return
undefined .
- Return
- Return ?
ChainEvaluation ofOptionalChain with arguments baseValue and baseReference.
13.3.9.2 Runtime Semantics: ChainEvaluation
The
- Let thisChain be this
OptionalChain . - Let tailCall be
IsInTailPosition (thisChain). - Return ?
EvaluateCall (baseValue, baseReference,Arguments , tailCall).
- If the
source text matched by thisOptionalChain isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithExpressionKey (baseValue,Expression , strict).
- If the
source text matched by thisOptionalChain isstrict mode code , let strict betrue ; else let strict befalse . - Return
EvaluatePropertyAccessWithIdentifierKey (baseValue,IdentifierName , strict).
- Let fieldNameString be the
StringValue ofPrivateIdentifier . - Return
MakePrivateReference (baseValue, fieldNameString).
- Let optionalChain be
OptionalChain . - Let newReference be ?
ChainEvaluation of optionalChain with arguments baseValue and baseReference. - Let newValue be ?
GetValue (newReference). - Let thisChain be this
OptionalChain . - Let tailCall be
IsInTailPosition (thisChain). - Return ?
EvaluateCall (newValue, newReference,Arguments , tailCall).
- Let optionalChain be
OptionalChain . - Let newReference be ?
ChainEvaluation of optionalChain with arguments baseValue and baseReference. - Let newValue be ?
GetValue (newReference). - If the
source text matched by thisOptionalChain isstrict mode code , let strict betrue ; else let strict befalse . - Return ?
EvaluatePropertyAccessWithExpressionKey (newValue,Expression , strict).
- Let optionalChain be
OptionalChain . - Let newReference be ?
ChainEvaluation of optionalChain with arguments baseValue and baseReference. - Let newValue be ?
GetValue (newReference). - If the
source text matched by thisOptionalChain isstrict mode code , let strict betrue ; else let strict befalse . - Return
EvaluatePropertyAccessWithIdentifierKey (newValue,IdentifierName , strict).
- Let optionalChain be
OptionalChain . - Let newReference be ?
ChainEvaluation of optionalChain with arguments baseValue and baseReference. - Let newValue be ?
GetValue (newReference). - Let fieldNameString be the
StringValue ofPrivateIdentifier . - Return
MakePrivateReference (newValue, fieldNameString).
13.3.10 Import Calls
13.3.10.1 Runtime Semantics: Evaluation
- Let referrer be
GetActiveScriptOrModule (). - If referrer is
null , set referrer tothe current Realm Record . - Let argRef be ?
Evaluation ofAssignmentExpression . - Let specifier be ?
GetValue (argRef). - Let promiseCapability be !
NewPromiseCapability (%Promise% ). - Let specifierString be
Completion (ToString (specifier)). IfAbruptRejectPromise (specifierString, promiseCapability).- Perform
HostLoadImportedModule (referrer, specifierString,empty , promiseCapability). - Return promiseCapability.[[Promise]].
13.3.10.1.1 ContinueDynamicImport ( promiseCapability, moduleCompletion )
The abstract operation ContinueDynamicImport takes arguments promiseCapability (a import()
- If moduleCompletion is an
abrupt completion , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « moduleCompletion.[[Value]] »). - Return
unused .
- Perform !
- Let module be moduleCompletion.[[Value]].
- Let loadPromise be module.LoadRequestedModules().
- Let rejectedClosure be a new
Abstract Closure with parameters (reason) that captures promiseCapability and performs the following steps when called:- Perform !
Call (promiseCapability.[[Reject]],undefined , « reason »). - Return
unused .
- Perform !
- Let onRejected be
CreateBuiltinFunction (rejectedClosure, 1,"" , « »). - Let linkAndEvaluateClosure be a new
Abstract Closure with no parameters that captures module, promiseCapability, and onRejected and performs the following steps when called:- Let link be
Completion (module.Link()). - If link is an
abrupt completion , then- Perform !
Call (promiseCapability.[[Reject]],undefined , « link.[[Value]] »). - Return
unused .
- Perform !
- Let evaluatePromise be module.Evaluate().
- Let fulfilledClosure be a new
Abstract Closure with no parameters that captures module and promiseCapability and performs the following steps when called:- Let namespace be
GetModuleNamespace (module). - Perform !
Call (promiseCapability.[[Resolve]],undefined , « namespace »). - Return
unused .
- Let namespace be
- Let onFulfilled be
CreateBuiltinFunction (fulfilledClosure, 0,"" , « »). - Perform
PerformPromiseThen (evaluatePromise, onFulfilled, onRejected). - Return
unused .
- Let link be
- Let linkAndEvaluate be
CreateBuiltinFunction (linkAndEvaluateClosure, 0,"" , « »). - Perform
PerformPromiseThen (loadPromise, linkAndEvaluate, onRejected). - Return
unused .
13.3.11 Tagged Templates
A tagged template is a function call where the arguments of the call are derived from a
13.3.11.1 Runtime Semantics: Evaluation
- Let tagRef be ?
Evaluation ofMemberExpression . - Let tagFunc be ?
GetValue (tagRef). - Let thisCall be this
MemberExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (tagFunc, tagRef,TemplateLiteral , tailCall).
- Let tagRef be ?
Evaluation ofCallExpression . - Let tagFunc be ?
GetValue (tagRef). - Let thisCall be this
CallExpression . - Let tailCall be
IsInTailPosition (thisCall). - Return ?
EvaluateCall (tagFunc, tagRef,TemplateLiteral , tailCall).
13.3.12 Meta Properties
13.3.12.1 Runtime Semantics: Evaluation
- Return
GetNewTarget ().
- Let module be
GetActiveScriptOrModule (). Assert : module is aSource Text Module Record .- Let importMeta be module.[[ImportMeta]].
- If importMeta is
empty , then- Set importMeta to
OrdinaryObjectCreate (null ). - Let importMetaValues be
HostGetImportMetaProperties (module). - For each
Record { [[Key]], [[Value]] } p of importMetaValues, do- Perform !
CreateDataPropertyOrThrow (importMeta, p.[[Key]], p.[[Value]]).
- Perform !
- Perform
HostFinalizeImportMeta (importMeta, module). - Set module.[[ImportMeta]] to importMeta.
- Return importMeta.
- Set importMeta to
- Else,
Assert : importMetais an Object .- Return importMeta.
13.3.12.1.1 HostGetImportMetaProperties ( moduleRecord )
The import.meta
.
The default implementation of HostGetImportMetaProperties is to return a new empty
13.3.12.1.2 HostFinalizeImportMeta ( importMeta, moduleRecord )
The import.meta
.
Most
The default implementation of HostFinalizeImportMeta is to return