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: {

View File

@@ -0,0 +1,5 @@
class Foo extends Bar {
constructor() {
super.foo(super());
}
}

View File

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

View File

@@ -0,0 +1,5 @@
class Foo extends Bar {
constructor() {
super[super().method]();
}
}

View File

@@ -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);

View File

@@ -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);