Use a functionExpression with class decorators. Fixes #1161.

This commit is contained in:
dignifiedquire
2015-04-07 11:32:33 +02:00
parent 0cb5a7c91e
commit 148aa3f96d
3 changed files with 37 additions and 11 deletions

View File

@@ -30,7 +30,7 @@ var collectPropertyReferencesVisitor = {
}
if (this.isReferenced() && scope.getBinding(node.name) === state.scope.getBinding(node.name)) {
state.references[node.name] = true;;
state.references[node.name] = true;
}
}
}
@@ -140,7 +140,7 @@ class ClassTransformer {
var constructorBody = this.constructorBody = t.blockStatement([]);
var constructor;
if (this.className) {
if (this.className && !this.node.decorators) {
constructor = t.functionDeclaration(this.className, [], constructorBody);
body.push(constructor);
} else {
@@ -189,6 +189,14 @@ class ClassTransformer {
}
if (this.className) {
if (decorators) {
constructor = t.functionExpression(this.className, constructor.params, constructorBody);
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(classRef, constructor)
]));
}
// named class with only a constructor
if (body.length === 1) return t.toExpression(body[0]);
} else {