disallow invalid async function forms inside object literals - fixes #2629

This commit is contained in:
Sebastian McKenzie 2015-11-02 08:00:01 +00:00
parent 7fabc4c83d
commit c2973d0c7a
5 changed files with 14 additions and 6 deletions

View File

@ -712,12 +712,7 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) {
};
pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos) {
if (this.eat(tt.colon)) {
prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos);
return this.finishNode(prop, "ObjectProperty");
}
if (this.match(tt.parenL)) {
if (isAsync || isGenerator || this.match(tt.parenL)) {
if (isPattern) this.unexpected();
prop.kind = "method";
prop.method = true;
@ -725,6 +720,11 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
return this.finishNode(prop, "ObjectMethod");
}
if (this.eat(tt.colon)) {
prop.value = isPattern ? this.parseMaybeDefault(this.state.start, this.state.startLoc) : this.parseMaybeAssign(false, refShorthandDefaultPos);
return this.finishNode(prop, "ObjectProperty");
}
if (!prop.computed && prop.key.type === "Identifier" && (prop.key.name === "get" || prop.key.name === "set") && (!this.match(tt.comma) && !this.match(tt.braceR))) {
if (isGenerator || isAsync || isPattern) this.unexpected();
prop.kind = prop.key.name;

View File

@ -0,0 +1 @@
({ async a });

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:11)"
}

View File

@ -0,0 +1 @@
({ async a: function () {} });

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:10)"
}