I'm wondering if UglifyJS2 might not be able to do a better job at compressing common output of CoffeeScript. Here an example:
test = (
(s) -> w.toLowerCase() for w in s.trim().split(" ")
)("test")
Which compiles to this:
var test;
test = (function(s) {
var w, _i, _len, _ref, _results;
_ref = s.trim().split(" ");
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
w = _ref[_i];
_results.push(w.toLowerCase());
}
return _results;
})("test");
Which is uglified to this:
var test;
test = function(t) {
var e, r, s, n, o;
for (n = t.trim().split(" "), o = [], r = 0, s = n.length; s > r; r++) e = n[r],
o.push(e.toLowerCase());
return o;
}("test");
Shouldn't it also be possible to produce the following?
var test = function(t) {
var n = t.trim().split(" "), o = [], r = 0, s = n.length;
for (; s > r; r++) o.push(n[r].toLowerCase());
return o;
}("test");
I removed the unnecessary temporary variable e from the last example, but mostly I'm referring to moving assignments up into the corresponding var declaration. I'm new to UglifyJS, so forgive me if I'm just missing a compiler flag.
I'm wondering if UglifyJS2 might not be able to do a better job at compressing common output of CoffeeScript. Here an example:
Which compiles to this:
Which is uglified to this:
Shouldn't it also be possible to produce the following?
I removed the unnecessary temporary variable
efrom the last example, but mostly I'm referring to moving assignments up into the correspondingvardeclaration. I'm new to UglifyJS, so forgive me if I'm just missing a compiler flag.