fix: remove check for super in arrow function

This commit is contained in:
Sven SAULEAU 2017-03-07 20:05:26 +01:00 committed by Brian Ng
parent c5bad22767
commit 819056e94a
No known key found for this signature in database
GPG Key ID: 3F2380E1E1508CA9
3 changed files with 27 additions and 2 deletions

View File

@ -23,15 +23,20 @@ const noMethodVisitor = {
};
const verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
Super(path) {
Super(path, state) {
if (
this.isDerived && !this.hasBareSuper &&
!path.parentPath.isCallExpression({ callee: path.node })
!path.parentPath.isCallExpression({ callee: path.node }) &&
!state.inArrowFunctionExpression
) {
throw path.buildCodeFrameError("'super.*' is not allowed before super()");
}
},
ArrowFunctionExpression(path, state) {
state.inArrowFunctionExpression = true;
},
CallExpression: {
exit(path) {
if (path.get("callee").isSuper()) {

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