Factors out DOM traversal, keeping the code in `parallel` free of traversal-specific logic.

DOM traversals and Flow traversals look very similar. This patch unifies them
with the preorder/postorder pattern. Hopefully, it also opens the door for writing
the traversal code only once, instead of the duplication we have today.
nit: the Rust style says to name this `PostorderDomTraversal`. This is different from the DOM coding style.