Skip to content

Commit 35ba58f

Browse files
Remove minification on search-index.js file
1 parent 5748b4c commit 35ba58f

File tree

1 file changed

+9
-85
lines changed

1 file changed

+9
-85
lines changed

src/librustdoc/html/render.rs

+9-85
Original file line numberDiff line numberDiff line change
@@ -715,19 +715,13 @@ themePicker.onblur = handleThemeButtonsBlur;
715715
path: &Path,
716716
krate: &str,
717717
key: &str,
718-
for_search_index: bool,
719-
) -> io::Result<(Vec<String>, Vec<String>, Vec<String>)> {
718+
) -> io::Result<(Vec<String>, Vec<String>)> {
720719
let mut ret = Vec::new();
721720
let mut krates = Vec::new();
722-
let mut variables = Vec::new();
723721

724722
if path.exists() {
725723
for line in BufReader::new(File::open(path)?).lines() {
726724
let line = line?;
727-
if for_search_index && line.starts_with("var R") {
728-
variables.push(line.clone());
729-
continue;
730-
}
731725
if !line.starts_with(key) {
732726
continue;
733727
}
@@ -741,7 +735,7 @@ themePicker.onblur = handleThemeButtonsBlur;
741735
.unwrap_or_else(|| String::new()));
742736
}
743737
}
744-
Ok((ret, krates, variables))
738+
Ok((ret, krates))
745739
}
746740

747741
fn show_item(item: &IndexItem, krate: &str) -> String {
@@ -756,7 +750,7 @@ themePicker.onblur = handleThemeButtonsBlur;
756750

757751
let dst = cx.dst.join(&format!("aliases{}.js", cx.shared.resource_suffix));
758752
{
759-
let (mut all_aliases, _, _) = try_err!(collect(&dst, &krate.name, "ALIASES", false), &dst);
753+
let (mut all_aliases, _) = try_err!(collect(&dst, &krate.name, "ALIASES"), &dst);
760754
let mut output = String::with_capacity(100);
761755
for (alias, items) in &cx.cache.aliases {
762756
if items.is_empty() {
@@ -853,9 +847,7 @@ themePicker.onblur = handleThemeButtonsBlur;
853847
}
854848

855849
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);
850+
let (mut all_sources, _krates) = try_err!(collect(&dst, &krate.name, "sourcesIndex"), &dst);
859851
all_sources.push(format!("sourcesIndex[\"{}\"] = {};",
860852
&krate.name,
861853
hierarchy.to_json_string()));
@@ -867,20 +859,15 @@ themePicker.onblur = handleThemeButtonsBlur;
867859

868860
// Update the search index
869861
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);
862+
let (mut all_indexes, mut krates) = try_err!(collect(&dst, &krate.name, "searchIndex"), &dst);
874863
all_indexes.push(search_index);
875864

876865
// Sort the indexes by crate so the file will be generated identically even
877866
// with rustdoc running in parallel.
878867
all_indexes.sort();
879868
{
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));
869+
let mut v = String::from("var searchIndex={};\n");
870+
v.push_str(&all_indexes.join("\n"));
884871
// "addSearchOptions" has to be called first so the crate filtering can be set before the
885872
// search might start (if it's set into the URL for example).
886873
v.push_str("addSearchOptions(searchIndex);initSearch(searchIndex);");
@@ -981,9 +968,8 @@ themePicker.onblur = handleThemeButtonsBlur;
981968
remote_item_type,
982969
remote_path[remote_path.len() - 1]));
983970

984-
let (mut all_implementors, _, _) = try_err!(collect(&mydst, &krate.name, "implementors",
985-
false),
986-
&mydst);
971+
let (mut all_implementors, _) = try_err!(collect(&mydst, &krate.name, "implementors"),
972+
&mydst);
987973
all_implementors.push(implementors);
988974
// Sort the implementors by crate so the file will be generated
989975
// identically even with rustdoc running in parallel.
@@ -1020,68 +1006,6 @@ fn write_minify(fs:&DocFS, dst: PathBuf, contents: &str, enable_minification: bo
10201006
}
10211007
}
10221008

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-
10851009
#[derive(Debug, Eq, PartialEq, Hash)]
10861010
struct ItemEntry {
10871011
url: String,

0 commit comments

Comments
 (0)