davidchambers/doctest — pull request #22 by davidchambers (2014-03-06 06:58:15+00:00)
Title: simplify rewriters

Commit message:

> The current JavaScript rewriter is particularly convoluted. It invokes esprima.parse once up front to ascertain the position of each comment, then rewrites the comments one at a time, resulting in the entire file being parsed N + 1 times (where N is the number of comments).
>
> In addition to being inefficient, this code is confusing: it relies on evaluating `esprima.parse(input)` multiple times with differing results (due to reassignment within the loop). Worst of all, processComment is a stateful function: its return value is determined in part by previously supplied arguments.
>
> The new rewriters eschew mutation, reassignment, and stateful functions, and are easier to reason about as result. They introduce an intermediate data structure, a list of {input,output} pairs, which breaks the problem into two simpler problems. The JavaScript rewriter invokes esprima.parse once per file rather than N + 1 times.

I'd appreciate your feedback on this, @danse. :)