This is the spec text proposal for introducing Optional Chaining feature (aka Null Propagation, aka Existential Operator) 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).
Modified content are marked like this. In order to avoid distraction, we don’t mark mere editorial amendments.
A major rewrite is in progress, that will eliminate the need of Nil reference. The observed behaviour will change in edge or rare cases only.
The Reference type is used to explain the behaviour of such operators as delete
, typeof
, the assignment operators, the super
keyword and other language features. For example, the left-hand operand of an assignment is expected to produce a reference.
A Reference is a resolved name or property binding. A Reference consists of three components, the base value component, the referenced name component, and the Boolean-valued strict reference flag. The base value component is either
A Super Reference is a Reference that is used to represents a name binding that was expressed using the super keyword. A
A Nil Reference is a special Reference that is used to propagate an ?.
). A
The following abstract operations are used in this specification to operate on references:
The object that may be created in step 5.a.ii is not accessible outside of the above abstract operation and the ordinary object [[Get]] internal method. An implementation might choose to avoid the actual creation of the object.
The object that may be created in step 6.a.ii is not accessible outside of the above algorithm and the ordinary object [[Set]] internal method. An implementation might choose to avoid the actual creation of that object.
delete
OperatorIt is a Syntax Error if the derived
and
The last rule means that expressions such as delete (((foo)))
produce early errors because of recursive application of the first rule.
When a delete
operator occurs within delete
operator occurs within
When processing an instance of the production
the interpretation of
this
Keyword(not modified)
(not modified)
(not modified)
(not modified)
(not modified)
(not modified)
(not modified)
(not modified)
This algorithm does not apply delete
and typeof
may be applied to parenthesized expressions.
When processing an instance of the production
With parameter symbol.
super
, return 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 StringValue of
Is evaluated in exactly the same manner as
Is evaluated in exactly the same manner as
Is evaluated in exactly the same manner as
Is evaluated in exactly the same manner as
new
OperatorThe abstract operation EvaluateNew with arguments constructExpr, arguments, and optionalEvaluation performs the following steps:
"eval"
, thenA
Is evaluated in the same manner as
and the last step, which is replaced by:
The abstract operation EvaluateCall takes as arguments a value ref, a Parse Node arguments, a Boolean argument tailPosition, and a Boolean argument optionalEvaluation. It performs the following steps:
The abstract operation EvaluateDirectCall takes as arguments a value func, a value thisValue, a Parse Node arguments, a Boolean argument tailPosition, and a Boolean argument optionalEvaluation. It performs the following steps:
super
Keyword(not modified)
(not modified)
A tagged template is a function call where the arguments of the call are derived from a
(not modified)