@@ -33,6 +33,20 @@ function onEachBtwn(arr, func, funcBtwn) {
33
33
}
34
34
}
35
35
36
+ /**
37
+ * Convert any `undefined` to `null`.
38
+ *
39
+ * @template T
40
+ * @param {T|undefined } x
41
+ * @returns {T|null }
42
+ */
43
+ function undef2null ( x ) {
44
+ if ( x !== undefined ) {
45
+ return x ;
46
+ }
47
+ return null ;
48
+ }
49
+
36
50
// ==================== Core search logic begin ====================
37
51
// This mapping table should match the discriminants of
38
52
// `rustdoc::formats::item_type::ItemType` type in Rust.
@@ -2133,8 +2147,7 @@ class DocSearch {
2133
2147
// convert `rawPaths` entries into object form
2134
2148
// generate normalizedPaths for function search mode
2135
2149
let len = rawPaths . length ;
2136
- const lastPathU = itemPaths . get ( 0 ) ;
2137
- let lastPath = lastPathU === undefined ? null : lastPathU ;
2150
+ let lastPath = undef2null ( itemPaths . get ( 0 ) ) ;
2138
2151
for ( let i = 0 ; i < len ; ++ i ) {
2139
2152
const elem = rawPaths [ i ] ;
2140
2153
const ty = elem [ 0 ] ;
@@ -2192,12 +2205,11 @@ class DocSearch {
2192
2205
}
2193
2206
const name = itemNames [ i ] === "" ? lastName : itemNames [ i ] ;
2194
2207
const word = itemNames [ i ] === "" ? lastWord : itemNames [ i ] . toLowerCase ( ) ;
2195
- /** @type {string } */
2196
- // @ts -expect-error
2197
- const path = itemPaths . has ( i ) ? itemPaths . get ( i ) : lastPath ;
2198
- const paramNames = itemParamNames . has ( i ) ?
2199
- // @ts -expect-error
2200
- itemParamNames . get ( i ) . split ( "," ) :
2208
+ const pathU = itemPaths . get ( i ) ;
2209
+ const path = pathU !== undefined ? pathU : lastPath ;
2210
+ const paramNameString = itemParamNames . get ( i ) ;
2211
+ const paramNames = paramNameString !== undefined ?
2212
+ paramNameString . split ( "," ) :
2201
2213
lastParamNames ;
2202
2214
const type = itemFunctionDecoder . next ( ) ;
2203
2215
if ( type !== null ) {
@@ -2239,8 +2251,7 @@ class DocSearch {
2239
2251
word,
2240
2252
normalizedName,
2241
2253
bitIndex,
2242
- implDisambiguator : implDisambiguator . has ( i ) ?
2243
- implDisambiguator . get ( i ) : null ,
2254
+ implDisambiguator : undef2null ( implDisambiguator . get ( i ) ) ,
2244
2255
} ;
2245
2256
this . nameTrie . insert ( normalizedName , id , this . tailTable ) ;
2246
2257
id += 1 ;
0 commit comments