diff --git a/src/librustdoc/html/static/js/externs.js b/src/librustdoc/html/static/js/externs.js index 026b4f911c3..15665b1f31a 100644 --- a/src/librustdoc/html/static/js/externs.js +++ b/src/librustdoc/html/static/js/externs.js @@ -21,7 +21,7 @@ var QueryElement; /** * @typedef {{ * original: string, - * val: string, + * userQuery: string, * length: number, * pos: number, * typeFilter: number, diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 443b7e366d4..55d957db333 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -163,7 +163,7 @@ window.initSearch = function(rawSearchIndex) { * @param {string} val - The user query * @return {ParsedQuery} - The parsed query */ - function parseQuery(val) { + function parseQuery(userQuery) { function isWhitespace(c) { return " \t\n\r".indexOf(c) !== -1; } @@ -182,8 +182,8 @@ window.initSearch = function(rawSearchIndex) { throw new Error("Cannot use literal search when there is more than one element"); } query.pos += 1; - while (query.pos < query.length && query.val[query.pos] !== "\"") { - if (query.val[query.pos] === "\\") { + while (query.pos < query.length && query.userQuery[query.pos] !== "\"") { + if (query.userQuery[query.pos] === "\\") { // We ignore the next coming character. query.pos += 1; } @@ -198,7 +198,7 @@ window.initSearch = function(rawSearchIndex) { } function skipWhitespaces(query) { while (query.pos < query.length) { - var c = query.val[query.pos]; + var c = query.userQuery[query.pos]; if (!isWhitespace(c)) { break; } @@ -207,7 +207,7 @@ window.initSearch = function(rawSearchIndex) { } function skipStopCharacters(query) { while (query.pos < query.length) { - var c = query.val[query.pos]; + var c = query.userQuery[query.pos]; if (!isStopCharacter(c)) { break; } @@ -216,11 +216,11 @@ window.initSearch = function(rawSearchIndex) { } function isPathStart(query) { var pos = query.pos; - return pos + 1 < query.length && query.val[pos] === ':' && query.val[pos + 1] === ':'; + return pos + 1 < query.length && query.userQuery[pos] === ':' && query.userQuery[pos + 1] === ':'; } function isReturnArrow(query) { var pos = query.pos; - return pos + 1 < query.length && query.val[pos] === '-' && query.val[pos + 1] === '>'; + return pos + 1 < query.length && query.userQuery[pos] === '-' && query.userQuery[pos + 1] === '>'; } function removeEmptyStringsFromArray(x) { for (var i = 0, len = x.length; i < len; ++i) { @@ -230,19 +230,19 @@ window.initSearch = function(rawSearchIndex) { } } } - function createQueryElement(query, elems, val, generics) { + function createQueryElement(query, elems, name, generics) { removeEmptyStringsFromArray(generics); - if (val === '*' || (val.length === 0 && generics.length === 0)) { + if (name === '*' || (name.length === 0 && generics.length === 0)) { return; } - var paths = val.split("::"); + var paths = name.split("::"); removeEmptyStringsFromArray(paths); // In case we only have something like `
`, there is no name but it remains valid.
if (paths.length === 0) {
paths = [""];
}
elems.push({
- name: val,
+ name: name,
fullPath: paths,
pathWithoutLast: paths.slice(0, paths.length - 1),
pathLast: paths[paths.length - 1],
@@ -257,14 +257,14 @@ window.initSearch = function(rawSearchIndex) {
var start = query.pos;
var end = start;
// We handle the strings on their own mostly to make code easier to follow.
- if (query.val[query.pos] === "\"") {
+ if (query.userQuery[query.pos] === "\"") {
start += 1;
getStringElem(query, isInGenerics);
end = query.pos - 1;
skipWhitespaces(query);
} else {
while (query.pos < query.length) {
- var c = query.val[query.pos];
+ var c = query.userQuery[query.pos];
if (isStopCharacter(c) || isSpecialStartCharacter(c)) {
break;
}
@@ -281,17 +281,17 @@ window.initSearch = function(rawSearchIndex) {
skipWhitespaces(query);
}
}
- if (query.pos < query.length && query.val[query.pos] === "<") {
+ if (query.pos < query.length && query.userQuery[query.pos] === "<") {
getItemsBefore(query, generics, ">");
}
if (start >= end && generics.length === 0) {
return;
}
- createQueryElement(query, elems, query.val.slice(start, end), generics);
+ createQueryElement(query, elems, query.userQuery.slice(start, end), generics);
}
function getItemsBefore(query, elems, limit) {
while (query.pos < query.length) {
- var c = query.val[query.pos];
+ var c = query.userQuery[query.pos];
if (c === limit) {
break;
} else if (isSpecialStartCharacter(c) || c === ":") {
@@ -307,7 +307,7 @@ window.initSearch = function(rawSearchIndex) {
var c, before;
while (query.pos < query.length) {
- c = query.val[query.pos];
+ c = query.userQuery[query.pos];
if (isStopCharacter(c)) {
if (c === ",") {
query.pos += 1;
@@ -331,14 +331,14 @@ window.initSearch = function(rawSearchIndex) {
getNextElem(query, query.elems, false);
if (query.elems.length === before) {
// Nothing was added, let's check it's not because of a solo ":"!
- if (query.pos >= query.length || query.val[query.pos] !== ":") {
+ if (query.pos >= query.length || query.userQuery[query.pos] !== ":") {
break;
}
query.pos += 1;
}
}
while (query.pos < query.length) {
- c = query.val[query.pos];
+ c = query.userQuery[query.pos];
if (query.args.length === 0 && c === "(") {
if (query.elemName === null && query.elems.length === 1) {
query.elemName = query.elems.pop();
@@ -364,11 +364,11 @@ window.initSearch = function(rawSearchIndex) {
return NO_TYPE_FILTER;
}
- val = val.trim();
+ userQuery = userQuery.trim();
var query = {
- original: val,
- val: val.toLowerCase(),
- length: val.length,
+ original: userQuery,
+ userQuery: userQuery.toLowerCase(),
+ length: userQuery.length,
pos: 0,
typeFilter: null,
elems: [],
@@ -386,7 +386,7 @@ window.initSearch = function(rawSearchIndex) {
literalSearch: false,
error: null,
};
- query.id = val;
+ query.id = userQuery;
try {
parseInput(query);
} catch (err) {
@@ -405,9 +405,9 @@ window.initSearch = function(rawSearchIndex) {
if (query.elemName !== null) {
query.foundElems += 1;
}
- if (query.foundElems === 0 && val.length !== 0) {
+ if (query.foundElems === 0 && userQuery.length !== 0) {
// In this case, we'll simply keep whatever was entered by the user...
- createQueryElement(query, query.elems, val, []);
+ createQueryElement(query, query.elems, userQuery, []);
query.foundElems += 1;
}
if (query.typeFilter !== null) {
@@ -422,8 +422,8 @@ window.initSearch = function(rawSearchIndex) {
query.elemName = null;
}
if (query.elemName !== null || query.elems.length === 1) {
- val = query.elemName || query.elems[0];
- query.nameSplit = typeof val.path === "undefined" ? null : val.path;
+ userQuery = query.elemName || query.elems[0];
+ query.nameSplit = typeof userQuery.path === "undefined" ? null : userQuery.path;
}
return query;
}
@@ -493,7 +493,7 @@ window.initSearch = function(rawSearchIndex) {
function sortResults(results, isType) {
var nameSplit = queryInfo.nameSplit;
- var query = queryInfo.val;
+ var query = queryInfo.userQuery;
var ar = [];
for (var entry in results) {
if (hasOwnPropertyRustdoc(results, entry)) {
@@ -1344,7 +1344,7 @@ window.initSearch = function(rawSearchIndex) {
output.className = "search-failed" + extraClass;
output.innerHTML = "No results :(
" +
"Try on DuckDuckGo?
" +
"Or try looking in one of these:
", returned: [], typeFilter: -1, - val: "
", + userQuery: "
", error: null, }, { @@ -75,7 +75,7 @@ const PARSED = [ original: 'A, E>', returned: [], typeFilter: -1, - val: 'a, e>', + userQuery: 'a, e>', error: null, } ]; diff --git a/src/test/rustdoc-js-std/parser-in_args.js b/src/test/rustdoc-js-std/parser-in_args.js index 6542319458f..88761771d9d 100644 --- a/src/test/rustdoc-js-std/parser-in_args.js +++ b/src/test/rustdoc-js-std/parser-in_args.js @@ -17,7 +17,7 @@ const PARSED = [ original: "(whatever)", returned: [], typeFilter: -1, - val: "(whatever)", + userQuery: "(whatever)", error: null, }, { @@ -44,7 +44,7 @@ const PARSED = [ original: "(
)", returned: [], typeFilter: -1, - val: "(
)", + userQuery: "(
)", error: null, }, ]; diff --git a/src/test/rustdoc-js-std/parser-invalid.js b/src/test/rustdoc-js-std/parser-invalid.js index a94792b0694..b5d96e9f507 100644 --- a/src/test/rustdoc-js-std/parser-invalid.js +++ b/src/test/rustdoc-js-std/parser-invalid.js @@ -37,7 +37,7 @@ const PARSED = [ }, ], typeFilter: -1, - val: "->
(p2)", + userQuery: "->
(p2)", error: null, }, { @@ -65,7 +65,7 @@ const PARSED = [ original: "(p -> p2", returned: [], typeFilter: -1, - val: "(p -> p2", + userQuery: "(p -> p2", error: null, }, { @@ -86,7 +86,7 @@ const PARSED = [ original: "a b", returned: [], typeFilter: -1, - val: "a b", + userQuery: "a b", error: null, }, { @@ -122,7 +122,7 @@ const PARSED = [ original: "a,b(c)", returned: [], typeFilter: -1, - val: "a,b(c)", + userQuery: "a,b(c)", error: null, }, ]; diff --git a/src/test/rustdoc-js-std/parser-literal.js b/src/test/rustdoc-js-std/parser-literal.js index 0624930f14a..1a70bafbf5e 100644 --- a/src/test/rustdoc-js-std/parser-literal.js +++ b/src/test/rustdoc-js-std/parser-literal.js @@ -25,7 +25,7 @@ const PARSED = [ original: "\"R\"
", returned: [], typeFilter: -1, - val: "\"r\"
", + userQuery: "\"r\"
",
error: null,
}
];
diff --git a/src/test/rustdoc-js-std/parser-paths.js b/src/test/rustdoc-js-std/parser-paths.js
index 9422eada9bc..980a396ba7f 100644
--- a/src/test/rustdoc-js-std/parser-paths.js
+++ b/src/test/rustdoc-js-std/parser-paths.js
@@ -17,7 +17,7 @@ const PARSED = [
original: "A::B",
returned: [],
typeFilter: -1,
- val: "a::b",
+ userQuery: "a::b",
error: null,
},
{
@@ -36,7 +36,7 @@ const PARSED = [
original: '::A::B',
returned: [],
typeFilter: -1,
- val: '::a::b',
+ userQuery: '::a::b',
error: null,
},
{
@@ -64,7 +64,7 @@ const PARSED = [
original: 'A::B::,C',
returned: [],
typeFilter: -1,
- val: 'a::b::,c',
+ userQuery: 'a::b::,c',
error: null,
},
{
@@ -100,7 +100,7 @@ const PARSED = [
original: 'A::B:: ",
returned: [],
typeFilter: -1,
- val: "\"p\" ",
+ userQuery: "\"p\" ",
error: null,
},
];
diff --git a/src/test/rustdoc-js-std/parser-returned.js b/src/test/rustdoc-js-std/parser-returned.js
index 92b378f1393..ceecda67050 100644
--- a/src/test/rustdoc-js-std/parser-returned.js
+++ b/src/test/rustdoc-js-std/parser-returned.js
@@ -25,7 +25,7 @@ const PARSED = [
],
}],
typeFilter: -1,
- val: "-> ",
+ userQuery: "-> ",
error: null,
},
{
@@ -44,7 +44,7 @@ const PARSED = [
generics: [],
}],
typeFilter: -1,
- val: "-> p",
+ userQuery: "-> p",
error: null,
},
];
diff --git a/src/tools/rustdoc-js/tester.js b/src/tools/rustdoc-js/tester.js
index 207ddc944de..5b051523cea 100644
--- a/src/tools/rustdoc-js/tester.js
+++ b/src/tools/rustdoc-js/tester.js
@@ -296,7 +296,7 @@ function checkFieldNeededFields(fullPath, expected, error_text, queryName, posit
"original",
"returned",
"typeFilter",
- "val",
+ "userQuery",
"error",
];
} else if (fullPath.endsWith("elems") || fullPath.endsWith("generics")) {