{"action":"created","issue":{"url":"https://api.github.com/repos/mbj/unparser/issues/54","labels_url":"https://api.github.com/repos/mbj/unparser/issues/54/labels{/name}","comments_url":"https://api.github.com/repos/mbj/unparser/issues/54/comments","events_url":"https://api.github.com/repos/mbj/unparser/issues/54/events","html_url":"https://github.com/mbj/unparser/pull/54","id":116099986,"number":54,"title":"Emit a \\ line continuation when one is used between string literals in original source","user":{"login":"alexdowad","id":1067359,"avatar_url":"https://avatars.githubusercontent.com/u/1067359?v=3","gravatar_id":"","url":"https://api.github.com/users/alexdowad","html_url":"https://github.com/alexdowad","followers_url":"https://api.github.com/users/alexdowad/followers","following_url":"https://api.github.com/users/alexdowad/following{/other_user}","gists_url":"https://api.github.com/users/alexdowad/gists{/gist_id}","starred_url":"https://api.github.com/users/alexdowad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexdowad/subscriptions","organizations_url":"https://api.github.com/users/alexdowad/orgs","repos_url":"https://api.github.com/users/alexdowad/repos","events_url":"https://api.github.com/users/alexdowad/events{/privacy}","received_events_url":"https://api.github.com/users/alexdowad/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":29,"created_at":"2015-11-10T12:46:37Z","updated_at":"2016-01-24T11:07:09Z","closed_at":"2016-01-24T11:02:37Z","pull_request":{"url":"https://api.github.com/repos/mbj/unparser/pulls/54","html_url":"https://github.com/mbj/unparser/pull/54","diff_url":"https://github.com/mbj/unparser/pull/54.diff","patch_url":"https://github.com/mbj/unparser/pull/54.patch"},"body":"This makes the 'corpus' integration test pass on Mutant. It didn't before.\r\n\r\nRuby allows string literals to be continued on another line like this:\r\n\r\n```ruby\r\n    \"a string\" \\\r\n    \"another\"\r\n```\r\n\r\nWhen parser sees this, it generates 2 `str` nodes, one after the other.\r\nTherefore, make `Unparser::Emitter::Literal::DynamicBody` generate code which uses\r\na line continuation when it sees 2 adjacent `str` nodes under a `dstr` node, which\r\nwere separated by a line break in the original source.\r\n\r\nWhen merging string literals into new `str` nodes, retain the source map information,\r\nso we can make intelligent decisions about things like this.\r\n\r\nOf course, when `unparser` is used to \"unparse\" ASTs which were built from scratch\r\n(not parsed from Ruby source code), then no source map information will be available.\r\nBut in many cases, an AST may originally be parsed from Ruby source, and just a few\r\nnodes will be added, removed, or modified. So many nodes will still have source maps,\r\nwhich we can exploit to retain the original code formatting as much as possible.\r\n\r\nTo this end, when canonicalizing ASTs, we should avoid \"throwing away\" the source maps."},"comment":{"url":"https://api.github.com/repos/mbj/unparser/issues/comments/174282126","html_url":"https://github.com/mbj/unparser/pull/54#issuecomment-174282126","issue_url":"https://api.github.com/repos/mbj/unparser/issues/54","id":174282126,"user":{"login":"alexdowad","id":1067359,"avatar_url":"https://avatars.githubusercontent.com/u/1067359?v=3","gravatar_id":"","url":"https://api.github.com/users/alexdowad","html_url":"https://github.com/alexdowad","followers_url":"https://api.github.com/users/alexdowad/followers","following_url":"https://api.github.com/users/alexdowad/following{/other_user}","gists_url":"https://api.github.com/users/alexdowad/gists{/gist_id}","starred_url":"https://api.github.com/users/alexdowad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexdowad/subscriptions","organizations_url":"https://api.github.com/users/alexdowad/orgs","repos_url":"https://api.github.com/users/alexdowad/repos","events_url":"https://api.github.com/users/alexdowad/events{/privacy}","received_events_url":"https://api.github.com/users/alexdowad/received_events","type":"User","site_admin":false},"created_at":"2016-01-24T11:07:09Z","updated_at":"2016-01-24T11:07:09Z","body":"> I removed the flattening of dstr nodes. To reproduce the AST more precisely.\r\n\r\nI can see that this does make it easier to \"round-trip\" AST to code to identical AST. Unfortunately, it means we are much further from generating \"pretty\" code than we were before.\r\n\r\nI am not going to work further on this issue right now."}}