Only traverse replaced node after calling .replace() #25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #24
I was looking into this a bit and I think the problem was that, when evaluating a conditional, although it would correctly call
.replace()
with the block that should run, the visitor would continue to visit all children, so the else blocks would step over any#define
s in the if block.I think what we want to have happen here is that if we replace the current node with something else, rather than continuing to visit the old node, the visitor should traverse the reversed node. This would definitely be a behaviour change, but I was thinking that if you wanted to replace but keep traversing the original tree, using
exit
instead ofenter
might be a better fit for that already. Let me know if I'm wrong in this assumption though, this changed behaviour could also easily just be an option invisit()
instead!