{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10189","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10189/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10189/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10189/events","html_url":"https://github.com/Microsoft/TypeScript/pull/10189","id":169759086,"number":10189,"title":"Emit more efficient/concise \"empty\" ES6 ctor","user":{"login":"chancancode","id":55829,"avatar_url":"https://avatars.githubusercontent.com/u/55829?v=3","gravatar_id":"","url":"https://api.github.com/users/chancancode","html_url":"https://github.com/chancancode","followers_url":"https://api.github.com/users/chancancode/followers","following_url":"https://api.github.com/users/chancancode/following{/other_user}","gists_url":"https://api.github.com/users/chancancode/gists{/gist_id}","starred_url":"https://api.github.com/users/chancancode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chancancode/subscriptions","organizations_url":"https://api.github.com/users/chancancode/orgs","repos_url":"https://api.github.com/users/chancancode/repos","events_url":"https://api.github.com/users/chancancode/events{/privacy}","received_events_url":"https://api.github.com/users/chancancode/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/cla-signed","name":"cla-signed","color":"207de5"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2016-08-06T18:15:58Z","updated_at":"2016-08-16T22:39:22Z","closed_at":"2016-08-16T22:39:12Z","pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/10189","html_url":"https://github.com/Microsoft/TypeScript/pull/10189","diff_url":"https://github.com/Microsoft/TypeScript/pull/10189.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/10189.patch"},"body":"Fixes #10175\r\n\r\nOur setup is to have tsc compile into ES6 and run the output through our existing build pipeline (babel plugins, etc). I understand this is not strictly speaking a bug in tsc, but it is definitely a problem for us. This is a case where both sides, independently, are doing an acceptable thing but the combination of the two is not, so I figured I'll give this a shot and see if we can get this addressed in tsc.\r\n\r\n- - -\r\n\r\nWhen there are property assignments in a the class body of an inheriting class, tsc current emit the following compilation:\r\n\r\n```ts\r\nclass Foo extends Bar {\r\n  public foo = 1;\r\n}\r\n```\r\n\r\n```js\r\nclass Foo extends Bar {\r\n  constructor(…args) {\r\n    super(…args);\r\n    this.foo = 1;\r\n  }\r\n}\r\n```\r\n\r\nThis introduces an unneeded local variable and might force a reification of the `arguments` object (or otherwise reify the arguments into an array).\r\n\r\nThis is particularly bad when that output is fed into another transpiler like Babel. In Babel, you get something like this today:\r\n\r\n\r\n```js\r\nvar Foo = (function (_Bar) {\r\n  _inherits(Foo, _Bar);\r\n\r\n  function Foo() {\r\n    _classCallCheck(this, Foo);\r\n\r\n    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {\r\n      args[_key] = arguments[_key];\r\n    }\r\n\r\n    _Bar.call.apply(_Bar, [this].concat(args));\r\n    this.foo = 1;\r\n  }\r\n\r\n  return Foo;\r\n})(Bar);\r\n```\r\n\r\nThis causes a lot of needless work/allocations and some very strange code (`.call.apply` o_0).\r\n\r\nAdmittedly, this is not strictly tsc’s problem; it could have done a deeper analysis of the code and optimized out the extra dance. However, tsc could also have emitted this simpler, more concise and semantically equivalent code in the first place:\r\n\r\n\r\n```js\r\nclass Foo extends Bar {\r\n  constructor() {\r\n    super(…arguments);\r\n    this.foo = 1;\r\n  }\r\n}\r\n```\r\n\r\nWhich compiles into the following in Babel:\r\n\r\n```js\r\nvar Foo = (function (_Bar) {\r\n  _inherits(Foo, _Bar);\r\n\r\n  function Foo() {\r\n    _classCallCheck(this, Foo);\r\n\r\n    _Bar.apply(this, arguments);\r\n    this.foo = 1;\r\n  }\r\n\r\n  return Foo;\r\n})(Bar);\r\n```\r\n\r\nWhich is well-optimized (today) in most engines and much less confusing\r\nto read.\r\n\r\nAs far as I can tell, the proposed compilation has exactly the same\r\nsemantics as before."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/240261579","html_url":"https://github.com/Microsoft/TypeScript/pull/10189#issuecomment-240261579","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/10189","id":240261579,"user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"created_at":"2016-08-16T22:39:21Z","updated_at":"2016-08-16T22:39:21Z","body":"Merged, we'll add the comment for you :smile"}}
{"actor":{"display_login":"DanielRosenwasser"}}