diff --git a/src/parser/statement.js b/src/parser/statement.js index ea0b0fa343..ab7c9d93e8 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -618,8 +618,12 @@ pp.parseClass = function (node, isStatement, optionalId) { return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); }; -pp.isClassProperty = function () { - return this.match(tt.eq) || this.isLineTerminator(); +pp.isInitializedClassProperty = function () { + return this.match(tt.eq); +}; + +pp.isUninitializedClassProperty = function () { + return this.isLineTerminator(); }; pp.isClassMutatorStarter = function () { @@ -674,7 +678,7 @@ pp.parseClassBody = function (node) { } if (!isGenerator) { - if (this.isClassProperty()) { + if (this.isInitializedClassProperty() || (this.isUninitializedClassProperty() && method.key.name !== "get" && method.key.name !== "set")) { classBody.body.push(this.parseClassProperty(method)); continue; } diff --git a/src/plugins/flow.js b/src/plugins/flow.js index c624fbe2b5..807cb1296c 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -976,8 +976,15 @@ export default function (instance) { }; }); - // determine whether or not we're currently in the position where a class property would appear - instance.extend("isClassProperty", function (inner) { + // determine whether or not we're currently in the position where an initialized class property would appear + instance.extend("isInitializedClassProperty", function (inner) { + return function () { + return this.match(tt.colon) || inner.call(this); + }; + }); + + // determine whether or not we're currently in the position where an uninitialized class property would appear + instance.extend("isUninitializedClassProperty", function (inner) { return function () { return this.match(tt.colon) || inner.call(this); };