Fix return super(); in class constructor - fixes T2997
This commit is contained in:
parent
58f512f7c4
commit
9a270a3d0a
@ -2,10 +2,10 @@ var Foo = (function (_Bar) {
|
|||||||
babelHelpers.inherits(Foo, _Bar);
|
babelHelpers.inherits(Foo, _Bar);
|
||||||
|
|
||||||
function Foo(...args) {
|
function Foo(...args) {
|
||||||
var _temp, _this;
|
var _temp, _this, _ret;
|
||||||
|
|
||||||
babelHelpers.classCallCheck(this, Foo);
|
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;
|
return Foo;
|
||||||
|
|||||||
@ -433,7 +433,15 @@ export default class ClassTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let returnPath of this.superReturns) {
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2997/actual.js
vendored
Normal file
7
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2997/actual.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class A {}
|
||||||
|
|
||||||
|
class B extends A {
|
||||||
|
constructor() {
|
||||||
|
return super();
|
||||||
|
}
|
||||||
|
}
|
||||||
20
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2997/expected.js
vendored
Normal file
20
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/T2997/expected.js
vendored
Normal 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);
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user