Skip to content

Commit 3565751

Browse files
committed
make constants
1 parent 637a0a2 commit 3565751

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

acorn/src/expression.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,15 @@ pp.parseMaybeConditional = function(noIn, refDestructuringErrors) {
165165

166166
// Start the precedence parser.
167167

168+
const BOTH_ALLOWED = 0
169+
const ONLY_LOGICAL = 1
170+
const ONLY_COALESCE = 2
171+
168172
pp.parseExprOps = function(noIn, refDestructuringErrors) {
169173
let startPos = this.start, startLoc = this.startLoc
170174
let expr = this.parseMaybeUnary(refDestructuringErrors, false)
171175
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)
173177
}
174178

175179
// Parse binary operators with the operator precedence parsing
@@ -178,20 +182,15 @@ pp.parseExprOps = function(noIn, refDestructuringErrors) {
178182
// defer further parser to one of its callers when it encounters an
179183
// operator that has a lower precedence than the set it is parsing.
180184

181-
// shortCircuitOps:
182-
// * 1 = only `||` and `&&` are allowed
183-
// * 2 = only `??` is allowed
184-
// * others = all
185-
186185
pp.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn, shortCircuitOps) {
187186
let prec = this.type.binop
188187
if (prec != null && (!noIn || this.type !== tt._in)) {
189188
let logical = this.type === tt.logicalOR || this.type === tt.logicalAND
190189
let coalesce = this.type === tt.coalesce
191-
if (shortCircuitOps === 1 && coalesce || shortCircuitOps === 2 && logical) {
190+
if (shortCircuitOps === ONLY_LOGICAL && coalesce || shortCircuitOps === ONLY_COALESCE && logical) {
192191
this.raiseRecoverable(this.start, "Logical expressions and coalesce expressions cannot be mixed. Wrap either by parentheses")
193192
}
194-
shortCircuitOps = shortCircuitOps || (logical ? 1 : coalesce ? 2 : 0)
193+
shortCircuitOps = shortCircuitOps || (logical ? ONLY_LOGICAL : coalesce ? ONLY_COALESCE : BOTH_ALLOWED)
195194

196195
if (prec > minPrec) {
197196
let op = this.value

0 commit comments

Comments
 (0)