Extract 'parseClassMember' method (#533)

This commit is contained in:
Andy
2017-05-26 20:44:56 -07:00
committed by Henry Zhu
parent aad95c63ec
commit 50694f99b1
4 changed files with 120 additions and 102 deletions

View File

@@ -887,7 +887,7 @@ export default class ExpressionParser extends LValParser {
// get methods aren't allowed to have any parameters
// set methods must have exactly 1 parameter
checkGetterSetterParamCount(method: N.ObjectMethod): void {
checkGetterSetterParamCount(method: N.ObjectMethod | N.ClassMethod): void {
const paramCount = method.kind === "get" ? 0 : 1;
if (method.params.length !== paramCount) {
const start = method.start;
@@ -956,12 +956,14 @@ export default class ExpressionParser extends LValParser {
if (!node) this.unexpected();
}
parsePropertyName(prop: N.ObjectMember): N.Identifier {
parsePropertyName(prop: N.ObjectOrClassMember): N.Identifier {
if (this.eat(tt.bracketL)) {
// $FlowFixMe (ClassPrivateMember shouldn't be allowed to be computed!)
prop.computed = true;
prop.key = this.parseMaybeAssign();
this.expect(tt.bracketR);
} else {
// $FlowFixMe (ClassPrivateMember shouldn't be allowed to be computed!)
prop.computed = false;
const oldInPropertyName = this.state.inPropertyName;
this.state.inPropertyName = true;