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

CoffeeScript/Babel turning classes into functions on Cordova/Desktop #13080

Open
MatejJan opened this issue Apr 4, 2024 · 1 comment
Open

Comments

@MatejJan
Copy link

MatejJan commented Apr 4, 2024

When CoffeeScript is used in a project with a Cordova/Desktop (Electron) build target, all the classes are turned into functions for those builds. This creates problems when a CoffeeScript class tries to extend a JavaScript class.

This is not a problem on a normal web build (Meteor.isModern returning true) where CoffeeScript classes translate to JavaScript classes. However, in a Desktop build (Meteor.isModern returning false), the result of a class declaration is a function.

Even worse, JavaScript classes (defined in .js files) do NOT get turned into functions in the Desktop build, leading to this incompatibility. However, if one includes a JavaScript class in a .cs file (using the embedded JavaScript syntax), that class will get turned into a function.

I'm assuming the problem then boils down to these lines in the CoffeeScript compiler:

    // CoffeeScript contains a handful of features that output as ES2015+,
    // such as modules, generator functions, for…of, and tagged template
    // literals. Because they’re too varied to detect, pass all CoffeeScript
    // compiler output through the Babel compiler.
    const doubleRoastedCoffee =
      this.babelCompiler.processOneFileForTarget(inputFile, output.js);

Since Babel doesn't seem to be converting JavaScript classes in .js files into functions (even on Cordova/Desktop platforms), is there a way that the CoffeeScript compiler wouldn't be turning them either?

@nachocodoner
Copy link
Member

I believe this is expected since when building a non-modern/legacy bundle, classes doesn't exist, and to proper functions are converted. But I can't see why uses legacy to compile in Cordova/Electron.

It would be nice to have a small reproduction repository where we can quickly try out to explore any ideas of possible solutions. Since I have more questions on the specific setup which I am not familiar with.

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

2 participants