Fix bug super ref check doesn’t honor spec evaluation order (#5801)

This commit is contained in:
Buu Nguyen
2017-06-27 02:16:47 +07:00
committed by Justin Ridgewell
parent 851d2cb6e0
commit 033bad3098
6 changed files with 56 additions and 10 deletions

View File

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