From 3cf7b2b761ad01464155d163bd9b04d8f1f21493 Mon Sep 17 00:00:00 2001 From: Ondrej Kraus Date: Mon, 23 Feb 2015 17:19:41 +0100 Subject: [PATCH] add name to constructor of extended anonymous class --- lib/babel/transformation/transformers/es6/classes.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/babel/transformation/transformers/es6/classes.js b/lib/babel/transformation/transformers/es6/classes.js index 6d1705bffa..20df75660c 100644 --- a/lib/babel/transformation/transformers/es6/classes.js +++ b/lib/babel/transformation/transformers/es6/classes.js @@ -83,7 +83,14 @@ ClassTransformer.prototype.run = function () { constructor = t.functionDeclaration(className, [], constructorBody); body.push(constructor); } else { - constructor = t.functionExpression(null, [], constructorBody); + var constructorName = null; + // when there is only constructor or nothing, constructor is not + // wrapped in closure and has to be named + if (this.node.body.body.length <= 1) { + constructorName = className; + } + + constructor = t.functionExpression(constructorName, [], constructorBody); body.push(t.variableDeclaration("var", [ t.variableDeclarator(className, constructor) ]));