(ast: AST)
| 4888 | }) |
| 4889 | |
| 4890 | function flipAST(ast: AST): AST { |
| 4891 | if (ast.encoding) { |
| 4892 | return flipEncoding(ast, ast.encoding) |
| 4893 | } |
| 4894 | const owned = projectOwner(ast, flip) |
| 4895 | if (owned) return owned |
| 4896 | if (isSuspend(ast)) { |
| 4897 | const previous = flippedThunks.get(ast.thunk) |
| 4898 | if (previous) return copy(ast, { thunk: previous.source.thunk }) |
| 4899 | const flipped = ast.recur(flip) |
| 4900 | // Register the projection here so decoding alone does not pull in flip. |
| 4901 | flippedThunks.set(flipped.thunk, { |
| 4902 | source: ast, |
| 4903 | project(node) { |
| 4904 | const thunk = memoizeThunk(() => reverseBody(ast.thunk(), thunk)) |
| 4905 | return copy(node, { thunk }) |
| 4906 | } |
| 4907 | }) |
| 4908 | return flipped |
| 4909 | } |
| 4910 | return "flip" in ast ? ast.flip(flip) : ast |
| 4911 | } |
| 4912 | |
| 4913 | function reverseBody(body: AST, edge: Suspend["thunk"]): AST { |
| 4914 | if (types.get(body) !== body) return stripEncoding(flip(body)) |
no test coverage detected