@@ -1146,11 +1146,12 @@ function minify_javascript(data) {
11461146 var alpha = / [ 0 - 9 a - z $ ] / i;
11471147 var white = / \W / ;
11481148 var skip = { '$' : true , '_' : true } ;
1149+ var newlines = { '\n' : 1 , '\r' : 1 } ;
11491150 var regexp = false ;
1150- var scope ;
1151- var prev ;
1152- var next ;
1153- var last ;
1151+ var scope , prev , next , last ;
1152+ var vtmp = false ;
1153+ var regvar = / ^ ( \s ) * v a r / ;
1154+ var vindex = 0 ;
11541155
11551156 while ( true ) {
11561157
@@ -1181,7 +1182,7 @@ function minify_javascript(data) {
11811182 if ( c === '/' && next === '/' ) {
11821183 isCI = true ;
11831184 continue ;
1184- } else if ( isCI && ( c === '\n' || c === '\r' ) ) {
1185+ } else if ( isCI && newlines [ c ] ) {
11851186 isCI = false ;
11861187 alpha . test ( last ) && output . push ( ' ' ) ;
11871188 last = '' ;
@@ -1192,7 +1193,7 @@ function minify_javascript(data) {
11921193 continue ;
11931194 }
11941195
1195- if ( c === '\t' || c === '\n' || c === '\r' ) {
1196+ if ( c === '\t' || newlines [ c ] ) {
11961197 if ( ! last || ! alpha . test ( last ) )
11971198 continue ;
11981199 output . push ( ' ' ) ;
@@ -1201,8 +1202,11 @@ function minify_javascript(data) {
12011202 }
12021203
12031204 if ( ! regexp && ( c === ' ' && ( white . test ( prev ) || white . test ( next ) ) ) ) {
1204- if ( ! skip [ prev ] && ! skip [ next ] )
1205- continue ;
1205+ // if (!skip[prev] && !skip[next])
1206+ if ( ! skip [ prev ] ) {
1207+ if ( ! skip [ next ] || ! alpha . test ( prev ) )
1208+ continue ;
1209+ }
12061210 }
12071211
12081212 if ( regexp ) {
@@ -1233,6 +1237,36 @@ function minify_javascript(data) {
12331237 scope = c ;
12341238 }
12351239
1240+ // var
1241+ if ( ! scope && c === 'v' && next === 'a' ) {
1242+ var v = c + data [ index ] + data [ index + 1 ] + data [ index + 2 ] ;
1243+ if ( v === 'var ' ) {
1244+ if ( vtmp && output [ output . length - 1 ] === ';' ) {
1245+ output . pop ( ) ;
1246+ output . push ( ',' ) ;
1247+ } else
1248+ output . push ( 'var ' ) ;
1249+ index += 3 ;
1250+ vtmp = true ;
1251+ continue ;
1252+ }
1253+ } else {
1254+ if ( vtmp ) {
1255+
1256+
1257+ vindex = index + 1 ;
1258+
1259+ while ( true ) {
1260+ if ( ! data [ vindex ] || ! white . test ( data [ vindex ] ) )
1261+ break ;
1262+ vindex ++ ;
1263+ }
1264+
1265+ if ( c === '(' || c === ')' || ( c === ';' && ! regvar . test ( data . substring ( vindex , vindex + 20 ) ) ) )
1266+ vtmp = false ;
1267+ }
1268+ }
1269+
12361270 if ( ( c === '}' && last === ';' ) || ( ( c === '}' || c === ']' ) && output [ output . length - 1 ] === ' ' && alpha . test ( output [ output . length - 2 ] ) ) )
12371271 output . pop ( ) ;
12381272
0 commit comments