[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

Class name mangled after minification · Issue #2052 · jashkenas/coffeescript

michaelficarra

trabianmatt added a commit to trabian/trabian-webapp-core that referenced this issue

I was seeing some odd behavior when using a minified version of the js
on a project that leveraged the IdentityMap. It was caused by the use of
the class as the cache key -- js hashes only support string-based keys
so the toString() of the class constructor was being used as the hash
key.

This was fine (though inefficient) until the minification tool reused
function names when they weren't in the same scope (which is fairly
common when using CommonJS). A similar issue was covered in
jashkenas/coffeescript#2052.

This was solved in our case by assigning a unique CACHE_KEY property to
the class the first time it requests its cache. **Be aware, however,
that if you extend a class that already has a CACHE_KEY then it will use
that existing class's CACHE_KEY and therefore will mix IdentityCache
entries.** You can explicitly add a CACHE_KEY class property to avoid
this situation.