Javascript: How to add semicolon automatically on every line to existing scripts

Suppose you've found some interesting javascript code on the internet but this one has been written down without the final semicolon at the end of every line (That's not so rare because unfortunately the missing semicolon is perfectly legal in javascript :-( ), but you want it for some good reason, e.g.:

For the above reasons, I was looking for a tool able to add the semicolon automatically without the need to manually adding it among tons of lines… and I found one online here: http://refresh-sf.com/yui/

This is not exactly a tools for that purpose, anyway before shrinking it adds semicolon, so the only thing to do after that is using a beautifier to reformat the code to something human readable.

So, the first thing to do is going to http://refresh-sf.com/yui/ and before submitting the compression, set the following options:

The resulting file can now be reformatted into an IDE or if you don't have one you can use one of the many online beautifiers such this one http://jsbeautifier.org/

NB: the comments are inevitably lost because the minifiers cuts them off. If you know some better and specific tool, let me know! — Riccardo Bartolini 2013/07/15 13:16