Skip to content

refactor: simplify for loops to for...of in Server.js #5496

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

Merged
merged 3 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions client-src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ const parseURL = (resourceQuery) => {
if (typeof resourceQuery === "string" && resourceQuery !== "") {
const searchParams = resourceQuery.slice(1).split("&");

for (let i = 0; i < searchParams.length; i++) {
const pair = searchParams[i].split("=");
for (const searchParam of searchParams) {
const pair = searchParam.split("=");

result[pair[0]] = decodeURIComponent(pair[1]);
}
Expand Down Expand Up @@ -218,8 +218,7 @@ const logEnabledFeatures = (features) => {
let logString = "Server started:";

// Server started: Hot Module Replacement enabled, Live Reloading enabled, Overlay disabled.
for (let i = 0; i < listEnabledFeatures.length; i++) {
const key = listEnabledFeatures[i];
for (const key of listEnabledFeatures) {
logString += ` ${key} ${features[key] ? "enabled" : "disabled"},`;
}
// replace last comma with a period
Expand Down Expand Up @@ -471,8 +470,8 @@ const onSocketMessage = {

sendMessage("Warnings", printableWarnings);

for (let i = 0; i < printableWarnings.length; i++) {
log.warn(printableWarnings[i]);
for (const printableWarning of printableWarnings) {
log.warn(printableWarning);
}

const overlayWarningsSetting =
Expand Down Expand Up @@ -515,8 +514,8 @@ const onSocketMessage = {

sendMessage("Errors", printableErrors);

for (let i = 0; i < printableErrors.length; i++) {
log.error(printableErrors[i]);
for (const printableError of printableErrors) {
log.error(printableError);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not touch this file because it can be used in very old browsers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-akait
Ok, I've reverted the index.js fix.

}

const overlayErrorsSettings =
Expand Down
5 changes: 1 addition & 4 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3123,10 +3123,7 @@ class Server {
// always allow localhost host, for convenience
// allow if value is in allowedHosts
if (Array.isArray(allowedHosts) && allowedHosts.length > 0) {
for (let hostIdx = 0; hostIdx < allowedHosts.length; hostIdx++) {
/** @type {string} */
const allowedHost = allowedHosts[hostIdx];

for (const allowedHost of allowedHosts) {
if (allowedHost === value) {
return true;
}
Expand Down