clean up verifyConstructor classes visitor and disallow super.* before super() in derived class constructors - fixes #1921

This commit is contained in:
Sebastian McKenzie
2015-07-04 21:38:22 +02:00
parent bd1bd38556
commit 0e4bb5ee3f
3 changed files with 23 additions and 22 deletions

View File

@@ -25,16 +25,12 @@ var collectPropertyReferencesVisitor = {
};
var verifyConstructorVisitor = {
MethodDefinition: {
enter() {
this.skip();
}
MethodDefinition() {
this.skip();
},
Property: {
enter(node) {
if (node.method) this.skip();
}
Property(node) {
if (node.method) this.skip();
},
CallExpression: {
@@ -50,23 +46,19 @@ var verifyConstructorVisitor = {
}
},
FunctionDeclaration: {
enter() {
this.skip();
"FunctionDeclaration|FunctionExpression"() {
this.skip();
},
ThisExpression(node, parent, scope, state) {
if (state.isDerived && !state.hasBareSuper) {
throw this.errorWithNode("'this' is not allowed before super()");
}
},
FunctionExpression: {
enter() {
this.skip();
}
},
ThisExpression: {
enter(node, parent, scope, state) {
if (state.isDerived && !state.hasBareSuper) {
throw this.errorWithNode("'this' is not allowed before super()");
}
Super(node, parent, scope, state) {
if (state.isDerived && !state.hasBareSuper && !this.parentPath.isCallExpression({ callee: node })) {
throw this.errorWithNode("'super.*' is not allowed before super()");
}
}
};