Merge pull request #3112 from phantom10111/fix-es2015-classes

Fix return super(); in class constructor - fixes T2997
This commit is contained in:
Henry Zhu
2015-12-03 10:34:18 -05:00
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);