( rule: Walkable<T>, cb: (rule: T, idx: number, parent: Walkable<T>) => void | WalkAction, )
| 16 | // Custom walk implementation where we can skip going into nodes when we don't |
| 17 | // need to process them. |
| 18 | export function walk<T>( |
| 19 | rule: Walkable<T>, |
| 20 | cb: (rule: T, idx: number, parent: Walkable<T>) => void | WalkAction, |
| 21 | ): undefined | false { |
| 22 | let result: undefined | false = undefined |
| 23 | |
| 24 | rule.each?.((node, idx) => { |
| 25 | let action = cb(node, idx, rule) ?? WalkAction.Continue |
| 26 | if (action === WalkAction.Stop) { |
| 27 | result = false |
| 28 | return result |
| 29 | } |
| 30 | if (action !== WalkAction.Skip) { |
| 31 | result = walk(node as Walkable<T>, cb) |
| 32 | return result |
| 33 | } |
| 34 | }) |
| 35 | |
| 36 | return result |
| 37 | } |
| 38 | |
| 39 | // Depth first walk reversal implementation. |
| 40 | export function walkDepth<T>(rule: Walkable<T>, cb: (rule: T) => void) { |
no test coverage detected