Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure inserting at position 0 is consistent with non-zero positions. #10

Merged
merged 1 commit into from Apr 3, 2015
Merged

Ensure inserting at position 0 is consistent with non-zero positions. #10

merged 1 commit into from Apr 3, 2015

Conversation

eventualbuddha
Copy link
Contributor

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:

a = 1
b = c = 2

I would like the final output to be this:

var c;
var a = 1;
var b = c = 2;

However, what's actually being output is this:

var var c;
a = 1;
var b = c = 2;

decaffeinate inserts var c;\n at 0 first because it wants that to be above any other statements. It then later inserts var also at 0 (right before a), expecting it to appear after the previously-inserted variable declaration. That isn't happening, but with this patch it does.

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.
Rich-Harris added a commit that referenced this pull request Apr 3, 2015
…consistent

Ensure inserting at position 0 is consistent with non-zero positions.
@Rich-Harris Rich-Harris merged commit 91d074c into Rich-Harris:master Apr 3, 2015
@Rich-Harris
Copy link
Owner

Thanks - released in 0.4.7

eventualbuddha added a commit to decaffeinate/decaffeinate that referenced this pull request Apr 3, 2015
@eventualbuddha eventualbuddha deleted the ensure-insert-at-start-is-consistent branch April 3, 2015 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants