jashkenas/coffee-script — Issue #2052: Class name mangled after minification
Author: wuyuntao
Created: 2012-01-18 03:34:40+00:00
State: open

JavaScript minification tools renames local functions for performance, and this mangles CoffeeScript class names too.

Since Function.name is a read-only property, forcing class names which implemented in #494 does not work.

How about set class name to some other property, like `Foo.__name__` or `Foo.className`?

A brief example

```coffeescript
class Foo
constructor: ->
console.log(this.constructor.name)

foo = new Foo()
```

Compiles into

```javascript
(function() {
var Foo, foo;
Foo = (function() {
Foo.name = 'Foo';
function Foo() {
console.log(this.constructor.name);
}
return Foo;
})();
foo = new Foo();
}).call(this);
// Outputs 'Foo'
```

Minified

```javascript
(function(){
var a,b;
a=(function(){
a.name='Foo';
function a(){
console.log(this.constructor.name);
}
return a;
})();
b=new a();
}).call(this);
// Outputs 'a'
```