add name to constructor of extended anonymous class

This commit is contained in:
Ondrej Kraus
2015-02-23 17:19:41 +01:00
parent ae8b1e242b
commit 3cf7b2b761

View File

@@ -83,7 +83,14 @@ ClassTransformer.prototype.run = function () {
constructor = t.functionDeclaration(className, [], constructorBody);
body.push(constructor);
} else {
constructor = t.functionExpression(null, [], constructorBody);
var constructorName = null;
// when there is only constructor or nothing, constructor is not
// wrapped in closure and has to be named
if (this.node.body.body.length <= 1) {
constructorName = className;
}
constructor = t.functionExpression(constructorName, [], constructorBody);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(className, constructor)
]));