meteor/meteor

CoffeeScript/Babel turning classes into functions on Cordova/Desktop

MatejJan opened this issue · 1 comments

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?

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.