Skip to content

Commit a7bd3cd

Browse files
authored
Reject an unparenthesized arrow function as the left operand of **
FIX: Reject uses of `**` with a non-parenthesized arrow function as left-hand side.
1 parent b7c31b6 commit a7bd3cd

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

acorn/src/expression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pp.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forInit)
269269
}
270270
}
271271

272-
if (!incDec && this.eat(tt.starstar)) {
272+
if (!incDec && !(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(tt.starstar)) {
273273
if (sawUnary)
274274
this.unexpected(this.lastTokStart)
275275
else

test/tests-es7.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,9 @@ testFail(
396396
testFail("'use strict'; function y(x = 1) { 'use strict' }",
397397
"Illegal 'use strict' directive in function with non-simple parameter list (1:14)",
398398
{ecmaVersion: 7})
399+
400+
// An unparenthesized arrow function cannot be the left operand of `**`:
401+
// its left operand must be an UpdateExpression, and an arrow function is an
402+
// AssignmentExpression, so `() => {} ** x` is a SyntaxError (matches V8).
403+
testFail("() => {} ** 2", "Unexpected token (1:9)", {ecmaVersion: 7})
404+
testFail("a => {} ** b", "Unexpected token (1:8)", {ecmaVersion: 7})

0 commit comments

Comments
 (0)