disallow invalid async function forms inside object literals - fixes #2629
This commit is contained in:
parent
7fabc4c83d
commit
c2973d0c7a
@ -712,12 +712,7 @@ pp.parseObj = function (isPattern, refShorthandDefaultPos) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos) {
|
pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync, isPattern, refShorthandDefaultPos) {
|
||||||
if (this.eat(tt.colon)) {
|
if (isAsync || isGenerator || this.match(tt.parenL)) {
|
||||||
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 (isPattern) this.unexpected();
|
if (isPattern) this.unexpected();
|
||||||
prop.kind = "method";
|
prop.kind = "method";
|
||||||
prop.method = true;
|
prop.method = true;
|
||||||
@ -725,6 +720,11 @@ pp.parseObjPropValue = function (prop, startPos, startLoc, isGenerator, isAsync,
|
|||||||
return this.finishNode(prop, "ObjectMethod");
|
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 (!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();
|
if (isGenerator || isAsync || isPattern) this.unexpected();
|
||||||
prop.kind = prop.key.name;
|
prop.kind = prop.key.name;
|
||||||
|
|||||||
1
test/fixtures/experimental/async-functions/invalid-object-shorthand/actual.js
vendored
Normal file
1
test/fixtures/experimental/async-functions/invalid-object-shorthand/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
({ async a });
|
||||||
3
test/fixtures/experimental/async-functions/invalid-object-shorthand/options.json
vendored
Normal file
3
test/fixtures/experimental/async-functions/invalid-object-shorthand/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected token (1:11)"
|
||||||
|
}
|
||||||
1
test/fixtures/experimental/async-functions/invalid-object-value/actual.js
vendored
Normal file
1
test/fixtures/experimental/async-functions/invalid-object-value/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
({ async a: function () {} });
|
||||||
3
test/fixtures/experimental/async-functions/invalid-object-value/options.json
vendored
Normal file
3
test/fixtures/experimental/async-functions/invalid-object-value/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected token (1:10)"
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user