MCPcopy Create free account
hub / github.com/angular/components / compareNodes

Function compareNodes

tools/postcss/compare-nodes.ts:17–50  ·  view source on GitHub ↗
(a: Node, b: Node)

Source from the content-addressed store, hash-verified

15 * and the comparison of declarations and rule selectors.
16 */
17export function compareNodes(a: Node, b: Node): boolean {
18 if (a.type !== b.type) {
19 return false;
20 }
21
22 if (isComment(a) && isComment(b)) {
23 return a.text === b.text;
24 }
25
26 // Types of A and B are always equal, but for type inferring we
27 // check both nodes again.
28 if (isDeclaration(a) && isDeclaration(b)) {
29 return a.prop === b.prop && a.value === b.value;
30 }
31
32 // We only check either rules or declarations. Since we check CSS,
33 // there cannot be any nested `atrule` or `rule` nodes.
34 if (!isRule(a) || !isRule(b)) {
35 return false;
36 }
37
38 const aNodes = a.nodes || [];
39 const bNodes = b.nodes || [];
40
41 if (aNodes.length !== bNodes.length) {
42 return false;
43 }
44
45 let equal = true;
46 for (let i = 0; i < aNodes.length; i++) {
47 equal = equal && compareNodes(aNodes[i], bNodes[i]);
48 }
49 return equal;
50}
51
52/** Asserts that a node is a `Declaration`. */
53function isDeclaration(node: Node): node is Declaration {

Callers

nothing calls this directly

Calls 3

isCommentFunction · 0.85
isDeclarationFunction · 0.85
isRuleFunction · 0.85

Tested by

no test coverage detected