New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fat arrow functions bound before calls to super render constructors invalid #2141
Comments
Previously decaffeinate would produce code that worked around this when using Babel or TypeScript to transpile to ES5 or lower, but Babel changed in a way that broke the workaround. Given that the workaround didn't work when using real ES6 classes, I just decided to remove it in 14ab797. Note that the output you posted does indicate that you should fix the invalid constructor. Most of the time you can simply change it manually to be as you wrote it, but it's possible that you'd been relying on the ordering that bound the method first, so that's how it leaves it. |
Just popping a meta, that we might speak of how to deal with issues which are issues but which have a complex background.... Isn't it more appropriate to leave the issue open rather than, in effect, say WontFix about it? Maybe someone else might want to give it a whack. BTW, thanks for all your work on decaffeinate! Much appreciated. |
That's a fair point, though the only way I can think of to fix this is to use ES5-style classes. That's almost certainly more work than anyone is willing to put in. |
I know nothing about decaffeinate's internals -- forgive me -- but given that decaffeinate introduces the |
CS2 changed the behavior of when classes would bind methods to be compatible with ES6 classes. They bind after the call to super, rather than before as in CS1. When targeting CS2, follow that same behavior. Refs #2141.
I'm still seeing this one in version 6.1.8 with option e.g.:
Is there some reason the fix isn't being used in this case? |
Same issue as above (with 6.1.10) Having a CoffeeScript sub class, that calls super, is putting all the binds before the super call, regardless of the I have ~=480 classes to migrate. Currently looking at doing our own "coffeescript > compile" conversion due to this problem (like bulkdecaffeinate without the decaffineate). Invalid outputdefine (require) ->
Layout = require 'backbone.layoutmanager'
class View extends Layout
constructor: (options) ->
super options
enable: () =>
return /*
* decaffeinate suggestions:
* DS002: Fix invalid constructor
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(function(require) {
let View;
const Layout = require('backbone.layoutmanager');
return (View = class View extends Layout {
constructor(options) {
this.enable = this.enable.bind(this);
super(options);
}
enable() {
}
});
}); Valid outputdefine (require) ->
Layout = require 'backbone.layoutmanager'
class View extends Layout
enable: () =>
return /*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(function(require) {
let View;
const Layout = require('backbone.layoutmanager');
return (View = class View extends Layout {
constructor(...args) {
super(...args);
this.enable = this.enable.bind(this);
}
enable() {
}
});
}); |
…comply with ES6 requirements Addresses the case noted here decaffeinate#2141 (comment). Note, this assumes we're always sourcing from CS2 (e.g. --use-cs2).
@softgripper and I spent some time debugging yesterday and came up with the following fix for the issue he documents: As noted in the commit message, this change assumes you're always using |
🎉 This issue has been resolved in version 6.1.11 🎉 The release is available on: Your semantic-release bot 📦🚀 |
decaffeinate is producing the wrong JavaScript based on my CoffeeScript input:
I get this output:
Here's what I expect it to be instead:
The text was updated successfully, but these errors were encountered: