{"action":"opened","issue":{"url":"https://api.github.com/repos/decaffeinate/decaffeinate/issues/585","repository_url":"https://api.github.com/repos/decaffeinate/decaffeinate","labels_url":"https://api.github.com/repos/decaffeinate/decaffeinate/issues/585/labels{/name}","comments_url":"https://api.github.com/repos/decaffeinate/decaffeinate/issues/585/comments","events_url":"https://api.github.com/repos/decaffeinate/decaffeinate/issues/585/events","html_url":"https://github.com/decaffeinate/decaffeinate/issues/585","id":193264746,"number":585,"title":"Follow CoffeeScript scoping rules","user":{"login":"alangpierce","id":211605,"avatar_url":"https://avatars.githubusercontent.com/u/211605?v=3","gravatar_id":"","url":"https://api.github.com/users/alangpierce","html_url":"https://github.com/alangpierce","followers_url":"https://api.github.com/users/alangpierce/followers","following_url":"https://api.github.com/users/alangpierce/following{/other_user}","gists_url":"https://api.github.com/users/alangpierce/gists{/gist_id}","starred_url":"https://api.github.com/users/alangpierce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alangpierce/subscriptions","organizations_url":"https://api.github.com/users/alangpierce/orgs","repos_url":"https://api.github.com/users/alangpierce/repos","events_url":"https://api.github.com/users/alangpierce/events{/privacy}","received_events_url":"https://api.github.com/users/alangpierce/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-03T04:23:24Z","updated_at":"2016-12-03T04:23:24Z","closed_at":null,"body":"decaffeinate is producing the wrong JavaScript based on my CoffeeScript input:\r\n\r\n```coffee\r\ntry\r\n  x = 1\r\ncatch err\r\n  x = 2\r\nconsole.log(err)\r\n```\r\n\r\n[(repl)](http://decaffeinate-project.org/repl/#?evaluate=true&stage=full&code=try%0A%20%20x%20%3D%201%0Acatch%20err%0A%20%20x%20%3D%202%0Aconsole.log(err))\r\n\r\nI get this output:\r\n\r\n```js\r\ntry {\r\n  var x = 1;\r\n} catch (err) {\r\n  var x = 2;\r\n}\r\nconsole.log(err);\r\n```\r\n\r\nHere's what I expect it to be instead:\r\n\r\n```js\r\nlet err;\r\ntry {\r\n  var x = 1;\r\n} catch (error) {\r\n  err = error;\r\n  var x = 2;\r\n}\r\nconsole.log(err);\r\n```\r\n\r\nOriginally mentioned in https://github.com/decaffeinate/decaffeinate/issues/583#issuecomment-264615258 . The issue is that CS catch variables are stored as regular variables in the function's scope, but JS catch variables are scoped to the catch block.\r\n\r\nI didn't see the issue come up in actual code I just noticed it when looking at CS output, and in practice it would be caught by eslint, so it seems relatively low priority. I think the right behavior is to see if the exception variable is actually used in the outer scope, and only generate the assignment in that case. That way, the common case (an exception only used in the catch block) doesn't get any uglier."}}
{"actor":{"display_login":"alangpierce"}}