Merge pull request #870 from neVERberleRfellerER/fix-extends-anon-class

fix extends with empty anonymous base class
This commit is contained in:
Sebastian McKenzie
2015-02-24 11:18:18 +11:00
3 changed files with 161 additions and 1 deletions

View File

@@ -65,6 +65,7 @@ function ClassTransformer(node, file, scope, isStatement) {
ClassTransformer.prototype.run = function () {
var superName = this.superName;
var className = this.className;
var classBody = this.node.body.body;
var file = this.file;
//
@@ -83,7 +84,17 @@ ClassTransformer.prototype.run = function () {
constructor = t.functionDeclaration(className, [], constructorBody);
body.push(constructor);
} else {
constructor = t.functionExpression(null, [], constructorBody);
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)) {
constructorName = className;
}
constructor = t.functionExpression(constructorName, [], constructorBody);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(className, constructor)
]));