Fix bug super ref check doesn’t honor spec evaluation order (#5801)
This commit is contained in:
committed by
Justin Ridgewell
parent
851d2cb6e0
commit
033bad3098
@@ -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: {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo extends Bar {
|
||||
constructor() {
|
||||
super.foo(super());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "'super.*' is not allowed before super()"
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo extends Bar {
|
||||
constructor() {
|
||||
super[super().method]();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
let called = false;
|
||||
|
||||
class A {
|
||||
method() {
|
||||
called = true;
|
||||
}
|
||||
|
||||
get methodName() {
|
||||
return "method";
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
constructor() {
|
||||
super[super().methodName]()
|
||||
}
|
||||
}
|
||||
|
||||
new B();
|
||||
assert.equal(called, true);
|
||||
@@ -0,0 +1,14 @@
|
||||
var Foo = function (_Bar) {
|
||||
babelHelpers.inherits(Foo, _Bar);
|
||||
|
||||
function Foo() {
|
||||
var _this;
|
||||
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
|
||||
babelHelpers.get(Foo.prototype.__proto__ || Object.getPrototypeOf(Foo.prototype), (_this = babelHelpers.possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this)), _this).method, _this).call(_this);
|
||||
return _this;
|
||||
}
|
||||
|
||||
return Foo;
|
||||
}(Bar);
|
||||
Reference in New Issue
Block a user