benjamn/ast-types — pull request #34 by eventualbuddha (2014-04-23 19:06:04+00:00)
Title: Ensure replacing a node with itself works consistently.

This comes from a desire to prepend variables at the top of a scope. I [asked on twitter how to achieve this](https://twitter.com/eventualbuddha/status/458994449410834432) since using `Array#unshift` to prepend caused subsequent `replace` calls for any of the `NodePath` inside the same array to replace the wrong node. The [solution proposed by @benjamn](https://twitter.com/benjamn/status/459001056861904897) works as long as you aren't traversing and holding on to a stale copy of the `NodePath` with the wrong index (name).

This commit ensures that the stale `NodePath` is updated with the right index (name) so that if you call `this.replace(...)` inside your traversal callback you will be replacing the right node.