Optional Chaining (original) (raw)
1 Scope
This is the spec text of the Optional Chaining proposal in ECMAScript.
For the syntax, we use the ?.
token, with a lookahead at the level of the lexical grammar that allows to discriminate between a?.b
(optional chaining) and a?.3:0
(conditional operator, whose meaning cannot be changed due to backward compatibility constraints).
An early version of this proposal used a Nil reference to express short-circuiting. This one is based on syntax only.
Normative additions are marked like this. In order to avoid distraction, we may omit mere editorial amendments.
List of significant editorial modifications:
- Property Accessors: Factoring part of the property access operations in the new EvaluateDynamicPropertyAccess and EvaluateStaticPropertyAccess abstract operations.
The following features may not be evident at a cursory read:
- Optional chaining is forbidden in write contexts such as
a?.b = c
. This is handled by defining properly the IsSimpleAssignmentTarget static semantics rule (). - Optional deletion as in:
delete a ?.b
is supported. There is no change needed in Section The delete Operator.