From f0c766098011f21c38ea1a4c80051699e66598f8 Mon Sep 17 00:00:00 2001 From: Vladimir Kurchatkin Date: Fri, 24 Jun 2016 20:23:02 +0300 Subject: [PATCH] move logic to flow plugin --- src/parser/statement.js | 11 +++++------ src/plugins/flow.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/parser/statement.js b/src/parser/statement.js index e81a437b83..d20e8c5bde 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -621,6 +621,10 @@ pp.isClassProperty = function () { return this.match(tt.eq) || this.isLineTerminator(); }; +pp.isClassMutatorStarter = function () { + return false; +}; + pp.parseClassBody = function (node) { // class bodies are implicitly strict let oldStrict = this.state.strict; @@ -658,7 +662,6 @@ pp.parseClassBody = function (node) { let isGenerator = this.eat(tt.star); let isGetSet = false; let isAsync = false; - let isGeneric = false; this.parsePropertyName(method); @@ -693,13 +696,9 @@ pp.parseClassBody = function (node) { if (!method.computed) { let { key } = method; - if (this.hasPlugin("flow") && this.isRelational("<")) { - isGeneric = true; - } - // handle get/set methods // eg. class Foo { get bar() {} set bar() {} } - if (!isAsync && !isGenerator && !isGeneric && key.type === "Identifier" && !this.match(tt.parenL) && (key.name === "get" || key.name === "set")) { + if (!isAsync && !isGenerator && !this.isClassMutatorStarter() && key.type === "Identifier" && !this.match(tt.parenL) && (key.name === "get" || key.name === "set")) { isGetSet = true; method.kind = key.name; key = this.parsePropertyName(method); diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 9d0279ae99..4bcf405632 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -1075,4 +1075,14 @@ export default function (instance) { return inner.call(this, node); }; }); + + instance.extend("isClassMutatorStarter", function (inner) { + return function () { + if (this.isRelational("<")) { + return true; + } else { + return inner.call(this); + } + }; + }); }