33
44// Local js definitions:
55/* global addClass, onEachLazy, removeClass, browserSupportsHistoryApi */
6- /* global updateLocalStorage, getVar */
6+ /* global updateLocalStorage, getVar, nonnull */
77
8- // Eventually fix this.
9- // @ts -nocheck
108
119"use strict" ;
1210
@@ -29,6 +27,14 @@ function closeSidebarIfMobile() {
2927 }
3028}
3129
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+ */
3238function createDirEntry ( elem , parent , fullPath , hasFoundFile ) {
3339 const dirEntry = document . createElement ( "details" ) ;
3440 const summary = document . createElement ( "summary" ) ;
@@ -95,7 +101,7 @@ window.rustdocToggleSrcSidebar = () => {
95101// This function is called from "src-files.js", generated in `html/render/write_shared.rs`.
96102// eslint-disable-next-line no-unused-vars
97103function createSrcSidebar ( ) {
98- const container = document . querySelector ( "nav.sidebar" ) ;
104+ const container = nonnull ( document . querySelector ( "nav.sidebar" ) ) ;
99105
100106 const sidebar = document . createElement ( "div" ) ;
101107 sidebar . id = "src-sidebar" ;
@@ -111,6 +117,7 @@ function createSrcSidebar() {
111117 // Focus on the current file in the source files sidebar.
112118 const selected_elem = sidebar . getElementsByClassName ( "selected" ) [ 0 ] ;
113119 if ( typeof selected_elem !== "undefined" ) {
120+ // @ts -expect-error
114121 selected_elem . focus ( ) ;
115122 }
116123}
@@ -130,19 +137,20 @@ function highlightSrcLines() {
130137 to = from ;
131138 from = tmp ;
132139 }
133- let elem = document . getElementById ( from ) ;
140+ const from_s = "" + from ;
141+ let elem = document . getElementById ( from_s ) ;
134142 if ( ! elem ) {
135143 return ;
136144 }
137- const x = document . getElementById ( from ) ;
145+ const x = document . getElementById ( from_s ) ;
138146 if ( x ) {
139147 x . scrollIntoView ( ) ;
140148 }
141149 onEachLazy ( document . querySelectorAll ( "a[data-nosnippet]" ) , e => {
142150 removeClass ( e , "line-highlighted" ) ;
143151 } ) ;
144152 for ( let i = from ; i <= to ; ++ i ) {
145- elem = document . getElementById ( i ) ;
153+ elem = document . getElementById ( "" + i ) ;
146154 if ( ! elem ) {
147155 break ;
148156 }
@@ -153,11 +161,12 @@ function highlightSrcLines() {
153161const handleSrcHighlight = ( function ( ) {
154162 let prev_line_id = 0 ;
155163
164+ /** @type {function(string): void } */
156165 const set_fragment = name => {
157166 const x = window . scrollX ,
158167 y = window . scrollY ;
159168 if ( browserSupportsHistoryApi ( ) ) {
160- history . replaceState ( null , null , "#" + name ) ;
169+ history . replaceState ( null , "" , "#" + name ) ;
161170 highlightSrcLines ( ) ;
162171 } else {
163172 location . replace ( "#" + name ) ;
@@ -166,6 +175,7 @@ const handleSrcHighlight = (function() {
166175 window . scrollTo ( x , y ) ;
167176 } ;
168177
178+ // @ts -expect-error
169179 return ev => {
170180 let cur_line_id = parseInt ( ev . target . id , 10 ) ;
171181 // This event handler is attached to the entire line number column, but it should only
@@ -191,7 +201,7 @@ const handleSrcHighlight = (function() {
191201 } else {
192202 prev_line_id = cur_line_id ;
193203
194- set_fragment ( cur_line_id ) ;
204+ set_fragment ( "" + cur_line_id ) ;
195205 }
196206 } ;
197207} ( ) ) ;
0 commit comments