refactor: search parent instead of using state
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo extends Bar {
|
||||
constructor() {
|
||||
const t = () => super.test()
|
||||
super.foo();
|
||||
super();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "'super.*' is not allowed before super()"
|
||||
}
|
||||
Reference in New Issue
Block a user