This repository has been archived by the owner on Jan 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
spec.html
182 lines (163 loc) · 7.66 KB
/
spec.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!doctype html>
<meta charset="utf8">
<pre class=metadata>
title: Nullish Coalescing Operator
stage: 4
contributors: Daniel Ehrenberg, Daniel Rosenwasser
</pre>
<emu-intro id=sec-intro>
<h1>Introduction</h1>
<p>This document specifies the nullish coalescing operator `??`. See <a href="https://github.com/tc39/proposal-nullish-coalescing">the explainer</a> for an introduction.</p>
<p>The main design decisions made in this specification are:
<ol>
<li>The right argument of `??` is evaluated only if needed ("short circuiting").</li>
<li>`??` has lower precedence than `||`.</li>
<li>`??` cannot immediately contain, or be contained within, an `&&` or `||` operation.</li>
<li>The right argument is selected if the left argument is `null` or `undefined`.</li>
</ol>
</p>
</emu-intro>
<emu-clause id="sec-binary-logical-operators">
<h1>Binary Logical Operators</h1>
<h2>Syntax</h2>
<emu-grammar type="definition">
<ins>
ShortCircuitExpression[In, Yield, Await] :
LogicalORExpression[?In, ?Yield, ?Await]
CoalesceExpression[?In, ?Yield, ?Await]
CoalesceExpression[In, Yield, Await] :
CoalesceExpressionHead[?In, ?Yield, ?Await] `??` BitwiseORExpression[?In, ?Yield, ?Await]
CoalesceExpressionHead[In, Yield, Await] :
CoalesceExpression[?In, ?Yield, ?Await]
BitwiseORExpression[?In, ?Yield, ?Await]
</ins>
</emu-grammar>
<emu-clause id="sec-binary-logical-operators-static-semantics-isfunctiondefinition">
<h1>Static Semantics: IsFunctionDefinition</h1>
<emu-see-also-para op="IsFunctionDefinition"></emu-see-also-para>
<emu-grammar>
LogicalANDExpression : LogicalANDExpression `&&` BitwiseORExpression
LogicalORExpression : LogicalORExpression `||` LogicalANDExpression
<ins>CoalesceExpression : CoalesceExpressionHead `??` BitwiseORExpression</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause oldids="sec-binary-logical-operators-static-semantics-isvalidsimpleassignmenttarget,sec-semantics-static-semantics-assignmenttargettype" id="sec-binary-logical-operators-static-semantics-issimpleassignmenttarget">
<h1>Static Semantics: IsSimpleAssignmentTarget</h1>
<emu-see-also-para op="IsSimpleAssignmentTarget"></emu-see-also-para>
<emu-grammar>
LogicalANDExpression : LogicalANDExpression `&&` BitwiseORExpression
LogicalORExpression : LogicalORExpression `||` LogicalANDExpression
<ins>CoalesceExpression : CoalesceExpressionHead `??` BitwiseORExpression</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-binary-logical-operators-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar><ins>CoalesceExpression : CoalesceExpressionHead `??` BitwiseORExpression</ins></emu-grammar>
<emu-alg>
1. <ins>Let _lref_ be the result of evaluating |CoalesceExpressionHead|.</ins>
1. <ins>Let _lval_ be ? GetValue(_lref_).</ins>
1. <ins>If _lval_ is *undefined* or *null*,</ins>
1. <ins>Let _rref_ be the result of evaluating |BitwiseORExpression|.</ins>
1. <ins>Return ? GetValue(_rref_).</ins>
1. <ins>Otherwise, return _lval_.</ins>
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-conditional-operator">
<h1>Conditional Operator ( `? :` )</h1>
<h2>Syntax</h2>
<emu-grammar type="definition">
ConditionalExpression[In, Yield, Await] :
<del>
LogicalORExpression[?In, ?Yield, ?Await]
LogicalORExpression[?In, ?Yield, ?Await] `?` AssignmentExpression[+In, ?Yield, ?Await] `:` AssignmentExpression[?In, ?Yield, ?Await]
</del>
<ins>
ShortCircuitExpression[?In, ?Yield, ?Await]
ShortCircuitExpression[?In, ?Yield, ?Await] `?` AssignmentExpression[+In, ?Yield, ?Await] `:` AssignmentExpression[+In, ?Yield, ?Await]
</ins>
</emu-grammar>
<emu-clause id="sec-conditional-operator-static-semantics-isfunctiondefinition">
<h1>Static Semantics: IsFunctionDefinition</h1>
<emu-see-also-para op="IsFunctionDefinition"></emu-see-also-para>
<emu-grammar>
<del>ConditionalExpression : LogicalORExpression `?` AssignmentExpression `:` AssignmentExpression</del>
<ins>ConditionalExpression : ShortCircuitExpression `?` AssignmentExpression `:` AssignmentExpression</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause oldids="sec-conditional-operator-static-semantics-isvalidsimpleassignmenttarget,sec-semantics-static-semantics-assignmenttargettype" id="sec-conditional-operator-static-semantics-issimpleassignmenttarget">
<h1>Static Semantics: IsSimpleAssignmentTarget</h1>
<emu-see-also-para op="IsSimpleAssignmentTarget"></emu-see-also-para>
<emu-grammar>
<del>ConditionalExpression : LogicalORExpression `?` AssignmentExpression `:` AssignmentExpression</del>
<ins>ConditionalExpression : ShortCircuitExpression `?` AssignmentExpression `:` AssignmentExpression</ins>
</emu-grammar>
<emu-alg>
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-conditional-operator-runtime-semantics-evaluation">
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>
<del>ConditionalExpression : LogicalORExpression `?` AssignmentExpression `:` AssignmentExpression</del>
<ins>ConditionalExpression : ShortCircuitExpression `?` AssignmentExpression `:` AssignmentExpression</ins>
</emu-grammar>
<emu-alg>
1. <del>Let _lref_ be the result of evaluating |LogicalORExpression|.</del>
1. <ins>Let _lref_ be the result of evaluating |ShortCircuitExpression|.</ins>
1. Let _lval_ be ToBoolean(? GetValue(_lref_)).
1. If _lval_ is *true*, then
1. Let _trueRef_ be the result of evaluating the first |AssignmentExpression|.
1. Return ? GetValue(_trueRef_).
1. Else,
1. Let _falseRef_ be the result of evaluating the second |AssignmentExpression|.
1. Return ? GetValue(_falseRef_).
</emu-alg>
</emu-clause>
</emu-clause>
<emu-clause id="sec-tail-position-calls">
<h1>Tail Position Calls</h1>
<emu-clause id="sec-static-semantics-hascallintailposition">
<h1>Static Semantics: HasCallInTailPosition</h1>
<p>With parameter _call_.</p>
<emu-clause id="sec-expression-rules">
<h1>Expression Rules</h1>
<emu-grammar>
<del>ConditionalExpression : LogicalORExpression `?` AssignmentExpression `:` AssignmentExpression</del>
<ins>ConditionalExpression : ShortCircuitExpression `?` AssignmentExpression `:` AssignmentExpression</ins>
</emu-grammar>
<emu-alg>
1. Let _has_ be HasCallInTailPosition of the first |AssignmentExpression| with argument _call_.
1. If _has_ is *true*, return *true*.
1. Return HasCallInTailPosition of the second |AssignmentExpression| with argument _call_.
</emu-alg>
<emu-grammar>LogicalANDExpression : LogicalANDExpression `&&` BitwiseORExpression</emu-grammar>
<emu-alg>
1. Return HasCallInTailPosition of |BitwiseORExpression| with argument _call_.
</emu-alg>
<emu-grammar>LogicalORExpression : LogicalORExpression `||` LogicalANDExpression</emu-grammar>
<emu-alg>
1. Return HasCallInTailPosition of |LogicalANDExpression| with argument _call_.
</emu-alg>
<emu-grammar>
<ins>
CoalesceExpression : CoalesceExpressionHead `??` BitwiseORExpression
</ins>
</emu-grammar>
<emu-alg>
<ins>
1. Return HasCallInTailPosition of |BitwiseORExpression| with argument _call_.
</ins>
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>