Skip to content

Commit

Permalink
Disallow yield as default parameters
Browse files Browse the repository at this point in the history
Applies to both arrow functions and any function in strict mode

Fixes acornjs#336
  • Loading branch information
nzakas authored and marijnh committed Nov 4, 2015
1 parent c9f83aa commit 63526c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lval.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pp.toAssignable = function(node, isBinding) {
case "Identifier":
case "ObjectPattern":
case "ArrayPattern":
case "AssignmentPattern":
break

case "ObjectExpression":
Expand All @@ -34,10 +33,16 @@ pp.toAssignable = function(node, isBinding) {
if (node.operator === "=") {
node.type = "AssignmentPattern"
delete node.operator
// falls through to AssignmentPattern
} else {
this.raise(node.left.end, "Only '=' operator can be used for specifying default value.")
break;
}
break

case "AssignmentPattern":
if (node.right.type === "YieldExpression")
this.raise(node.right.start, "Yield expression cannot be a default value")
break;

case "ParenthesizedExpression":
node.expression = this.toAssignable(node.expression, isBinding)
Expand Down
3 changes: 3 additions & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -5928,6 +5928,9 @@ test("(function* () { yield yield 10 })", {
locations: true
});

testFail("function *g() { (x = yield) => {} }", "Yield expression cannot be a default value (1:21)", { ecmaVersion: 6 })
testFail("function *g() { ({x = yield}) => {} }", "Yield expression cannot be a default value (1:22)", { ecmaVersion: 6 })

// Harmony: Iterators

test("for(x of list) process(x);", {
Expand Down

0 comments on commit 63526c7

Please sign in to comment.