{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4138","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4138/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4138/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4138/events","html_url":"https://github.com/Microsoft/TypeScript/issues/4138","id":98882393,"number":4138,"title":"JavaScript output has variable below return","user":{"login":"blakeembrey","id":1088987,"avatar_url":"https://avatars.githubusercontent.com/u/1088987?v=3","gravatar_id":"","url":"https://api.github.com/users/blakeembrey","html_url":"https://github.com/blakeembrey","followers_url":"https://api.github.com/users/blakeembrey/followers","following_url":"https://api.github.com/users/blakeembrey/following{/other_user}","gists_url":"https://api.github.com/users/blakeembrey/gists{/gist_id}","starred_url":"https://api.github.com/users/blakeembrey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blakeembrey/subscriptions","organizations_url":"https://api.github.com/users/blakeembrey/orgs","repos_url":"https://api.github.com/users/blakeembrey/repos","events_url":"https://api.github.com/users/blakeembrey/events{/privacy}","received_events_url":"https://api.github.com/users/blakeembrey/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/By%20Design","name":"By Design","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-04T03:39:07Z","updated_at":"2015-08-04T10:52:59Z","closed_at":"2015-08-04T04:35:36Z","body":"Using latest commit (4c7b214a69c97eb1746b94712ff9a4c2202e2dca) and compiling the code below results in the variable initialization below `return`. \r\n\r\n```ts\r\nclass C {\r\n  constructor (...args: any[]) {}\r\n}\r\n\r\nfunction fn (...args) {\r\n  return new (C)(...args)\r\n}\r\n```\r\n\r\n```js\r\nfunction fn() {\r\n    var args = [];\r\n    for (var _i = 0; _i < arguments.length; _i++) {\r\n        args[_i - 0] = arguments[_i];\r\n    }\r\n    return new ((_a = (C)).bind.apply(_a, [void 0].concat(args)))();\r\n    var _a;\r\n}\r\n```\r\n\r\nThe variable is always below the return, even when the statement is assigned to a variable instead of returning.\r\n\r\nEdit: `node node_modules/.bin/tsc test.ts --target es5`"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/127564792","html_url":"https://github.com/Microsoft/TypeScript/issues/4138#issuecomment-127564792","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4138","id":127564792,"user":{"login":"kitsonk","id":1282577,"avatar_url":"https://avatars.githubusercontent.com/u/1282577?v=3","gravatar_id":"","url":"https://api.github.com/users/kitsonk","html_url":"https://github.com/kitsonk","followers_url":"https://api.github.com/users/kitsonk/followers","following_url":"https://api.github.com/users/kitsonk/following{/other_user}","gists_url":"https://api.github.com/users/kitsonk/gists{/gist_id}","starred_url":"https://api.github.com/users/kitsonk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kitsonk/subscriptions","organizations_url":"https://api.github.com/users/kitsonk/orgs","repos_url":"https://api.github.com/users/kitsonk/repos","events_url":"https://api.github.com/users/kitsonk/events{/privacy}","received_events_url":"https://api.github.com/users/kitsonk/received_events","type":"User","site_admin":false},"created_at":"2015-08-04T10:52:59Z","updated_at":"2015-08-04T10:52:59Z","body":"> I realised, but it didn't look by design and I didn't see a previous issue logged.\r\n\r\nI suspect it was because it wasn't supported before when targeting ES5, so it wasn't a \"break\" of previous behaviour, because there was no previous behaviour.\r\n\r\nDeclaring things after the return though doesn't seem like clean idiomatic JavaScript though."}}