0

My uglified (using rails uglifier) javascript ends like this:

/* ... actual code */}.call(this),function(){}.call(this),function(){}.call(this),function(){}.call(this),function(){}.call(this),function(){}.call(this);

Or for humans:

}.call(this),
function(){}.call(this),
function(){}.call(this),
function(){}.call(this),
function(){}.call(this),
function(){}.call(this);

Uglifier should be reducing the number of bytes in the final product. I've got some empty coffee files (but more than 6) so as far as I know, it's not because rails is processing them. Anyone know why this would be happening?

jcuenod
  • 55,835
  • 14
  • 65
  • 102
  • That code alone does nothing. Well, it may throw an exception on line 1 - which I suppose is *something*... – shennan Feb 27 '15 at 22:51
  • no, sorry I just excluded the stuff before that. I know that from line 2 it's not doing anything but it's a bit peculiar. – jcuenod Feb 27 '15 at 22:57
  • Do you have some empty files in your js folders? Maybe some .gitkeep files? – Austin Mullins Feb 27 '15 at 23:07
  • Is that the only output? What do your input and configuration files look like? – Tracker1 Feb 28 '15 at 00:03
  • @AustinMullins: Empty files, I hadn't thought of that - I'll check (you'd think uglifier would be smarter though). – jcuenod Feb 28 '15 at 12:34
  • @Tracker1 nope, that's just how the file ends - the uglified javascript is working fine though (as expected) - it's just silly that it ends like this (especially considering the whole point is to save bytes) – jcuenod Feb 28 '15 at 12:34
  • @AustinMullins There are empty files but there are at least 6 so it's unlikely they're the cause – jcuenod Feb 28 '15 at 12:56
  • Also, why the downvote people? – jcuenod Feb 28 '15 at 12:56
  • What file types is your Rails apps configured to uglify? – Nuri Hodges Mar 10 '15 at 21:11
  • I haven't explicitly changed anything so it's the defaults. As far as I know it just processes all javascript (including parsed coffee script) – jcuenod Mar 11 '15 at 07:05
  • Possibly `function(){}.call(this)` code from other empty files just goes elsewhere in the output, and only from these 5 is cumulated in the end. – Frax Mar 13 '15 at 08:46
  • i get this sometimes. i just RegExp it out and move on... – dandavis Mar 14 '15 at 23:39

1 Answers1

3

CoffeeScript wraps all files to a function that is invoked immediately. This prevents variable declarations from multiple files from interfering with each other when the files are concatenated (which is what Rails asset pipeline is doing). Sure, those empty functions could be removed in minification process, but UglifyJS isn't currently able to perform such optimisation.

https://github.com/lautis/uglifier/issues/82

jcuenod
  • 55,835
  • 14
  • 65
  • 102