Ensure inserting at position 0 is consistent with non-zero positions. #10
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.
When inserting at non-zero positions the string is placed after any previous strings that would have been placed at that position. Before this commit, inserting at position 0 was treated specially, deferring to the
prepend
operation. This commit changes the behavior of inserts at 0 to match inserts at any other position. If the old behavior is desired,prepend
should be called directly.For context, this is an issue for
decaffeinate
because, given this CoffeeScript:I would like the final output to be this:
However, what's actually being output is this:
decaffeinate inserts
var c;\n
at 0 first because it wants that to be above any other statements. It then later insertsvar
also at 0 (right beforea
), expecting it to appear after the previously-inserted variable declaration. That isn't happening, but with this patch it does.