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

SAP / less-openui5 / 13906243876

17 Mar 2025 05:43PM UTC coverage: 94.719%. Remained the same
13906243876

Pull #391

github

web-flow
Merge dd2a4f8ee into b8693f39a
Pull Request #391: Bump actions/setup-node from 4.2.0 to 4.3.0

501 of 560 branches covered (89.46%)

Branch coverage included in aggregate %.

916 of 936 relevant lines covered (97.86%)

206.89 hits per line

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

96.15
/lib/diff.js
1
"use strict";
2

3
// Regular expression to match type of property in order to check whether
4
// it possibly contains color values.
5
const rProperties = /(color|background|border|text|outline)(?!-(width|radius|offset|style|align|overflow|transform))(-(color|shadow|image))?/;
1✔
6

7
function selectorEquals(s1, s2) {
8
        // Make sure there is the same number of select parts
9
        if (s1.length !== s2.length) {
343!
10
                return false;
×
11
        }
12

13
        // Check if all the parts are the same strings
14
        for (let i = 0; i < s1.length; i++) {
343✔
15
                if (s1[i] !== s2[i]) {
455✔
16
                        return false;
27✔
17
                }
18
        }
19

20
        return true;
316✔
21
}
22

23
function Diffing(oBase, oCompare) {
24
        this.oBase = oBase;
105✔
25
        this.oCompare = oCompare;
105✔
26

27
        this.oDiff = {
105✔
28
                type: "stylesheet",
29
                stylesheet: {
30
                        rules: []
31
                },
32
        };
33

34
        this.oStack = {
105✔
35
                type: "stylesheet",
36
                stylesheet: {
37
                        rules: []
38
                },
39
        };
40
}
41

42
Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) {
1✔
43
        const aDiffRules = [];
129✔
44
        let iBaseNode; let iCompareNode;
45

46
        for (iBaseNode = 0, iCompareNode = 0; iBaseNode < oBaseRules.length; iBaseNode++, iCompareNode++) {
129✔
47
                const oBaseNode = oBaseRules[iBaseNode];
368✔
48
                let oCompareNode = oCompareRules[iCompareNode];
368✔
49
                let oDiffNode = null;
368✔
50

51
                // Add all different compare nodes to stack and check for next one
52
                while (oCompareNode && oBaseNode.type !== oCompareNode.type) {
368✔
53
                        this.oStack.stylesheet.rules.push(oCompareNode);
6✔
54
                        iCompareNode++;
6✔
55
                        oCompareNode = oCompareRules[iCompareNode];
6✔
56
                }
57

58
                if (oCompareNode && oBaseNode.type === "comment") {
368✔
59
                        const sBaseComment = oBaseNode.comment;
18✔
60
                        const sCompareComment = oCompareNode.comment;
18✔
61

62
                        if (sBaseComment !== sCompareComment) {
18✔
63
                                oDiffNode = oCompareNode;
1✔
64
                        }
65
                }
66

67
                if (oBaseNode.type === "rule") {
368✔
68
                        // Add all rules with different selector to stack and check for next one
69
                        while (oCompareNode && (oCompareNode.type !== "rule" || !selectorEquals(oBaseNode.selectors, oCompareNode.selectors))) {
317✔
70
                                this.oStack.stylesheet.rules.push(oCompareNode);
35✔
71
                                iCompareNode++;
35✔
72
                                oCompareNode = oCompareRules[iCompareNode];
35✔
73
                        }
74

75
                        const aBaseDeclarations = oBaseNode.declarations;
317✔
76
                        const aCompareDeclarations = oCompareNode && oCompareNode.declarations;
317✔
77
                        for (let j = 0; j < aBaseDeclarations.length; j++) {
317✔
78
                                const oBaseDeclaration = aBaseDeclarations[j];
410✔
79
                                const oCompareDeclaration = aCompareDeclarations && aCompareDeclarations[j];
410✔
80

81
                                if (oCompareDeclaration && oBaseDeclaration.type === "declaration") {
410✔
82
                                        // TODO: Also check for different node and add to stack???
83
                                        if (oBaseDeclaration.type === oCompareDeclaration.type) {
397!
84
                                                if (oBaseDeclaration.property === oCompareDeclaration.property) {
397!
85
                                                        // Always add color properties to diff to prevent unexpected CSS overrides
86
                                                        // due to selectors with more importance
87
                                                        if (oBaseDeclaration.value !== oCompareDeclaration.value ||
397✔
88
                                                                        oCompareDeclaration.property.match(rProperties)) {
89
                                                                // Add compared rule to diff
90
                                                                if (!oDiffNode) {
222✔
91
                                                                        oDiffNode = oCompareNode;
214✔
92
                                                                        oDiffNode.declarations = [];
214✔
93
                                                                }
94
                                                                oDiffNode.declarations.push(oCompareDeclaration);
222✔
95
                                                        }
96
                                                }
97
                                        }
98
                                }
99
                        }
100
                } else if (oCompareNode && oBaseNode.type === "media") {
51✔
101
                        const aMediaDiffRules = this.diffRules(oBaseNode.rules, oCompareNode.rules);
24✔
102

103
                        if (aMediaDiffRules.length > 0) {
24✔
104
                                oDiffNode = oCompareNode;
16✔
105
                                oDiffNode.rules = aMediaDiffRules;
16✔
106
                        }
107
                }
108

109
                if (oDiffNode) {
368✔
110
                        aDiffRules.push(oDiffNode);
231✔
111
                }
112
        }
113

114
        // Add all leftover compare nodes to stack
115
        for (; iCompareNode < oCompareRules.length; iCompareNode++) {
129✔
116
                this.oStack.stylesheet.rules.push(oCompareRules[iCompareNode]);
24✔
117
        }
118

119
        return aDiffRules;
129✔
120
};
121

122
Diffing.prototype.run = function() {
1✔
123
        const oBaseRules = this.oBase.stylesheet.rules;
105✔
124
        const oCompareRules = this.oCompare.stylesheet.rules;
105✔
125

126
        this.oDiff.stylesheet.rules = this.diffRules(oBaseRules, oCompareRules);
105✔
127

128
        return {
105✔
129
                diff: this.oDiff,
130
                stack: this.oStack
131
        };
132
};
133

134

135
module.exports = function diff(oBase, oCompare) {
1✔
136
        return new Diffing(oBase, oCompare).run();
105✔
137
};
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