Check javascript for missing ";" before compression

I am doing some optimizations and decided to compress my javascript files using YUI Compressor . The problem is that some lines of code are missing ";" in the end, since javascript allows this and the developers not to look too much at it.

Will there be a problem with code compression? If so, is there a way to check javascript for strings that do not have ";"?

+5
source share
4 answers

jsLint can check your code for this. And yes, this is likely to cause problems if the compressor does not actually contain a JavaScript parser and actively corrects for missing semicolons.

+9
source

According to this SO answer , YUI Compressor can handle this.

+3
source

JavaScript: Yuicompressor, Yuglify Google Closure Compiler. Ubuntu 12.10 , :

function dbz(){
    var goku = 1
    var vegeta = 2
    var freeza = 3
    console.log(goku + vegeta + freeza)
}
dbz()

:

(2.4.7):

function dbz(){var b=1;var c=2;var a=3;console.log(b+c+a)}dbz();

(0.1.2):

function dbz(){var e=1,t=2,n=3;console.log(e+t+n)}dbz();

Closure-Compiler ( 20121212, 2388):

function dbz(){console.log(6)}dbz();

, . , .

+2
source

You can always use regexp to match new characters that don't have; in front of them, and, of course, make exceptions for things like empty lines,)}, etc.

But to be honest, if it really doesn’t do this automatically, it seems that it is really broken \ plain bad.

+1
source

All Articles