@@ -644,10 +644,9 @@ themePicker.onblur = handleThemeButtonsBlur;
644
644
themes.appendChild(but);
645
645
}});"# ,
646
646
as_json( & themes) ) ;
647
- write ( cx. dst . join ( & format ! ( "theme{}.js" , cx. shared. resource_suffix) ) ,
648
- theme_js. as_bytes ( )
649
- ) ?;
650
-
647
+ write_minify ( & cx. shared . fs , cx. path ( "theme.js" ) ,
648
+ & theme_js,
649
+ options. enable_minification ) ?;
651
650
write_minify ( & cx. shared . fs , cx. path ( "main.js" ) ,
652
651
static_files:: MAIN_JS ,
653
652
options. enable_minification ) ?;
@@ -715,19 +714,13 @@ themePicker.onblur = handleThemeButtonsBlur;
715
714
path : & Path ,
716
715
krate : & str ,
717
716
key : & str ,
718
- for_search_index : bool ,
719
- ) -> io:: Result < ( Vec < String > , Vec < String > , Vec < String > ) > {
717
+ ) -> io:: Result < ( Vec < String > , Vec < String > ) > {
720
718
let mut ret = Vec :: new ( ) ;
721
719
let mut krates = Vec :: new ( ) ;
722
- let mut variables = Vec :: new ( ) ;
723
720
724
721
if path. exists ( ) {
725
722
for line in BufReader :: new ( File :: open ( path) ?) . lines ( ) {
726
723
let line = line?;
727
- if for_search_index && line. starts_with ( "var R" ) {
728
- variables. push ( line. clone ( ) ) ;
729
- continue ;
730
- }
731
724
if !line. starts_with ( key) {
732
725
continue ;
733
726
}
@@ -741,7 +734,7 @@ themePicker.onblur = handleThemeButtonsBlur;
741
734
. unwrap_or_else ( || String :: new ( ) ) ) ;
742
735
}
743
736
}
744
- Ok ( ( ret, krates, variables ) )
737
+ Ok ( ( ret, krates) )
745
738
}
746
739
747
740
fn show_item ( item : & IndexItem , krate : & str ) -> String {
@@ -756,7 +749,7 @@ themePicker.onblur = handleThemeButtonsBlur;
756
749
757
750
let dst = cx. dst . join ( & format ! ( "aliases{}.js" , cx. shared. resource_suffix) ) ;
758
751
{
759
- let ( mut all_aliases, _, _ ) = try_err ! ( collect( & dst, & krate. name, "ALIASES" , false ) , & dst) ;
752
+ let ( mut all_aliases, _) = try_err ! ( collect( & dst, & krate. name, "ALIASES" ) , & dst) ;
760
753
let mut output = String :: with_capacity ( 100 ) ;
761
754
for ( alias, items) in & cx. cache . aliases {
762
755
if items. is_empty ( ) {
@@ -853,9 +846,7 @@ themePicker.onblur = handleThemeButtonsBlur;
853
846
}
854
847
855
848
let dst = cx. dst . join ( & format ! ( "source-files{}.js" , cx. shared. resource_suffix) ) ;
856
- let ( mut all_sources, _krates, _) = try_err ! ( collect( & dst, & krate. name, "sourcesIndex" ,
857
- false ) ,
858
- & dst) ;
849
+ let ( mut all_sources, _krates) = try_err ! ( collect( & dst, & krate. name, "sourcesIndex" ) , & dst) ;
859
850
all_sources. push ( format ! ( "sourcesIndex[\" {}\" ] = {};" ,
860
851
& krate. name,
861
852
hierarchy. to_json_string( ) ) ) ;
@@ -867,23 +858,18 @@ themePicker.onblur = handleThemeButtonsBlur;
867
858
868
859
// Update the search index
869
860
let dst = cx. dst . join ( & format ! ( "search-index{}.js" , cx. shared. resource_suffix) ) ;
870
- let ( mut all_indexes, mut krates, variables) = try_err ! ( collect( & dst,
871
- & krate. name,
872
- "searchIndex" ,
873
- true ) , & dst) ;
861
+ let ( mut all_indexes, mut krates) = try_err ! ( collect( & dst, & krate. name, "searchIndex" ) , & dst) ;
874
862
all_indexes. push ( search_index) ;
875
863
876
864
// Sort the indexes by crate so the file will be generated identically even
877
865
// with rustdoc running in parallel.
878
866
all_indexes. sort ( ) ;
879
867
{
880
- let mut v = String :: from ( "var N=null,E=\" \" ,T=\" t\" ,U=\" u\" ,searchIndex={};\n " ) ;
881
- v. push_str ( & minify_replacer (
882
- & format ! ( "{}\n {}" , variables. join( "" ) , all_indexes. join( "\n " ) ) ,
883
- options. enable_minification ) ) ;
868
+ let mut v = String :: from ( "var searchIndex={};\n " ) ;
869
+ v. push_str ( & all_indexes. join ( "\n " ) ) ;
884
870
// "addSearchOptions" has to be called first so the crate filtering can be set before the
885
871
// search might start (if it's set into the URL for example).
886
- v. push_str ( "addSearchOptions (searchIndex);initSearch(searchIndex);" ) ;
872
+ v. push_str ( "\n addSearchOptions (searchIndex);initSearch(searchIndex);" ) ;
887
873
cx. shared . fs . write ( & dst, & v) ?;
888
874
}
889
875
if options. enable_index_page {
@@ -981,9 +967,8 @@ themePicker.onblur = handleThemeButtonsBlur;
981
967
remote_item_type,
982
968
remote_path[ remote_path. len( ) - 1 ] ) ) ;
983
969
984
- let ( mut all_implementors, _, _) = try_err ! ( collect( & mydst, & krate. name, "implementors" ,
985
- false ) ,
986
- & mydst) ;
970
+ let ( mut all_implementors, _) = try_err ! ( collect( & mydst, & krate. name, "implementors" ) ,
971
+ & mydst) ;
987
972
all_implementors. push ( implementors) ;
988
973
// Sort the implementors by crate so the file will be generated
989
974
// identically even with rustdoc running in parallel.
@@ -1020,68 +1005,6 @@ fn write_minify(fs:&DocFS, dst: PathBuf, contents: &str, enable_minification: bo
1020
1005
}
1021
1006
}
1022
1007
1023
- fn minify_replacer (
1024
- contents : & str ,
1025
- enable_minification : bool ,
1026
- ) -> String {
1027
- use minifier:: js:: { simple_minify, Keyword , ReservedChar , Token , Tokens } ;
1028
-
1029
- if enable_minification {
1030
- let tokens: Tokens < ' _ > = simple_minify ( contents)
1031
- . into_iter ( )
1032
- . filter ( |( f, next) | {
1033
- // We keep backlines.
1034
- minifier:: js:: clean_token_except ( f, next, & |c : & Token < ' _ > | {
1035
- c. get_char ( ) != Some ( ReservedChar :: Backline )
1036
- } )
1037
- } )
1038
- . map ( |( f, _) | {
1039
- minifier:: js:: replace_token_with ( f, & |t : & Token < ' _ > | {
1040
- match * t {
1041
- Token :: Keyword ( Keyword :: Null ) => Some ( Token :: Other ( "N" ) ) ,
1042
- Token :: String ( s) => {
1043
- let s = & s[ 1 ..s. len ( ) -1 ] ; // The quotes are included
1044
- if s. is_empty ( ) {
1045
- Some ( Token :: Other ( "E" ) )
1046
- } else if s == "t" {
1047
- Some ( Token :: Other ( "T" ) )
1048
- } else if s == "u" {
1049
- Some ( Token :: Other ( "U" ) )
1050
- } else {
1051
- None
1052
- }
1053
- }
1054
- _ => None ,
1055
- }
1056
- } )
1057
- } )
1058
- . collect :: < Vec < _ > > ( )
1059
- . into ( ) ;
1060
- let o = tokens. apply ( |f| {
1061
- // We add a backline after the newly created variables.
1062
- minifier:: js:: aggregate_strings_into_array_with_separation_filter (
1063
- f,
1064
- "R" ,
1065
- Token :: Char ( ReservedChar :: Backline ) ,
1066
- // This closure prevents crates' names from being aggregated.
1067
- //
1068
- // The point here is to check if the string is preceded by '[' and
1069
- // "searchIndex". If so, it means this is a crate name and that it
1070
- // shouldn't be aggregated.
1071
- |tokens, pos| {
1072
- pos < 2 ||
1073
- !tokens[ pos - 1 ] . eq_char ( ReservedChar :: OpenBracket ) ||
1074
- tokens[ pos - 2 ] . get_other ( ) != Some ( "searchIndex" )
1075
- }
1076
- )
1077
- } )
1078
- . to_string ( ) ;
1079
- format ! ( "{}\n " , o)
1080
- } else {
1081
- format ! ( "{}\n " , contents)
1082
- }
1083
- }
1084
-
1085
1008
#[ derive( Debug , Eq , PartialEq , Hash ) ]
1086
1009
struct ItemEntry {
1087
1010
url : String ,
0 commit comments