remove anonymous class constructor name in specific case

Name of anonymous class constructor is not needed when it contains
exactly one method that is not construtor, because constructor
will be assigned to variable in closure.
This commit is contained in:
Ondrej Kraus 2015-02-24 00:20:45 +01:00
parent 9621d1bbeb
commit b7c297bb89

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;
//
@ -86,7 +87,10 @@ ClassTransformer.prototype.run = function () {
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
if (!this.hasSuper && this.node.body.body.length <= 1) {
var containsOnlyConstructor = classBody.length === 1 &&
classBody[0].key.name === "constructor";
if (!this.hasSuper && (classBody.length === 0 ||
containsOnlyConstructor)) {
constructorName = className;
}