Merge pull request #870 from neVERberleRfellerER/fix-extends-anon-class
fix extends with empty anonymous base class
This commit is contained in:
@@ -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)
|
||||
]));
|
||||
|
||||
Reference in New Issue
Block a user