Cleanup.

* rename toSourceNode() to toSourceNodeWhenNeeded()
* clean up loop variables in flattenString()