(ast: AST, encoding: Encoding)
| 3741 | }) |
| 3742 | |
| 3743 | function flipEncoding(ast: AST, encoding: Encoding): AST { |
| 3744 | const links = encoding |
| 3745 | const len = links.length |
| 3746 | const last = links[len - 1] |
| 3747 | const ls: Arr.NonEmptyArray<Link> = [ |
| 3748 | new Link(flip(replaceEncoding(ast, undefined)), links[0].transformation.flip()) |
| 3749 | ] |
| 3750 | for (let i = 1; i < len; i++) { |
| 3751 | ls.unshift(new Link(flip(links[i - 1].to), links[i].transformation.flip())) |
| 3752 | } |
| 3753 | const to = flip(last.to) |
| 3754 | if (to.encoding) { |
| 3755 | return replaceEncoding(to, [...to.encoding, ...ls]) |
| 3756 | } else { |
| 3757 | return replaceEncoding(to, ls) |
| 3758 | } |
| 3759 | } |
| 3760 | |
| 3761 | /** |
| 3762 | * Swaps the decode and encode directions of an AST's {@link Encoding} chain. |
no test coverage detected