CoffeeScript/Babel turning classes into functions on Cordova/Desktop
- Dominant language
- JavaScript
- Stars
- 44.8k
- Forks
- 5.2k
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 25
Description
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](https://github.com/meteor/meteor/blob/791f2e607bc83edc57a1186e58a6e746adb347ed/packages/non-core/coffeescript-compiler/coffeescript-compiler.js#L64C5-L69C72) in the CoffeeScript compiler:
```js
// 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?
Contributor guide
Research direction
Start in packages/non-core/coffeescript-compiler/coffeescript-compiler.js at the Babel processing lines linked in the issue. Compare CoffeeScript output with JavaScript class handling for normal web and Cordova/Desktop targets, then verify that CoffeeScript classes extending JavaScript classes remain compatible in the Desktop build.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- babel, coffeescript, javascript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100