refactor: search parent instead of using state

This commit is contained in:
Sven SAULEAU
2017-03-07 21:19:06 +01:00
committed by Brian Ng
parent 819056e94a
commit bf9b434736
3 changed files with 17 additions and 8 deletions

View File

@@ -23,18 +23,17 @@ const noMethodVisitor = {
};
const verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
Super(path, state) {
Super(path) {
if (
this.isDerived && !this.hasBareSuper &&
!path.parentPath.isCallExpression({ callee: path.node }) &&
!state.inArrowFunctionExpression
!path.parentPath.isCallExpression({ callee: path.node })
) {
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
}
},
const hasArrowFunctionParent = path.findParent((p) => p.isArrowFunctionExpression());
ArrowFunctionExpression(path, state) {
state.inArrowFunctionExpression = true;
if (!hasArrowFunctionParent) {
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
}
}
},
CallExpression: {

View File

@@ -0,0 +1,7 @@
class Foo extends Bar {
constructor() {
const t = () => super.test()
super.foo();
super();
}
}

View File

@@ -0,0 +1,3 @@
{
"throws": "'super.*' is not allowed before super()"
}