@@ -965,7 +965,11 @@ themePicker.onblur = handleThemeButtonsBlur;
965
965
if for_search_index && line. starts_with ( "var R" ) {
966
966
variables. push ( line. clone ( ) ) ;
967
967
// We need to check if the crate name has been put into a variable as well.
968
- let tokens = js:: simple_minify ( & line) . apply ( js:: clean_tokens) ;
968
+ let tokens: js:: Tokens < ' _ > = js:: simple_minify ( & line)
969
+ . into_iter ( )
970
+ . filter ( js:: clean_token)
971
+ . collect :: < Vec < _ > > ( )
972
+ . into ( ) ;
969
973
let mut pos = 0 ;
970
974
while pos < tokens. len ( ) {
971
975
if let Some ( ( var_pos, Some ( value_pos) ) ) =
@@ -1288,46 +1292,51 @@ fn write_minify_replacer<W: Write>(
1288
1292
contents : & str ,
1289
1293
enable_minification : bool ,
1290
1294
) -> io:: Result < ( ) > {
1291
- use minifier:: js:: { Keyword , ReservedChar , Token } ;
1295
+ use minifier:: js:: { simple_minify , Keyword , ReservedChar , Token , Tokens } ;
1292
1296
1293
1297
if enable_minification {
1294
1298
writeln ! ( dst, "{}" ,
1295
- minifier:: js:: simple_minify( contents)
1296
- . apply( |f| {
1297
- // We keep backlines.
1298
- minifier:: js:: clean_tokens_except( f, |c| {
1299
- c. get_char( ) != Some ( ReservedChar :: Backline )
1300
- } )
1301
- } )
1302
- . apply( |f| {
1303
- minifier:: js:: replace_token_with( f, |t| {
1304
- match * t {
1305
- Token :: Keyword ( Keyword :: Null ) => Some ( Token :: Other ( "N" ) ) ,
1306
- Token :: String ( s) => {
1307
- let s = & s[ 1 ..s. len( ) -1 ] ; // The quotes are included
1308
- if s. is_empty( ) {
1309
- Some ( Token :: Other ( "E" ) )
1310
- } else if s == "t" {
1311
- Some ( Token :: Other ( "T" ) )
1312
- } else if s == "u" {
1313
- Some ( Token :: Other ( "U" ) )
1314
- } else {
1315
- None
1316
- }
1317
- }
1318
- _ => None ,
1319
- }
1320
- } )
1321
- } )
1322
- . apply( |f| {
1323
- // We add a backline after the newly created variables.
1324
- minifier:: js:: aggregate_strings_into_array_with_separation(
1325
- f,
1326
- "R" ,
1327
- Token :: Char ( ReservedChar :: Backline ) ,
1328
- )
1329
- } )
1330
- . to_string( ) )
1299
+ {
1300
+ let tokens: Tokens <' _> = simple_minify( contents)
1301
+ . into_iter( )
1302
+ . filter( |f| {
1303
+ // We keep backlines.
1304
+ minifier:: js:: clean_token_except( f, & |c: & Token <' _>| {
1305
+ c. get_char( ) != Some ( ReservedChar :: Backline )
1306
+ } )
1307
+ } )
1308
+ . map( |f| {
1309
+ minifier:: js:: replace_token_with( f, & |t: & Token <' _>| {
1310
+ match * t {
1311
+ Token :: Keyword ( Keyword :: Null ) => Some ( Token :: Other ( "N" ) ) ,
1312
+ Token :: String ( s) => {
1313
+ let s = & s[ 1 ..s. len( ) -1 ] ; // The quotes are included
1314
+ if s. is_empty( ) {
1315
+ Some ( Token :: Other ( "E" ) )
1316
+ } else if s == "t" {
1317
+ Some ( Token :: Other ( "T" ) )
1318
+ } else if s == "u" {
1319
+ Some ( Token :: Other ( "U" ) )
1320
+ } else {
1321
+ None
1322
+ }
1323
+ }
1324
+ _ => None ,
1325
+ }
1326
+ } )
1327
+ } )
1328
+ . collect:: <Vec <_>>( )
1329
+ . into( ) ;
1330
+ tokens. apply( |f| {
1331
+ // We add a backline after the newly created variables.
1332
+ minifier:: js:: aggregate_strings_into_array_with_separation(
1333
+ f,
1334
+ "R" ,
1335
+ Token :: Char ( ReservedChar :: Backline ) ,
1336
+ )
1337
+ } )
1338
+ . to_string( )
1339
+ } )
1331
1340
} else {
1332
1341
writeln ! ( dst, "{}" , contents)
1333
1342
}
0 commit comments