@@ -28,7 +28,7 @@ if (!Array.prototype.toSpliced) {
2828 * @template T
2929 * @param {Iterable<T> } arr
3030 * @param {function(T): Promise<any> } func
31- * @param {function(T): boolean } funcBtwn
31+ * @param {function(T): void } funcBtwn
3232 */
3333async function onEachBtwnAsync ( arr , func , funcBtwn ) {
3434 let skipped = true ;
@@ -2132,8 +2132,8 @@ class DocSearch {
21322132 *
21332133 * @param {rustdoc.ParsedQuery<rustdoc.ParserQueryElement> } parsedQuery
21342134 * - The parsed user query
2135- * @param {Object } filterCrates - Crate to search in if defined
2136- * @param {string } currentCrate - Current crate, to rank results from this crate higher
2135+ * @param {string|null } filterCrates - Crate to search in if defined
2136+ * @param {string|null } currentCrate - Current crate, to rank results from this crate higher
21372137 *
21382138 * @return {Promise<rustdoc.ResultsTable> }
21392139 */
@@ -2421,7 +2421,6 @@ class DocSearch {
24212421 await onEachBtwnAsync (
24222422 fnType . generics ,
24232423 nested => writeFn ( nested , result ) ,
2424- // @ts -expect-error
24252424 ( ) => pushText ( { name : ", " , highlighted : false } , result ) ,
24262425 ) ;
24272426 pushText ( { name : sb , highlighted : fnType . highlighted } , result ) ;
@@ -2435,7 +2434,6 @@ class DocSearch {
24352434 prevHighlighted = ! ! value . highlighted ;
24362435 await writeFn ( value , result ) ;
24372436 } ,
2438- // @ts -expect-error
24392437 value => pushText ( {
24402438 name : " " ,
24412439 highlighted : prevHighlighted && value . highlighted ,
@@ -2454,7 +2452,6 @@ class DocSearch {
24542452 prevHighlighted = ! ! value . highlighted ;
24552453 await writeFn ( value , result ) ;
24562454 } ,
2457- // @ts -expect-error
24582455 value => pushText ( {
24592456 name : " " ,
24602457 highlighted : prevHighlighted && value . highlighted ,
@@ -2515,7 +2512,6 @@ class DocSearch {
25152512 await onEachBtwnAsync (
25162513 fnType . generics ,
25172514 nested => writeFn ( nested , where ) ,
2518- // @ts -expect-error
25192515 ( ) => pushText ( { name : " + " , highlighted : false } , where ) ,
25202516 ) ;
25212517 if ( where . length > 0 ) {
@@ -2545,7 +2541,6 @@ class DocSearch {
25452541 await onEachBtwnAsync (
25462542 fnType . generics ,
25472543 value => writeFn ( value , result ) ,
2548- // @ts -expect-error
25492544 ( ) => pushText ( { name : ", " , highlighted : false } , result ) ,
25502545 ) ;
25512546 if ( fnType . generics . length > 1 ) {
@@ -2568,6 +2563,7 @@ class DocSearch {
25682563 async ( [ key , values ] ) => [ await this . getName ( key ) , values ] ,
25692564 ) ) ,
25702565 async ( [ name , values ] ) => {
2566+ // values[0] cannot be null due to length check
25712567 // @ts -expect-error
25722568 if ( values . length === 1 && values [ 0 ] . id < 0 &&
25732569 // @ts -expect-error
@@ -2593,14 +2589,12 @@ class DocSearch {
25932589 await onEachBtwnAsync (
25942590 values || [ ] ,
25952591 value => writeFn ( value , result ) ,
2596- // @ts -expect-error
25972592 ( ) => pushText ( { name : " + " , highlighted : false } , result ) ,
25982593 ) ;
25992594 if ( values . length !== 1 ) {
26002595 pushText ( { name : ")" , highlighted : false } , result ) ;
26012596 }
26022597 } ,
2603- // @ts -expect-error
26042598 ( ) => pushText ( { name : ", " , highlighted : false } , result ) ,
26052599 ) ;
26062600 }
@@ -2610,7 +2604,6 @@ class DocSearch {
26102604 await onEachBtwnAsync (
26112605 fnType . generics ,
26122606 value => writeFn ( value , result ) ,
2613- // @ts -expect-error
26142607 ( ) => pushText ( { name : ", " , highlighted : false } , result ) ,
26152608 ) ;
26162609 if ( hasBindings || fnType . generics . length > 0 ) {
@@ -2623,14 +2616,12 @@ class DocSearch {
26232616 await onEachBtwnAsync (
26242617 fnInputs ,
26252618 fnType => writeFn ( fnType , type ) ,
2626- // @ts -expect-error
26272619 ( ) => pushText ( { name : ", " , highlighted : false } , type ) ,
26282620 ) ;
26292621 pushText ( { name : " -> " , highlighted : false } , type ) ;
26302622 await onEachBtwnAsync (
26312623 fnOutput ,
26322624 fnType => writeFn ( fnType , type ) ,
2633- // @ts -expect-error
26342625 ( ) => pushText ( { name : ", " , highlighted : false } , type ) ,
26352626 ) ;
26362627
@@ -2765,7 +2756,7 @@ class DocSearch {
27652756 * @this {DocSearch}
27662757 * @param {Array<rustdoc.PlainResultObject|null> } results
27672758 * @param {"sig"|"elems"|"returned"|null } typeInfo
2768- * @param {string } preferredCrate
2759+ * @param {string|null } preferredCrate
27692760 * @param {Set<string> } duplicates
27702761 * @returns {AsyncGenerator<rustdoc.ResultObject, number> }
27712762 */
@@ -3037,10 +3028,8 @@ class DocSearch {
30373028 ) ) {
30383029 continue ;
30393030 }
3040- // @ts -expect-error
3041- if ( fnType . id < 0 ) {
3031+ if ( fnType . id !== null && fnType . id < 0 ) {
30423032 const highlightedGenerics = unifyFunctionTypes (
3043- // @ts -expect-error
30443033 whereClause [ ( - fnType . id ) - 1 ] ,
30453034 queryElems ,
30463035 whereClause ,
@@ -3903,7 +3892,7 @@ class DocSearch {
39033892 const innerRunNameQuery =
39043893 /**
39053894 * @this {DocSearch}
3906- * @param {string } currentCrate
3895+ * @param {string|null } currentCrate
39073896 * @returns {AsyncGenerator<rustdoc.ResultObject> }
39083897 */
39093898 async function * ( currentCrate ) {
@@ -4145,7 +4134,7 @@ class DocSearch {
41454134 * @param {rustdoc.ParserQueryElement[] } inputs
41464135 * @param {rustdoc.ParserQueryElement[] } output
41474136 * @param {"sig"|"elems"|"returned"|null } typeInfo
4148- * @param {string } currentCrate
4137+ * @param {string|null } currentCrate
41494138 * @returns {AsyncGenerator<rustdoc.ResultObject> }
41504139 */
41514140 async function * ( inputs , output , typeInfo , currentCrate ) {
@@ -5180,7 +5169,7 @@ function makeTab(tabNb, text, results, query, isTypeSearch, goToFirst) {
51805169 * @param {DocSearch } docSearch
51815170 * @param {rustdoc.ResultsTable } results
51825171 * @param {boolean } goToFirst
5183- * @param {string } filterCrates
5172+ * @param {string|null } filterCrates
51845173 */
51855174async function showResults ( docSearch , results , goToFirst , filterCrates ) {
51865175 const search = window . searchState . outputElement ( ) ;
@@ -5253,6 +5242,8 @@ async function showResults(docSearch, results, goToFirst, filterCrates) {
52535242 }
52545243 const crateSearch = document . getElementById ( "crate-search" ) ;
52555244 if ( crateSearch ) {
5245+ // #crate-search is an input element
5246+ // @ts -expect-error
52565247 crateSearch . addEventListener ( "input" , updateCrate ) ;
52575248 }
52585249 search . appendChild ( tabsElem ) ;
@@ -5332,10 +5323,8 @@ async function search(forced) {
53325323
53335324 await showResults (
53345325 docSearch ,
5335- // @ts -expect-error
53365326 await docSearch . execQuery ( query , filterCrates , window . currentCrate ) ,
53375327 params . go_to_first ,
5338- // @ts -expect-error
53395328 filterCrates ) ;
53405329}
53415330
@@ -5412,27 +5401,33 @@ function registerSearchEvents() {
54125401 }
54135402 // up and down arrow select next/previous search result, or the
54145403 // search box if we're already at the top.
5404+ //
5405+ // the .focus() calls are safe because there's no kind of element
5406+ // that lacks .focus() that should be in the document.
54155407 if ( e . which === 38 ) { // up
5416- // @ts -expect-error
5417- const previous = document . activeElement . previousElementSibling ;
5418- if ( previous ) {
5419- // @ts -expect-error
5420- previous . focus ( ) ;
5421- } else {
5422- searchState . focus ( ) ;
5408+ const active = document . activeElement ;
5409+ if ( active ) {
5410+ const previous = active . previousElementSibling ;
5411+ if ( previous ) {
5412+ // @ts -expect-error
5413+ previous . focus ( ) ;
5414+ } else {
5415+ searchState . focus ( ) ;
5416+ }
54235417 }
54245418 e . preventDefault ( ) ;
54255419 } else if ( e . which === 40 ) { // down
5426- // @ts -expect-error
5427- const next = document . activeElement . nextElementSibling ;
5428- if ( next ) {
5429- // @ts -expect-error
5430- next . focus ( ) ;
5431- }
5432- // @ts -expect-error
5433- const rect = document . activeElement . getBoundingClientRect ( ) ;
5434- if ( window . innerHeight - rect . bottom < rect . height ) {
5435- window . scrollBy ( 0 , rect . height ) ;
5420+ const active = document . activeElement ;
5421+ if ( active ) {
5422+ const next = active . nextElementSibling ;
5423+ if ( next ) {
5424+ // @ts -expect-error
5425+ next . focus ( ) ;
5426+ }
5427+ const rect = active . getBoundingClientRect ( ) ;
5428+ if ( window . innerHeight - rect . bottom < rect . height ) {
5429+ window . scrollBy ( 0 , rect . height ) ;
5430+ }
54365431 }
54375432 e . preventDefault ( ) ;
54385433 } else if ( e . which === 37 ) { // left
@@ -5456,7 +5451,9 @@ function registerSearchEvents() {
54565451 } ) ;
54575452}
54585453
5459- // @ts -expect-error
5454+ /**
5455+ * @param {Event & { target: HTMLInputElement } } ev
5456+ */
54605457function updateCrate ( ev ) {
54615458 if ( ev . target . value === "all crates" ) {
54625459 // If we don't remove it from the URL, it'll be picked up again by the search.
0 commit comments