-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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 compiling badly interacts with Babel #7558
Conversation
d3325e9
to
e4dd868
Compare
To address the Meteor CoffeeScript compilation issue meteor/meteor#7558
As you probably realize, we can't merge this until it's fixed, though we do very much appreciate that you've provided these test cases (instead of just reporting the problem). When we get around to fixing this, we'll open a pull request against |
I can also just move the branch to this repository? |
Or I can give permissions on that fork for whoever wants. But yes, pull request is also good. |
Alternatively, now that CoffeeScript supports import and export, people could use that to share objects between files. Dropping support for shared variables would be a breaking change, though. |
@benjamn I think this is actually a bug in the Babel compiler. So from this CoffeeScript file, with no backticks or modules and therefore no Babel postprocessing: COFFEESCRIPT_EXPORTED = 123
COFFEESCRIPT_EXPORTED_ONE_MORE = 234
COFFEESCRIPT_EXPORTED_WITH_BACKTICKS = 345
class TestClass
class ClassExtending extends TestClass we get this: __coffeescriptShare = typeof __coffeescriptShare === 'object' ? __coffeescriptShare : {}; var share = __coffeescriptShare;
var ClassExtending, TestClass,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty; //
//
COFFEESCRIPT_EXPORTED = 123; // 1
//
COFFEESCRIPT_EXPORTED_ONE_MORE = 234; // 2
//
COFFEESCRIPT_EXPORTED_WITH_BACKTICKS = 345; // 6
//
TestClass = (function() { // 13
function TestClass() {} //
//
return TestClass; //
//
})(); //
//
ClassExtending = (function(superClass) { // 15
extend(ClassExtending, superClass); //
//
function ClassExtending() { //
return ClassExtending.__super__.constructor.apply(this, arguments);
} //
//
return ClassExtending; //
//
})(TestClass); // which works fine. Wrap the third line in backticks, though, to trigger Babel, and you get this: __coffeescriptShare = typeof __coffeescriptShare === 'object' ? __coffeescriptShare : {}; var share = __coffeescriptShare;
var //
COFFEESCRIPT_EXPORTED_ONE_MORE, //
ClassExtending, //
TestClass, //
extend = function extend(child, parent) { //
for (var key in meteorBabelHelpers.sanitizeForInObject(parent)) { //
if (hasProp.call(parent, key)) child[key] = parent[key]; //
}function ctor() { //
this.constructor = child; //
}ctor.prototype = parent.prototype;child.prototype = new ctor();child.__super__ = parent.prototype;return child;
}, //
hasProp = {}.hasOwnProperty; //
//
COFFEESCRIPT_EXPORTED = 123; //
//
COFFEESCRIPT_EXPORTED_ONE_MORE = 234; //
//
COFFEESCRIPT_EXPORTED_WITH_BACKTICKS = 345; //
//
TestClass = function () { //
function TestClass() {} //
//
return TestClass; //
}(); //
//
ClassExtending = function (superClass) { //
extend(ClassExtending, superClass); //
//
function ClassExtending() { //
return ClassExtending.__super__.constructor.apply(this, arguments); //
} //
//
return ClassExtending; //
}(TestClass); // The important thing to note here is that Do you know where the code is that generates this |
…ugh the Babel compiler, to avoid Babel turning a one-line `var` statement into a multiline `var` statement and breaking the parsing logic in `stripExportedVars`
@benjamn I take it back. It’s not Babel’s fault. It’s compile-coffeescript.js’ Or more specifically, it’s the fact that var a,
b,
c; Or at least it does in the case of @mitar’s tests. Rather than rewrite I submitted the fix as mitar#1, per @benjamn’s instructions above. @mitar, after you accept the PR you should merge the latest upstream |
Fix CoffeeScript exported variables on files processed by Babel
Merged, updated, merged, and tests are running. |
# Conflicts: # packages/coffeescript/plugin/compile-coffeescript.js
Update CoffeeScript
Updated once more. |
@benjamn I think this should be ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @mitar and @GeoffreyBooth!
Can you bump the coffeescript Meteor package version please? ;-) See my comment here: 8dbfd97 |
@@ -1,14 +1,14 @@ | |||
Package.describe({ | |||
summary: "Javascript dialect with fewer braces and semicolons", | |||
version: "1.2.6" | |||
version: "1.2.7" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this 1.11.1_1
?
It seems there is a bad interaction with Babel and CoffeeScript. Recently, a change has been introduced to CoffeeScript compiling which allows Babel to process code inside backticks. The bad side-effect of this is that when Babel processes the code, it rewraps the list of defined variables, which breaks these assumptions. As a consequence, some exported variables cannot be defined because a local variable is defined.
The problem is even more problematic because even if a backtick is just inside a comment in the CoffeeScript (read: Markdown documentation) it triggers Babel processing, breaking exports.
This pull requests adds tests which break CoffeeScript in the above described way.