diff --git a/src/parser/expression.js b/src/parser/expression.js index 6d2869f4b7..be1252cbc9 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -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; diff --git a/test/fixtures/experimental/async-functions/invalid-object-shorthand/actual.js b/test/fixtures/experimental/async-functions/invalid-object-shorthand/actual.js new file mode 100644 index 0000000000..7623612ba3 --- /dev/null +++ b/test/fixtures/experimental/async-functions/invalid-object-shorthand/actual.js @@ -0,0 +1 @@ +({ async a }); diff --git a/test/fixtures/experimental/async-functions/invalid-object-shorthand/options.json b/test/fixtures/experimental/async-functions/invalid-object-shorthand/options.json new file mode 100644 index 0000000000..cb6c66081e --- /dev/null +++ b/test/fixtures/experimental/async-functions/invalid-object-shorthand/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:11)" +} diff --git a/test/fixtures/experimental/async-functions/invalid-object-value/actual.js b/test/fixtures/experimental/async-functions/invalid-object-value/actual.js new file mode 100644 index 0000000000..fc9eb18b1a --- /dev/null +++ b/test/fixtures/experimental/async-functions/invalid-object-value/actual.js @@ -0,0 +1 @@ +({ async a: function () {} }); diff --git a/test/fixtures/experimental/async-functions/invalid-object-value/options.json b/test/fixtures/experimental/async-functions/invalid-object-value/options.json new file mode 100644 index 0000000000..89bfc2d73f --- /dev/null +++ b/test/fixtures/experimental/async-functions/invalid-object-value/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:10)" +}