Add static private class field support

This commit is contained in:
Justin Ridgewell
2017-07-02 01:44:12 -04:00
parent 5e1e94917c
commit 9c9f9e2adb
11 changed files with 209 additions and 14 deletions

View File

@@ -922,15 +922,6 @@ export default class StatementParser extends ExpressionParser {
const method: N.ClassMethod = memberAny;
const prop: N.ClassProperty = memberAny;
if (this.hasPlugin("classPrivateProperties") && this.match(tt.hash)) {
// Private property
this.next();
const privateProp: N.ClassPrivateProperty = memberAny;
privateProp.key = this.parseIdentifier(true);
classBody.body.push(this.parsePrivateClassProperty(privateProp));
return;
}
let isStatic = false;
if (this.match(tt.name) && this.state.value === "static") {
const key = this.parseIdentifier(true); // eats 'static'
@@ -960,6 +951,16 @@ export default class StatementParser extends ExpressionParser {
isStatic = true;
}
if (this.hasPlugin("classPrivateProperties") && this.match(tt.hash)) {
// Private property
this.next();
const privateProp: N.ClassPrivateProperty = memberAny;
privateProp.key = this.parseIdentifier(true);
privateProp.static = isStatic;
classBody.body.push(this.parsePrivateClassProperty(privateProp));
return;
}
this.parseClassMemberWithIsStatic(classBody, member, state, isStatic);
}

View File

@@ -680,6 +680,7 @@ export type ClassPrivateProperty = NodeBase & {
type: "ClassPrivateProperty",
key: Identifier,
value: ?Expression, // TODO: Not in spec that this is nullable.
static: boolean,
};
export type OptClassDeclaration = ClassBase &