MCPcopy Index your code
hub / github.com/css/csso / compareDeclarations

Function compareDeclarations

lib/restructure/utils.js:27–73  ·  view source on GitHub ↗
(declarations1, declarations2)

Source from the content-addressed store, hash-verified

25}
26
27export function compareDeclarations(declarations1, declarations2) {
28 const result = {
29 eq: [],
30 ne1: [],
31 ne2: [],
32 ne2overrided: []
33 };
34
35 const fingerprints = Object.create(null);
36 const declarations2hash = Object.create(null);
37
38 for (let cursor = declarations2.head; cursor; cursor = cursor.next) {
39 declarations2hash[cursor.data.id] = true;
40 }
41
42 for (let cursor = declarations1.head; cursor; cursor = cursor.next) {
43 const data = cursor.data;
44
45 if (data.fingerprint) {
46 fingerprints[data.fingerprint] = data.important;
47 }
48
49 if (declarations2hash[data.id]) {
50 declarations2hash[data.id] = false;
51 result.eq.push(data);
52 } else {
53 result.ne1.push(data);
54 }
55 }
56
57 for (let cursor = declarations2.head; cursor; cursor = cursor.next) {
58 const data = cursor.data;
59
60 if (declarations2hash[data.id]) {
61 // when declarations1 has an overriding declaration, this is not a difference
62 // unless no !important is used on prev and !important is used on the following
63 if (!hasOwnProperty.call(fingerprints, data.fingerprint) ||
64 (!fingerprints[data.fingerprint] && data.important)) {
65 result.ne2.push(data);
66 }
67
68 result.ne2overrided.push(data);
69 }
70 }
71
72 return result;
73}
74
75export function addSelectors(dest, source) {
76 source.forEach((sourceData) => {

Callers 1

processRuleFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…