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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user