@@ -165,11 +165,15 @@ pp.parseMaybeConditional = function(noIn, refDestructuringErrors) {
165
165
166
166
// Start the precedence parser.
167
167
168
+ const BOTH_ALLOWED = 0
169
+ const ONLY_LOGICAL = 1
170
+ const ONLY_COALESCE = 2
171
+
168
172
pp . parseExprOps = function ( noIn , refDestructuringErrors ) {
169
173
let startPos = this . start , startLoc = this . startLoc
170
174
let expr = this . parseMaybeUnary ( refDestructuringErrors , false )
171
175
if ( this . checkExpressionErrors ( refDestructuringErrors ) ) return expr
172
- return expr . start === startPos && expr . type === "ArrowFunctionExpression" ? expr : this . parseExprOp ( expr , startPos , startLoc , - 1 , noIn , 0 )
176
+ return expr . start === startPos && expr . type === "ArrowFunctionExpression" ? expr : this . parseExprOp ( expr , startPos , startLoc , - 1 , noIn , BOTH_ALLOWED )
173
177
}
174
178
175
179
// Parse binary operators with the operator precedence parsing
@@ -178,20 +182,15 @@ pp.parseExprOps = function(noIn, refDestructuringErrors) {
178
182
// defer further parser to one of its callers when it encounters an
179
183
// operator that has a lower precedence than the set it is parsing.
180
184
181
- // shortCircuitOps:
182
- // * 1 = only `||` and `&&` are allowed
183
- // * 2 = only `??` is allowed
184
- // * others = all
185
-
186
185
pp . parseExprOp = function ( left , leftStartPos , leftStartLoc , minPrec , noIn , shortCircuitOps ) {
187
186
let prec = this . type . binop
188
187
if ( prec != null && ( ! noIn || this . type !== tt . _in ) ) {
189
188
let logical = this . type === tt . logicalOR || this . type === tt . logicalAND
190
189
let coalesce = this . type === tt . coalesce
191
- if ( shortCircuitOps === 1 && coalesce || shortCircuitOps === 2 && logical ) {
190
+ if ( shortCircuitOps === ONLY_LOGICAL && coalesce || shortCircuitOps === ONLY_COALESCE && logical ) {
192
191
this . raiseRecoverable ( this . start , "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses" )
193
192
}
194
- shortCircuitOps = shortCircuitOps || ( logical ? 1 : coalesce ? 2 : 0 )
193
+ shortCircuitOps = shortCircuitOps || ( logical ? ONLY_LOGICAL : coalesce ? ONLY_COALESCE : BOTH_ALLOWED )
195
194
196
195
if ( prec > minPrec ) {
197
196
let op = this . value
0 commit comments