(rules: Iterable<Rule> | AsyncIterable<Rule>)
| 33 | * Chain multiple rules into a single rule. |
| 34 | */ |
| 35 | export function chain(rules: Iterable<Rule> | AsyncIterable<Rule>): Rule { |
| 36 | return async (initialTree, context) => { |
| 37 | let intermediateTree: Observable<Tree> | undefined; |
| 38 | if (Symbol.asyncIterator in rules) { |
| 39 | for await (const rule of rules) { |
| 40 | intermediateTree = callRule(rule, intermediateTree ?? initialTree, context); |
| 41 | } |
| 42 | } else { |
| 43 | for (const rule of rules) { |
| 44 | intermediateTree = callRule(rule, intermediateTree ?? initialTree, context); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return () => intermediateTree; |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Apply multiple rules to a source, and returns the source transformed. |
no test coverage detected