rollup-plugin-coffee-script
rollup-plugin-coffee-script copied to clipboard
Rollup writes `this` to `undefined` in CoffeeScript 2
When an operation is performed in the class (like Tags.forEach in the following example), CoffeeScript generates a function to call that. However, rollup rewrites this to undefied
Tags = [1,2]
class MyClass
constructor: -> console.log("constructor")
@hey: -> console.log("hey")
Tags.forEach (t) ->
@hey()
console.log(t)
var MyClass, Tags;
Tags = [1, 2];
MyClass = (function() {
class MyClass {
constructor() {
console.log("constructor");
}
static hey() {
return console.log("hey");
}
};
Tags.forEach(function(t) {
this.hey();
return console.log(t);
});
return MyClass;
}).call(this);
Then rollup throws this warning:
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
return MyClass;
}).call(this);
^
this is replaced with undefined