{"action":"created","issue":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4354","repository_url":"https://api.github.com/repos/jashkenas/coffeescript","labels_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4354/labels{/name}","comments_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4354/comments","events_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4354/events","html_url":"https://github.com/jashkenas/coffeescript/pull/4354","id":187540908,"number":4354,"title":"Compile class constructors to ES2015 classes","user":{"login":"connec","id":160652,"avatar_url":"https://avatars.githubusercontent.com/u/160652?v=3","gravatar_id":"","url":"https://api.github.com/users/connec","html_url":"https://github.com/connec","followers_url":"https://api.github.com/users/connec/followers","following_url":"https://api.github.com/users/connec/following{/other_user}","gists_url":"https://api.github.com/users/connec/gists{/gist_id}","starred_url":"https://api.github.com/users/connec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connec/subscriptions","organizations_url":"https://api.github.com/users/connec/orgs","repos_url":"https://api.github.com/users/connec/repos","events_url":"https://api.github.com/users/connec/events{/privacy}","received_events_url":"https://api.github.com/users/connec/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-06T04:15:22Z","updated_at":"2016-11-07T00:29:17Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jashkenas/coffeescript/pulls/4354","html_url":"https://github.com/jashkenas/coffeescript/pull/4354","diff_url":"https://github.com/jashkenas/coffeescript/pull/4354.diff","patch_url":"https://github.com/jashkenas/coffeescript/pull/4354.patch"},"body":"**Note:** This includes the commit from #4353. Once that's merged this can be rebased.\r\n\r\nRather than compiling class constructors as named functions, they are now compiled to ES2015 classes with a `constructor`. This change allows classes written in CoffeeScript to extend classes written in ES2015 without encountering `constructor ... cannot be invoked without 'new'` errors.\r\n\r\nThis also changes how inheritence is implemented, deferring most of the work to ES2015's `extends`. `__super__` is kept to allow the existing `super` compilation to continue to be used.\r\n\r\nThe main divergence from prior behaviour is that a constructor function with `@` parameters will implicitly call `super`, passing all arguments. This is because ES2015 derived classes require `super` to be called from the constructor before `this` is available. It follows that explicit `super` calls in constructors with `@` params are not allowed. In all other cases, `super` must explicitly be called in the constructors of derived classes, or they will encounter `this is undefined` errors.\r\n\r\nAnother awkward part of the compilation is dealing with the fact that `class` statements, unlike named functions, are not hoisted. To deal with this we insert a 'placeholder' fragment where we want the `class` to be written, whilst leaving the node in its original position to ensure the correct variable scope is used.\r\n\r\nThis is definitely missing a few tests, in particular around things like:\r\n\r\n- `@` params with/without super, including errors\r\n- bound functions with/without super, including errors\r\n- `super` in arrow functions in constructors\r\n- `super` and external constructors\r\n- ... any more anyone can think of\r\n\r\nSupersedes #4330."},"comment":{"url":"https://api.github.com/repos/jashkenas/coffeescript/issues/comments/258723456","html_url":"https://github.com/jashkenas/coffeescript/pull/4354#issuecomment-258723456","issue_url":"https://api.github.com/repos/jashkenas/coffeescript/issues/4354","id":258723456,"user":{"login":"connec","id":160652,"avatar_url":"https://avatars.githubusercontent.com/u/160652?v=3","gravatar_id":"","url":"https://api.github.com/users/connec","html_url":"https://github.com/connec","followers_url":"https://api.github.com/users/connec/followers","following_url":"https://api.github.com/users/connec/following{/other_user}","gists_url":"https://api.github.com/users/connec/gists{/gist_id}","starred_url":"https://api.github.com/users/connec/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/connec/subscriptions","organizations_url":"https://api.github.com/users/connec/orgs","repos_url":"https://api.github.com/users/connec/repos","events_url":"https://api.github.com/users/connec/events{/privacy}","received_events_url":"https://api.github.com/users/connec/received_events","type":"User","site_admin":false},"created_at":"2016-11-07T00:29:17Z","updated_at":"2016-11-07T00:29:17Z","body":"@svicalifornia nothing's been decided on that front yet, this is just what I thought was a sensible choice.\r\n\r\nTo be clear: the implementation here will add an implicit call to `super` unless an explicit one exists.\r\n\r\nI'm a fan of `@` params in constructors since it eliminates having to write out the variable names twice. On top of that, I can see an implicit `super` as quite a nice feature, since if you extend a class and write a constructor, you **must** call super in order to use the class. And half the time the arguments you give don't matter, making it tantamount to boilerplate in a lot of cases. If you *do* care about the arguments, you'll of course want to provide an explicit `super`, and CS won't let you use `@` params in that case."}}
{"actor":{"display_login":"connec"}}