Skip to content

Commit c2994ee

Browse files
committed
Disallow arrow functions to be the conditional in a ternary expr
FIX: Don't allow the conditional in a ternary expression to be a (naked) arrow function. Closes #1428
1 parent 610d62d commit c2994ee

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

acorn/src/expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pp.parseMaybeConditional = function(forInit, refDestructuringErrors) {
167167
let startPos = this.start, startLoc = this.startLoc
168168
let expr = this.parseExprOps(forInit, refDestructuringErrors)
169169
if (this.checkExpressionErrors(refDestructuringErrors)) return expr
170-
if (this.eat(tt.question)) {
170+
if (!(expr.type == "ArrowFunctionExpression" && expr.start == startPos) && this.eat(tt.question)) {
171171
let node = this.startNodeAt(startPos, startLoc)
172172
node.test = expr
173173
node.consequent = this.parseMaybeAssign()

test/tests-harmony.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,8 @@ test("foo((x, y) => {})", {
26372637
locations: true
26382638
});
26392639

2640+
testFail("() => {} ? 1 : 0", "Unexpected token (1:9)", {ecmaVersion: 6})
2641+
26402642
// ES6: Method Definition
26412643

26422644
test("x = { method() { } }", {

0 commit comments

Comments
 (0)