Fix parsing of private fields (#566)

The computed key is not part of the spec.
key for ClassProperties is an Expression
Do not parse computed and literal keys for PrivateClassProperties
This commit is contained in:
Daniel Tschinder
2017-06-06 17:42:07 +02:00
committed by Henry Zhu
parent 37793d5be7
commit 69cba43f82
18 changed files with 38 additions and 1919 deletions

View File

@@ -578,7 +578,7 @@ export default class ExpressionParser extends LValParser {
if (this.hasPlugin("classPrivateProperties")) {
return this.parseMaybePrivateName();
} else {
this.unexpected();
throw this.unexpected();
}
case tt._new:
@@ -1011,20 +1011,19 @@ export default class ExpressionParser extends LValParser {
if (!node) this.unexpected();
}
parsePropertyName(prop: N.ObjectOrClassMember): N.Identifier {
parsePropertyName(prop: N.ObjectOrClassMember): N.Expression {
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;
prop.key = (this.match(tt.num) || this.match(tt.string)) ? this.parseExprAtom() : this.parseIdentifier(true);
this.state.inPropertyName = oldInPropertyName;
}
return prop.key;
}