• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hybridsjs / hybrids / 9387127968

05 Jun 2024 03:38PM UTC coverage: 46.684% (-53.3%) from 99.956%
9387127968

Pull #258

github

web-flow
Merge e936aa704 into 36d6e398d
Pull Request #258: feat: remove `content` property & add shadow mode detection to render property

611 of 1778 branches covered (34.36%)

69 of 97 new or added lines in 9 files covered. (71.13%)

1169 existing lines in 25 files now uncovered.

1049 of 2247 relevant lines covered (46.68%)

32.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.58
/src/template/resolvers/array.js
1
import { getMeta, removeTemplate, getTemplateEnd } from "../utils.js";
2

3
export const arrayMap = new WeakMap();
2✔
4

5
function movePlaceholder(target, previousSibling) {
UNCOV
6
  const meta = getMeta(target);
×
UNCOV
7
  const startNode = meta.startNode;
×
UNCOV
8
  const endNode = getTemplateEnd(meta.endNode);
×
9

UNCOV
10
  previousSibling.parentNode.insertBefore(target, previousSibling.nextSibling);
×
11

UNCOV
12
  let prevNode = target;
×
UNCOV
13
  let node = startNode;
×
UNCOV
14
  while (node) {
×
UNCOV
15
    const nextNode = node.nextSibling;
×
UNCOV
16
    prevNode.parentNode.insertBefore(node, prevNode.nextSibling);
×
UNCOV
17
    prevNode = node;
×
UNCOV
18
    node = nextNode !== endNode.nextSibling && nextNode;
×
19
  }
20
}
21

22
export default function resolveArray(
23
  host,
24
  target,
25
  value,
26
  resolveValue,
27
  useLayout,
28
  shadow,
29
) {
30
  let lastEntries = arrayMap.get(target);
86✔
31
  const entries = value.map((item, index) => ({
91✔
32
    id: hasOwnProperty.call(item, "id") ? item.id : index,
91!
33
    value: item,
34
    placeholder: null,
35
    available: true,
36
  }));
37

38
  arrayMap.set(target, entries);
86✔
39

40
  if (lastEntries) {
86✔
41
    const ids = new Set();
56✔
42
    for (const entry of entries) {
56✔
43
      ids.add(entry.id);
61✔
44
    }
45

46
    lastEntries = lastEntries.filter((entry) => {
56✔
47
      if (!ids.has(entry.id)) {
60✔
48
        removeTemplate(entry.placeholder);
2✔
49
        entry.placeholder.parentNode.removeChild(entry.placeholder);
2✔
50
        return false;
2✔
51
      }
52

53
      return true;
58✔
54
    });
55
  }
56

57
  let previousSibling = target;
86✔
58
  const lastIndex = value.length - 1;
86✔
59
  const meta = getMeta(target);
86✔
60

61
  for (let index = 0; index < entries.length; index += 1) {
86✔
62
    const entry = entries[index];
91✔
63
    let matchedEntry;
64
    if (lastEntries) {
91✔
65
      for (let i = 0; i < lastEntries.length; i += 1) {
61✔
66
        if (lastEntries[i].available && lastEntries[i].id === entry.id) {
64✔
67
          matchedEntry = lastEntries[i];
58✔
68
          break;
58✔
69
        }
70
      }
71
    }
72

73
    if (matchedEntry) {
91✔
74
      matchedEntry.available = false;
58✔
75
      entry.placeholder = matchedEntry.placeholder;
58✔
76

77
      if (entry.placeholder.previousSibling !== previousSibling) {
58!
UNCOV
78
        movePlaceholder(entry.placeholder, previousSibling);
×
79
      }
80
      if (matchedEntry.value !== entry.value) {
58✔
81
        resolveValue(
41✔
82
          host,
83
          entry.placeholder,
84
          entry.value,
85
          matchedEntry.value,
86
          useLayout,
87
          shadow,
88
        );
89
      }
90
    } else {
91
      entry.placeholder = globalThis.document.createTextNode("");
33✔
92
      previousSibling.parentNode.insertBefore(
33✔
93
        entry.placeholder,
94
        previousSibling.nextSibling,
95
      );
96
      resolveValue(
33✔
97
        host,
98
        entry.placeholder,
99
        entry.value,
100
        undefined,
101
        useLayout,
102
        shadow,
103
      );
104
    }
105

106
    previousSibling = getTemplateEnd(
91✔
107
      getMeta(entry.placeholder, {}).endNode || entry.placeholder,
91!
108
    );
109

110
    if (index === 0) meta.startNode = entry.placeholder;
91✔
111
    if (index === lastIndex) meta.endNode = previousSibling;
91✔
112
  }
113

114
  if (lastEntries) {
86✔
115
    for (const entry of lastEntries) {
56✔
116
      if (entry.available) {
58!
UNCOV
117
        removeTemplate(entry.placeholder);
×
UNCOV
118
        entry.placeholder.parentNode.removeChild(entry.placeholder);
×
119
      }
120
    }
121
  }
122
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc