* Inject a scope path's bindings into a result path. * This is used to preserve FOREACH iteration variable bindings when * inner MATCH operations create new paths that lose the original bindings. * * The function rebuilds the result path chain with the scope path as the base, * so that path.get
( resultPath: TraversalPath<any, any, any>, scopePath: TraversalPath<any, any, any>, )
| 5728 | * so that path.get() can find bindings from both the result and the scope. |
| 5729 | */ |
| 5730 | function injectScopeIntoPath( |
| 5731 | resultPath: TraversalPath<any, any, any>, |
| 5732 | scopePath: TraversalPath<any, any, any>, |
| 5733 | ): TraversalPath<any, any, any> { |
| 5734 | // Collect the path chain from resultPath (from root to leaf) |
| 5735 | const chain: Array<{ value: any; labels: readonly string[] }> = []; |
| 5736 | let current: TraversalPath<any, any, any> | undefined = resultPath; |
| 5737 | while (current) { |
| 5738 | chain.unshift({ value: current.value, labels: current.labels }); |
| 5739 | current = current.parent as TraversalPath<any, any, any> | undefined; |
| 5740 | } |
| 5741 | |
| 5742 | // Rebuild the chain with scopePath as the base |
| 5743 | let rebuiltPath: TraversalPath<any, any, any> = scopePath; |
| 5744 | for (const { value, labels } of chain) { |
| 5745 | rebuiltPath = new TraversalPath(rebuiltPath, value, labels as readonly string[]); |
| 5746 | } |
| 5747 | |
| 5748 | return rebuiltPath; |
| 5749 | } |
| 5750 | |
| 5751 | export type SetAssignmentValue = |
| 5752 | | { |