@@ -101,6 +101,12 @@ build.cssMin = cssMin
101101build . parseView = parseView
102102
103103function clean ( str ) {
104+ try {
105+ return child . execSync (
106+ "uglifyjs --beautify beautify=false --" ,
107+ { input : "[" + str + "]" , stdio : [ "pipe" , "pipe" , "pipe" ] }
108+ ) . toString ( "utf8" ) . trim ( ) . replace ( / ^ \[ / , "" ) . replace ( / \] ; ? $ / , "" )
109+ } catch ( e ) { }
104110 return str . replace ( / ( [ $ \w ] [ ! $ \w ] ) | ( [ " ' ` \/ ] ) (?: \\ .| (? ! \2) .) * \2| \s / gi, ( match , p , q ) => {
105111 return p || q ? match : ""
106112 } )
@@ -492,6 +498,10 @@ function viewMin(str, attrs) {
492498 , templateRe = / ( [ \t ] * ) ( % ? ) ( (?: ( " | ' ) (?: \\ \4| .) * ?\4| [ - \w : . # [ \] ] = ? ) * ) [ \t ] * ( [ > ^ ; @ | \\ \/ ] | ! ? = | ) ( ( [ \] ) } ] ? ) .* ?( [ [ ( { ] ? ) ) (? = \x1f | \n | $ ) + / g
493499 , parent = 0
494500 , stack = [ - 1 ]
501+ , jsBlock = - 1
502+ , jsBlockBuf = ""
503+ , jsBlockPrefix = ""
504+ , jsBlockIndent = ""
495505 , joinBindingsRe = / ( \n + ) ( [ ; ^ ] [ ^ \n ] + ) \1(? = [ ; ^ ] ) / g
496506 , joinSelectorRe = / ( \n + ) ( [ \w : . # [ ] (?: [ ^ " ' \n ] | ( " | ' ) (?: \\ \3| (? ! \3) .) * ?\3) * ) \1 (? = [ ; ^ ] ) / g
497507
@@ -513,8 +523,16 @@ function viewMin(str, attrs) {
513523 }
514524 stack . shift ( )
515525 }
526+ if ( jsBlock >= 0 && q <= jsBlock ) {
527+ jsBlockBuf += "\n" + all . slice ( indent . length )
528+ out [ parent ] += jsBlockIndent + jsBlockPrefix + clean ( jsBlockBuf ) + "\n"
529+ jsBlock = - 1
530+ return
531+ }
516532
517- if ( ! isString ( out [ parent ] ) ) {
533+ if ( jsBlock >= 0 ) {
534+ jsBlockBuf += "\n" + all . slice ( indent . length )
535+ } else if ( ! isString ( out [ parent ] ) ) {
518536 out [ parent ] . _j += all + "\n"
519537 } else if ( plugin && ( name === "todo def" ) ) {
520538 out [ parent ] += all
@@ -529,8 +547,16 @@ function viewMin(str, attrs) {
529547 } else {
530548 if ( op === "/" ) return
531549 all = all . slice ( indent . length )
532- if ( op === ";" || op === "^" || op === "@" ) all = clean ( all )
533- out [ parent ] += " " . repeat ( indent . length ) + all + "\n"
550+ if ( mapStart && ( op === ";" || op === "^" || op === "@" ) ) {
551+ jsBlock = q
552+ jsBlockIndent = " " . repeat ( indent . length )
553+ name = all . lastIndexOf ( "function" )
554+ jsBlockPrefix = name > 0 ? clean ( all . slice ( 0 , name ) ) + " " : clean ( all . slice ( 0 , all . lastIndexOf ( mapStart ) ) )
555+ jsBlockBuf = all . slice ( name > 0 ? name : all . lastIndexOf ( mapStart ) )
556+ } else {
557+ if ( op === ";" || op === "^" || op === "@" ) all = clean ( all )
558+ out [ parent ] += " " . repeat ( indent . length ) + all + "\n"
559+ }
534560 }
535561 }
536562}
0 commit comments