From 9673146cc1e8059c0d0b946ab9df4a46e541b11c Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 19 Mar 2015 14:05:08 +0100 Subject: [PATCH] Verify that property name can be bound to in short-hand object pattern properties Issue #221 --- acorn.js | 10 ++++++---- test/tests-harmony.js | 2 ++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/acorn.js b/acorn.js index 00402ed773..7caacb8377 100644 --- a/acorn.js +++ b/acorn.js @@ -2492,12 +2492,10 @@ if (this.options.ecmaVersion >= 6) { prop.method = false; prop.shorthand = false; - if (isPattern || refShorthandDefaultPos) { + if (isPattern || refShorthandDefaultPos) start = this.currentPos(); - } - if (!isPattern) { + if (!isPattern) isGenerator = this.eat(tt.star); - } } this.parsePropertyName(prop); if (this.eat(tt.colon)) { @@ -2518,6 +2516,10 @@ } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") { prop.kind = "init"; if (isPattern) { + if (this.isKeyword(prop.key.name) || + (this.strict && (isStrictBadIdWord(prop.key.name) || isStrictReservedWord(prop.key.name))) || + (!this.options.allowReserved && this.isReservedWord(prop.key.name))) + this.raise(prop.key.start, "Binding " + prop.key.name); prop.value = this.parseMaybeDefault(start, prop.key); } else if (this.type === tt.eq && refShorthandDefaultPos) { if (!refShorthandDefaultPos.start) diff --git a/test/tests-harmony.js b/test/tests-harmony.js index 15fcd92c1e..4f2480e12a 100644 --- a/test/tests-harmony.js +++ b/test/tests-harmony.js @@ -15508,3 +15508,5 @@ testFail("'use strict'; [...eval] = arr", "Assigning to eval in strict mode (1:1 testFail("'use strict'; ({eval = defValue} = obj)", "Assigning to eval in strict mode (1:16)", {ecmaVersion: 6}); testFail("[...eval] = arr", "Assigning to eval in strict mode (1:4)", {ecmaVersion: 6, sourceType: "module"}); + +testFail("function* y({yield}) {}", "Binding yield (1:13)", {ecmaVersion: 6});