Allow super in class properties (#499)

This commit is contained in:
Brian Ng
2017-05-02 13:41:10 -05:00
committed by Henry Zhu
parent 9660f06b25
commit d33c82781a
6 changed files with 291 additions and 3 deletions

View File

@@ -381,7 +381,11 @@ export default class ExpressionParser extends LValParser {
switch (this.state.type) {
case tt._super:
if (!this.state.inMethod && !this.options.allowSuperOutsideMethod) {
if (
!this.state.inMethod &&
!this.state.inClassProperty &&
!this.options.allowSuperOutsideMethod
) {
this.raise(this.state.start, "'super' outside of function or class");
}

View File

@@ -772,19 +772,23 @@ export default class StatementParser extends ExpressionParser {
}
parseClassProperty(node) {
const hasPlugin = this.hasPlugin("classProperties");
const noPluginMsg = "You can only use Class Properties when the 'classProperties' plugin is enabled.";
if (!node.typeAnnotation && !this.hasPlugin("classProperties")) {
if (!node.typeAnnotation && !hasPlugin) {
this.raise(node.start, noPluginMsg);
}
this.state.inClassProperty = true;
if (this.match(tt.eq)) {
if (!this.hasPlugin("classProperties")) this.raise(this.state.start, noPluginMsg);
if (!hasPlugin) this.raise(this.state.start, noPluginMsg);
this.next();
node.value = this.parseMaybeAssign();
} else {
node.value = null;
}
this.semicolon();
this.state.inClassProperty = false;
return this.finishNode(node, "ClassProperty");
}

View File

@@ -18,6 +18,7 @@ export default class State {
this.inAsync =
this.inPropertyName =
this.inType =
this.inClassProperty =
this.noAnonFunctionType =
false;
@@ -73,6 +74,7 @@ export default class State {
inAsync: boolean;
inType: boolean;
inPropertyName: boolean;
inClassProperty: boolean;
// Labels in scope.
labels: Array<Object>;