(referenceNode: string, path: NodeNavigationStep[])
| 28 | * 'nextSibling'], the function returns: `bf2n`. |
| 29 | */ |
| 30 | export function compressNodeLocation(referenceNode: string, path: NodeNavigationStep[]): string { |
| 31 | const result: Array<string | number> = [referenceNode]; |
| 32 | for (const segment of path) { |
| 33 | const lastIdx = result.length - 1; |
| 34 | if (lastIdx > 0 && result[lastIdx - 1] === segment) { |
| 35 | // An empty string in a count slot represents 1 occurrence of an instruction. |
| 36 | const value = (result[lastIdx] || 1) as number; |
| 37 | result[lastIdx] = value + 1; |
| 38 | } else { |
| 39 | // Adding a new segment to the path. |
| 40 | // Using an empty string in a counter field to avoid encoding `1`s |
| 41 | // into the path, since they are implicit (e.g. `f1n1` vs `fn`), so |
| 42 | // it's enough to have a single char in this case. |
| 43 | result.push(segment, ''); |
| 44 | } |
| 45 | } |
| 46 | return result.join(''); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Helper function that reverts the `compressNodeLocation` and transforms a given |
no test coverage detected
searching dependent graphs…