Skip to content

Commit ae9e08e

Browse files
authored
Rollup merge of #118977 - GuillaumeGomez:simplifysrc-script, r=notriddle
Simplify `src-script.js` code Instead of keeping this value in the global scope and still use it in the function in case it wasn't used outside, let's just use it inside the function. r? ``@notriddle``
2 parents d5213cf + 552143c commit ae9e08e

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/librustdoc/html/static/js/src-script.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,8 @@ function createSrcSidebar() {
146146
}
147147
}
148148

149-
const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
150-
151-
function highlightSrcLines(match) {
152-
if (typeof match === "undefined") {
153-
match = window.location.hash.match(lineNumbersRegex);
154-
}
149+
function highlightSrcLines() {
150+
const match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
155151
if (!match) {
156152
return;
157153
}
@@ -233,12 +229,7 @@ const handleSrcHighlight = (function() {
233229
};
234230
}());
235231

236-
window.addEventListener("hashchange", () => {
237-
const match = window.location.hash.match(lineNumbersRegex);
238-
if (match) {
239-
return highlightSrcLines(match);
240-
}
241-
});
232+
window.addEventListener("hashchange", highlightSrcLines);
242233

243234
onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
244235
el.addEventListener("click", handleSrcHighlight);

0 commit comments

Comments
 (0)