(a: Node, b: Node)
| 15 | * and the comparison of declarations and rule selectors. |
| 16 | */ |
| 17 | export 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`. */ |
| 53 | function isDeclaration(node: Node): node is Declaration { |
nothing calls this directly
no test coverage detected