-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS cleanup #72294
JS cleanup #72294
Conversation
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fundamentally this looks like a reasonable cleanup.
I'm not sure of the value of the window.FooBar
over function FooBar
but I'm assuming you know more than I. The lint fixes look right, but again I'm not the best at JS.
r=me modulo the tweaks
src/librustdoc/html/static/main.js
Outdated
|
||
url += "/" + document.getElementsByClassName("version-selector")[0].value + stripped; | ||
url += "/" + document.getElementsByClassName("version-selector")[0].value + stripped; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think tidy dislikes this line.
@@ -450,7 +450,7 @@ function defocusSearchBar() { | |||
set_fragment(cur_line_id); | |||
} | |||
} | |||
})(); | |||
}()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this isn't bad, it seems spurious in a "move code" commit rather than a cleanup one. You can just resolve this if you don't care, otherwise move it to a different commit when you next rebase.
@@ -27,14 +27,15 @@ function removeClass(elem, className) { | |||
function onEach(arr, func, reversed) { | |||
if (arr && arr.length > 0 && func) { | |||
var length = arr.length; | |||
var i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really necessary? Each i
is local to the loop so declaring it out here makes reasoning the loop harder.
Edit: Also, is there a fold construct in JS? This simple loop can be made even simpler with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS var
s don't seem to understand the principle of scope. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JS a var
is hoisted to the top of the function. The new let
and const
don't have this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re: fold, yes, browsers implemented Array.prototype.reduce() a long time ago.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
Much like Iter
and for
loops are equivalent perf in Rust, reduce
and map
are equivalent in performance to for
loops in JS for similar reasons. They are, however, eagerly evaluated! Not lazy.
☔ The latest upstream changes (presumably #72422) made this pull request unmergeable. Please resolve the merge conflicts. |
867b5e6
to
bea0ef9
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
bea0ef9
to
398511a
Compare
@bors: r=kinnison |
📌 Commit 398511a has been approved by |
Rollup of 6 pull requests Successful merges: - rust-lang#72270 (add a lint against references to packed fields) - rust-lang#72294 (JS cleanup) - rust-lang#72342 (Warn about unused crate deps) - rust-lang#72401 (Use correct function for detecting `const fn` in unsafety checking) - rust-lang#72581 (Allow unlabeled breaks from desugared `?` in labeled blocks) - rust-lang#72592 (Update books) Failed merges: r? @ghost
The goal here is just to improve the source code a bit. I recommend to review one commit at a time, otherwise it might not make much sense. :)
The biggest commit is the second one: to prevent to have "global" variables declared in
main.js
(and thus prevent name conflict or overwriting), I moved such code into anonymous functions.r? @kinnison
cc @rust-lang/rustdoc