3
3
4
4
// Local js definitions:
5
5
/* global addClass, onEachLazy, removeClass, browserSupportsHistoryApi */
6
- /* global updateLocalStorage, getVar */
6
+ /* global updateLocalStorage, getVar, nonnull */
7
7
8
- // Eventually fix this.
9
- // @ts -nocheck
10
8
11
9
"use strict" ;
12
10
@@ -29,6 +27,14 @@ function closeSidebarIfMobile() {
29
27
}
30
28
}
31
29
30
+ /**
31
+ * @param {rustdoc.Dir } elem
32
+ * @param {HTMLElement } parent
33
+ * @param {string } fullPath
34
+ * @param {boolean } hasFoundFile
35
+ *
36
+ * @returns {boolean } - new value for hasFoundFile
37
+ */
32
38
function createDirEntry ( elem , parent , fullPath , hasFoundFile ) {
33
39
const dirEntry = document . createElement ( "details" ) ;
34
40
const summary = document . createElement ( "summary" ) ;
@@ -95,7 +101,7 @@ window.rustdocToggleSrcSidebar = () => {
95
101
// This function is called from "src-files.js", generated in `html/render/write_shared.rs`.
96
102
// eslint-disable-next-line no-unused-vars
97
103
function createSrcSidebar ( ) {
98
- const container = document . querySelector ( "nav.sidebar" ) ;
104
+ const container = nonnull ( document . querySelector ( "nav.sidebar" ) ) ;
99
105
100
106
const sidebar = document . createElement ( "div" ) ;
101
107
sidebar . id = "src-sidebar" ;
@@ -111,6 +117,7 @@ function createSrcSidebar() {
111
117
// Focus on the current file in the source files sidebar.
112
118
const selected_elem = sidebar . getElementsByClassName ( "selected" ) [ 0 ] ;
113
119
if ( typeof selected_elem !== "undefined" ) {
120
+ // @ts -expect-error
114
121
selected_elem . focus ( ) ;
115
122
}
116
123
}
@@ -130,19 +137,20 @@ function highlightSrcLines() {
130
137
to = from ;
131
138
from = tmp ;
132
139
}
133
- let elem = document . getElementById ( from ) ;
140
+ const from_s = "" + from ;
141
+ let elem = document . getElementById ( from_s ) ;
134
142
if ( ! elem ) {
135
143
return ;
136
144
}
137
- const x = document . getElementById ( from ) ;
145
+ const x = document . getElementById ( from_s ) ;
138
146
if ( x ) {
139
147
x . scrollIntoView ( ) ;
140
148
}
141
149
onEachLazy ( document . querySelectorAll ( "a[data-nosnippet]" ) , e => {
142
150
removeClass ( e , "line-highlighted" ) ;
143
151
} ) ;
144
152
for ( let i = from ; i <= to ; ++ i ) {
145
- elem = document . getElementById ( i ) ;
153
+ elem = document . getElementById ( "" + i ) ;
146
154
if ( ! elem ) {
147
155
break ;
148
156
}
@@ -153,11 +161,12 @@ function highlightSrcLines() {
153
161
const handleSrcHighlight = ( function ( ) {
154
162
let prev_line_id = 0 ;
155
163
164
+ /** @type {function(string): void } */
156
165
const set_fragment = name => {
157
166
const x = window . scrollX ,
158
167
y = window . scrollY ;
159
168
if ( browserSupportsHistoryApi ( ) ) {
160
- history . replaceState ( null , null , "#" + name ) ;
169
+ history . replaceState ( null , "" , "#" + name ) ;
161
170
highlightSrcLines ( ) ;
162
171
} else {
163
172
location . replace ( "#" + name ) ;
@@ -166,6 +175,7 @@ const handleSrcHighlight = (function() {
166
175
window . scrollTo ( x , y ) ;
167
176
} ;
168
177
178
+ // @ts -expect-error
169
179
return ev => {
170
180
let cur_line_id = parseInt ( ev . target . id , 10 ) ;
171
181
// This event handler is attached to the entire line number column, but it should only
@@ -191,7 +201,7 @@ const handleSrcHighlight = (function() {
191
201
} else {
192
202
prev_line_id = cur_line_id ;
193
203
194
- set_fragment ( cur_line_id ) ;
204
+ set_fragment ( "" + cur_line_id ) ;
195
205
}
196
206
} ;
197
207
} ( ) ) ;
0 commit comments