Passed
Push — develop ( bfb111...4fd4e2 )
by Xaver
01:12
created

lib/filters/genericnode.js (1 issue)

Checks whether a function inside a loop accesses variables mutated between iterations

Bug Major
1
define(['helper'], function (helper) {
2
  'use strict';
3
4
  return function (name, key, value, f) {
5
    var negate = false;
6
    var refresh;
7
8
    var label = document.createElement('label');
9
    var strong = document.createElement('strong');
10
    label.textContent = name + ': ';
11
    label.appendChild(strong);
12
13
    function run(d) {
14
      var o = helper.dictGet(d, key.slice(0));
15
16
      if (f) {
17
        o = f(o);
18
      }
19
20
      return o === value ? !negate : negate;
21
    }
22
23
    function setRefresh(r) {
24
      refresh = r;
25
    }
26
27
    function draw(el) {
28
      if (negate) {
29
        el.classList.add('not');
30
      } else {
31
        el.classList.remove('not');
32
      }
33
34
      strong.textContent = value;
0 ignored issues
show
The variable strong is changed as part of the for-each loop for example by document.createElement("strong") on line 9. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
35
    }
36
37
    function render(el) {
38
      el.appendChild(label);
39
      draw(el);
40
41
      label.onclick = function onclick() {
42
        negate = !negate;
43
44
        draw(el);
45
46
        if (refresh) {
47
          refresh();
48
        }
49
      };
50
    }
51
52
    function getKey() {
53
      return value.concat(name);
54
    }
55
56
    return {
57
      run: run,
58
      setRefresh: setRefresh,
59
      render: render,
60
      getKey: getKey
61
    };
62
  };
63
});
64