MCPcopy Index your code
hub / github.com/angular/angular / compressNodeLocation

Function compressNodeLocation

packages/core/src/hydration/compression.ts:30–47  ·  view source on GitHub ↗
(referenceNode: string, path: NodeNavigationStep[])

Source from the content-addressed store, hash-verified

28 * 'nextSibling'], the function returns: `bf2n`.
29 */
30export 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

Callers 2

calcPathBetweenFunction · 0.90

Calls 2

joinMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…