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.
Merge pull request #3638 from cgaebel/parallel-dom-traversal

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