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
Fix default export with arrows and function naming #4524
Fix default export with arrows and function naming #4524
Conversation
Current coverage is 88.33% (diff: 100%)@@ master #4524 diff @@
==========================================
Files 194 194
Lines 13616 13617 +1
Methods 1427 1427
Messages 0 0
Branches 3147 3148 +1
==========================================
+ Hits 12027 12029 +2
+ Misses 1589 1588 -1
Partials 0 0
|
Thank you. If you can easily reproduce this bug with amd and umd, then it would be nice to have a simple test for each of the module-systems. |
👍 will do, just wanted to check this is the correct approach first. An alternative approach is to transpile arrow functions whose parent is an function _default(_a) {
return {
a: function a() {
return _a;
}
};
}
exports.default = _default; |
However, looking into it more, the code giving default exports a name was introduced here: #3134, which seems to be the same issue this is resolving
If I remove that code, everything continues to work with my changes, just the associated test case changes to not be a separate statement: "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
+ exports.default = function () {
- function _default() {
return function () {
function Select() {
babelHelpers.classCallCheck(this, Select);
}
babelHelpers.createClass(Select, [{
key: "query",
value: function query(_query) {}
}]);
return Select;
}();
}
-
- exports.default = _default; (I'll check tonight how that works with class declarations, too.) |
The regression was #4228 with example code: |
Yeah, that was a regression from a previous attempted fix for exported arrows, which got reverted. |
This is great thanks!! |
Default arrow function exports, with
transform-es2015-arrow-functions
andtransform-es2015-function-name
(or, just thees2015
preset) results in loss of the default export.function-name
renames existing clashing identifiers when adding a function name.In the tests, I've only added ones for the CJS output as that's what I was originally trying to solve. This actually affects all module formats. I can follow up with duplicate tests for each module system if you'd like.
Minimal reproduction of the issue: