about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-12-15 20:19:54 +0100
committerGitHub <noreply@github.com>2023-12-15 20:19:54 +0100
commitae9e08e65ee76fca37ee8104f1578abf19afa993 (patch)
tree12b0453a8fd7be8e3c9eff14aa3ab5af23ad51f2
parentd5213cf52e6beb55433b055c411a59291fcb2fad (diff)
parent552143c875d4bd037ae9bbd73440dfc77c6e6dee (diff)
downloadrust-ae9e08e65ee76fca37ee8104f1578abf19afa993.tar.gz
rust-ae9e08e65ee76fca37ee8104f1578abf19afa993.zip
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``
-rw-r--r--src/librustdoc/html/static/js/src-script.js15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/librustdoc/html/static/js/src-script.js b/src/librustdoc/html/static/js/src-script.js
index bbb0527a833..fc1d2d37845 100644
--- a/src/librustdoc/html/static/js/src-script.js
+++ b/src/librustdoc/html/static/js/src-script.js
@@ -146,12 +146,8 @@ function createSrcSidebar() {
     }
 }
 
-const lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/;
-
-function highlightSrcLines(match) {
-    if (typeof match === "undefined") {
-        match = window.location.hash.match(lineNumbersRegex);
-    }
+function highlightSrcLines() {
+    const match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
     if (!match) {
         return;
     }
@@ -233,12 +229,7 @@ const handleSrcHighlight = (function() {
     };
 }());
 
-window.addEventListener("hashchange", () => {
-    const match = window.location.hash.match(lineNumbersRegex);
-    if (match) {
-        return highlightSrcLines(match);
-    }
-});
+window.addEventListener("hashchange", highlightSrcLines);
 
 onEachLazy(document.getElementsByClassName("src-line-numbers"), el => {
     el.addEventListener("click", handleSrcHighlight);