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

tbranyen / diffhtml / 12189631411

05 Dec 2024 11:09PM CUT coverage: 98.581%. Remained the same
12189631411

Pull #349

github

web-flow
Merge 3ee60590a into f25d1c4ac
Pull Request #349: Bump path-to-regexp and express in /packages/diffhtml-static-sync

840 of 896 branches covered (93.75%)

4795 of 4864 relevant lines covered (98.58%)

427.67 hits per line

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

78.72
/packages/diffhtml-components/lib/before-mount.js
1
import componentWillUnmount from './lifecycle/component-will-unmount';
2✔
2
import { invokeRef, invokeRefsForVTree } from './lifecycle/invoke-refs';
2✔
3
import diff from './util/binding';
2✔
4
import { Transaction } from './util/types';
2✔
5

2✔
6
const { createNode, NodeCache, PATCH_TYPE, decodeEntities } = diff.Internals;
2✔
7
const uppercaseEx = /[A-Z]/g;
2✔
8

2✔
9
/**
2✔
10
 * @param {Transaction} transaction
2✔
11
 */
2✔
12
export default transaction => {
2✔
13
  if (transaction.aborted) {
215!
14
    return;
×
15
  }
×
16

215✔
17
  const { patches } = transaction;
215✔
18
  const { length } = patches;
215✔
19

215✔
20
  let i = 0;
215✔
21

215✔
22
  while (true) {
215✔
23
    const patchType = patches[i];
828✔
24

828✔
25
    // Exhausted remaining patches.
828✔
26
    if (i === length) {
828✔
27
      break;
215✔
28
    }
215✔
29

828✔
30
    switch(patchType) {
828✔
31
      case PATCH_TYPE.SET_ATTRIBUTE: {
828✔
32
        const vTree = patches[i + 1];
53✔
33
        const name = patches[i + 2];
53✔
34
        const value = patches[i + 3];
53✔
35

53✔
36
        uppercaseEx.lastIndex = 0;
53✔
37

53✔
38
        // Normalize uppercase attributes.
53✔
39
        if (uppercaseEx.test(name)) {
53!
40
          uppercaseEx.lastIndex = 0;
×
41

×
42
          const newName = name.replace(
×
43
            uppercaseEx,
×
44
            (/** @type {string} */ ch) => `-${ch.toLowerCase()}`,
×
45
          );
×
46

×
47
          if (value && typeof value === 'string') {
×
48
            const decodedValue = decodeEntities(value);
×
49

×
50
            if (NodeCache.has(vTree)) {
×
51
              /** @type {HTMLElement} */(NodeCache.get(vTree)).setAttribute(newName, decodedValue);
×
52
            }
×
53
          }
×
54
        }
×
55

53✔
56
        if (name === 'ref') {
53✔
57
          invokeRef(createNode(vTree), vTree);
4✔
58
        }
4✔
59

53✔
60
        i += 4;
53✔
61
        break;
53✔
62
      }
53✔
63

828✔
64
      case PATCH_TYPE.REMOVE_ATTRIBUTE: {
828!
65
        i += 3;
×
66
        break;
×
67
      }
×
68

828✔
69
      case PATCH_TYPE.REPLACE_CHILD: {
828✔
70
        const oldTree = patches[i + 2];
14✔
71

14✔
72
        componentWillUnmount(oldTree);
14✔
73

14✔
74
        i += 3;
14✔
75
        break;
14✔
76
      }
14✔
77

828✔
78
      case PATCH_TYPE.NODE_VALUE:
828✔
79
      case PATCH_TYPE.INSERT_BEFORE: {
828✔
80
        i += 4;
520✔
81
        break;
520✔
82
      }
520✔
83

828✔
84
      case PATCH_TYPE.REMOVE_CHILD: {
828✔
85
        const vTree = patches[i + 1];
26✔
86
        invokeRefsForVTree(vTree, null);
26✔
87
        componentWillUnmount(vTree);
26✔
88

26✔
89
        i += 2;
26✔
90
        break;
26✔
91
      }
26✔
92
    }
828✔
93
  }
828✔
94
};
2✔
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

© 2025 Coveralls, Inc