Allow super in class properties (#499)
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user