This commit is contained in:
Sebastian McKenzie 2015-02-24 11:20:04 +11:00
parent 8c5e7cf272
commit 717ef280f7

View File

@ -78,19 +78,17 @@ ClassTransformer.prototype.run = function () {
className
]))
]);
var constructor;
var constructor;
if (this.node.id) {
constructor = t.functionDeclaration(className, [], constructorBody);
body.push(constructor);
} else {
var constructorName = null;
// when class has no parent and there is only constructor or nothing then
// constructor is not wrapped in closure and has to be named
var containsOnlyConstructor = classBody.length === 1 &&
classBody[0].key.name === "constructor";
if (!this.hasSuper && (classBody.length === 0 ||
containsOnlyConstructor)) {
// when a class has no parent and there is only a constructor or no body
// then the constructor is not wrapped in a closure and needs to be named
var containsOnlyConstructor = classBody.length === 1 && classBody[0].key.name === "constructor";
if (!this.hasSuper && (classBody.length === 0 || containsOnlyConstructor)) {
constructorName = className;
}