Fix implicit globals and remove dead code in core/js#3298
Conversation
- core.js: declare loop variable in `for (var i in _replace)` (was leaking i as implicit global) - view.class.js: declare `var result` in toHtml's pre_success (was leaking result as implicit global) - view.class.js: declare `var option` in handleViewAjax's graph zone loop (was leaking option as implicit global) - private.class.js: remove unused `var param = null` (dead code) These are pre-existing bugs in the var-based code, fixed without changing the surrounding declaration style. Found via ESLint (no-undef-init, no-unused-vars).
|
For context, while waiting for these PRs to be reviewed and merged,
|
|
Hi @limad, It looks like the changes from this PR have already been covered by the other PRs that were merged afterwards, and the files involved have significantly evolved since then. Given the current conflicts and the fact that the fixes seem to be already integrated elsewhere, this PR can probably be closed. |
|
Confirmed — just checked against upstream |
Summary
Three pre-existing minor bugs in
core/js/found while auditing the codebase. Each is a one-line change that does not modify the surrounding declaration style (still usingvarto match the existing code).Changes
core/js/core.js—for (i in _replace)was leakingias an implicit global onwindow. Now declared withvar i.core/js/view.class.js(toHtmlpre_success) —result = jeedom.view.handleViewAjax(...)was leakingresultas implicit global. Now declared withvar result.core/js/view.class.js(handleViewAjax graph zone loop) —option = configuration.replace(...)was leakingoptionas implicit global. Now declared withvar option.core/js/private.class.js—var param = null;declared but never read. Removed (dead code).Found via ESLint static analysis. Net diff: +3 / -4 lines across 3 files.
Why this matters
Implicit globals via assignment without declaration silently pollute
windowand can collide with other scripts. They also break under"use strict"mode (which is already declared in some Jeedom files likedesktop/js/log.js).Test plan
jeedom.view.toHtml— verify rendering unchangedjeedomUtils.getTemplateFileContentwith the_replaceparameter — verify replacements still workThis PR is the first in a series (see #3297 discussion) splitting the previously-too-large optimization PR into focused changes.