Skip to content
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

Rollup writes this to undefined in CoffeeScript 2 #7

Open
aminya opened this issue Jul 13, 2020 · 0 comments
Open

Rollup writes this to undefined in CoffeeScript 2 #7

aminya opened this issue Jul 13, 2020 · 0 comments

Comments

@aminya
Copy link

aminya commented Jul 13, 2020

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)

which is compiled to

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

@aminya aminya changed the title Rollup write this to undefined in CoffeeScript 2 Rollup writes this to undefined in CoffeeScript 2 Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant