| 4694 | |
| 4695 | // Suspensions are leaves in this walk. Only resolving a suspension may call its thunk. |
| 4696 | function everyNode(root: AST, predicate: (ast: AST) => boolean, proven?: WeakSet<AST>): boolean { |
| 4697 | const nodes = new Set([root]) |
| 4698 | for (const ast of nodes) { |
| 4699 | if (proven?.has(ast)) continue |
| 4700 | if (!predicate(ast)) return false |
| 4701 | if (!isSuspend(ast) && "recur" in ast) ast.recur(visit) |
| 4702 | } |
| 4703 | if (proven) { |
| 4704 | for (const ast of nodes) { |
| 4705 | proven.add(ast) |
| 4706 | } |
| 4707 | } |
| 4708 | return true |
| 4709 | |
| 4710 | function visit(child: AST): AST { |
| 4711 | nodes.add(child) |
| 4712 | return child |
| 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | const preservesShape = new WeakSet<AST>() |
| 4717 | |