Merge pull request #5802 from babel/issue5371

Remove check for super calls in arrow function
This commit is contained in:
Sven SAULEAU 2017-06-01 09:55:08 +02:00 committed by GitHub
commit 7e739f954d
5 changed files with 35 additions and 1 deletions

View File

@ -28,7 +28,11 @@ const verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
this.isDerived && !this.hasBareSuper &&
!path.parentPath.isCallExpression({ callee: path.node })
) {
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
const hasArrowFunctionParent = path.findParent((p) => p.isArrowFunctionExpression());
if (!hasArrowFunctionParent) {
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
}
}
},

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()"
}

View File

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

View File

@ -0,0 +1,14 @@
var Foo = function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
var _this;
babelHelpers.classCallCheck(this, Foo);
var t = () => babelHelpers.get(Foo.prototype.__proto__ || Object.getPrototypeOf(Foo.prototype), "test", _this).call(_this);
return _this = babelHelpers.possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).call(this));
}
return Foo;
}(Bar);