Verify that property name can be bound to in short-hand object pattern properties

Issue #221
This commit is contained in:
Marijn Haverbeke 2015-03-19 14:05:08 +01:00
parent a45172e044
commit 9673146cc1
2 changed files with 8 additions and 4 deletions

View File

@ -2492,12 +2492,10 @@
if (this.options.ecmaVersion >= 6) { if (this.options.ecmaVersion >= 6) {
prop.method = false; prop.method = false;
prop.shorthand = false; prop.shorthand = false;
if (isPattern || refShorthandDefaultPos) { if (isPattern || refShorthandDefaultPos)
start = this.currentPos(); start = this.currentPos();
} if (!isPattern)
if (!isPattern) {
isGenerator = this.eat(tt.star); isGenerator = this.eat(tt.star);
}
} }
this.parsePropertyName(prop); this.parsePropertyName(prop);
if (this.eat(tt.colon)) { if (this.eat(tt.colon)) {
@ -2518,6 +2516,10 @@
} else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") { } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
prop.kind = "init"; prop.kind = "init";
if (isPattern) { 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); prop.value = this.parseMaybeDefault(start, prop.key);
} else if (this.type === tt.eq && refShorthandDefaultPos) { } else if (this.type === tt.eq && refShorthandDefaultPos) {
if (!refShorthandDefaultPos.start) if (!refShorthandDefaultPos.start)

View File

@ -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("'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("[...eval] = arr", "Assigning to eval in strict mode (1:4)", {ecmaVersion: 6, sourceType: "module"});
testFail("function* y({yield}) {}", "Binding yield (1:13)", {ecmaVersion: 6});