Fix return super(); in class constructor - fixes T2997

This commit is contained in:
phantom10111 2015-11-25 21:59:23 +01:00
parent 58f512f7c4
commit 9a270a3d0a
4 changed files with 38 additions and 3 deletions

View File

@ -2,10 +2,10 @@ var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo(...args) {
var _temp, _this;
var _temp, _this, _ret;
babelHelpers.classCallCheck(this, Foo);
return babelHelpers.possibleConstructorReturn(_this, (_temp = (_this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this, ...args)), _this), _this.bar = "foo", _temp));
return _ret = (_temp = (_this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(Foo).call(this, ...args)), _this), _this.bar = "foo", _temp), babelHelpers.possibleConstructorReturn(_this, _ret);
}
return Foo;

View File

@ -433,7 +433,15 @@ export default class ClassTransformer {
}
for (let returnPath of this.superReturns) {
returnPath.get("argument").replaceWith(wrapReturn(returnPath.node.argument));
if (returnPath.node.argument) {
let ref = returnPath.scope.generateDeclaredUidIdentifier("ret");
returnPath.get("argument").replaceWithMultiple([
t.assignmentExpression("=", ref, returnPath.node.argument),
wrapReturn(ref)
]);
} else {
returnPath.get("argument").replaceWith(wrapReturn())
}
}
}

View File

@ -0,0 +1,7 @@
class A {}
class B extends A {
constructor() {
return super();
}
}

View File

@ -0,0 +1,20 @@
"use strict";
var A = function A() {
babelHelpers.classCallCheck(this, A);
};
var B = (function (_A) {
babelHelpers.inherits(B, _A);
function B() {
var _this, _ret;
babelHelpers.classCallCheck(this, B);
return _ret = (_this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(B).call(this)), _this), babelHelpers.possibleConstructorReturn(_this, _ret);
}
return B;
})(A);