{"action":"closed","issue":{"url":"https://api.github.com/repos/Rich-Harris/magic-string/issues/7","labels_url":"https://api.github.com/repos/Rich-Harris/magic-string/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/Rich-Harris/magic-string/issues/7/comments","events_url":"https://api.github.com/repos/Rich-Harris/magic-string/issues/7/events","html_url":"https://github.com/Rich-Harris/magic-string/issues/7","id":55582960,"number":7,"title":"Best practice for controlling order of multiple insertions at one position","user":{"login":"eventualbuddha","id":1938,"avatar_url":"https://avatars.githubusercontent.com/u/1938?v=3","gravatar_id":"","url":"https://api.github.com/users/eventualbuddha","html_url":"https://github.com/eventualbuddha","followers_url":"https://api.github.com/users/eventualbuddha/followers","following_url":"https://api.github.com/users/eventualbuddha/following{/other_user}","gists_url":"https://api.github.com/users/eventualbuddha/gists{/gist_id}","starred_url":"https://api.github.com/users/eventualbuddha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eventualbuddha/subscriptions","organizations_url":"https://api.github.com/users/eventualbuddha/orgs","repos_url":"https://api.github.com/users/eventualbuddha/repos","events_url":"https://api.github.com/users/eventualbuddha/events{/privacy}","received_events_url":"https://api.github.com/users/eventualbuddha/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-27T06:58:03Z","updated_at":"2015-01-27T16:23:33Z","closed_at":"2015-01-27T16:23:33Z","body":"In building decaffeinate I've run into an issue where the order of strings inserted at the same position is not always what I'd like it to be. For example, given the CoffeeScript string `a b: c` I'd like to turn it into the JavaScript string `a({b: c});`. This might be accomplished by visiting various AST node types in turn and inserting or replacing characters as required. Here's an example:\r\n\r\n```\r\nREPLACE 1...2 \"(\"\r\nINSERT 6 \")\"\r\nINSERT 2 \"{\"\r\nINSERT 6 \"}\"\r\nINSERT 6 \";\"\r\n```\r\n\r\nThis would be represented using MagicString's API like so:\r\n\r\n```js\r\n> new MagicString('a b: c').replace(1, 2, '(').insert(6, ')').insert(2, '{').insert(6, '}').insert(6, ';').toString()\r\n'a({b: c)};'\r\n```\r\n\r\nAs you can see, the resulting string is not correct. Do you have any suggestions for achieving the desired result here? I'm not tied to the sequence of API calls above."}}