Skip to content

Commit

Permalink
Fix: export default arrows with function naming (babel#4524)
Browse files Browse the repository at this point in the history
  • Loading branch information
danharper authored and hzoo committed Sep 20, 2016
1 parent e64d86c commit f859830
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default () => ({
x: ({x}) => {}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function () {
return {
x: function x(_ref) {
var _x = _ref.x;
}
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default ({ onClick }) => (
<div onClick={() => onClick()} />
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (_ref) {
var _onClick = _ref.onClick;
return React.createElement("div", { onClick: function onClick() {
return _onClick();
} });
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "react"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default (a) => {
return { a() { return a } };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

exports["default"] = function (_a) {
return {
a: function a() {
return _a;
}
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": ["es2015"],
"plugins": [
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default (a) => {
return { a() { return a } };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (_a) {
return {
a: function a() {
return _a;
}
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["transform-es2015-function-name", "transform-es2015-shorthand-properties", "transform-es2015-arrow-functions", "transform-es2015-modules-commonjs"]
}
16 changes: 9 additions & 7 deletions packages/babel-traverse/src/scope/lib/renamer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ export default class Renamer {
specifiers.push(t.exportSpecifier(t.identifier(localName), t.identifier(exportedName)));
}

let aliasDeclar = t.exportNamedDeclaration(null, specifiers);
if (specifiers.length) {
let aliasDeclar = t.exportNamedDeclaration(null, specifiers);

// hoist to the top if it's a function
if (parentDeclar.isFunctionDeclaration()) {
aliasDeclar._blockHoist = 3;
}
// hoist to the top if it's a function
if (parentDeclar.isFunctionDeclaration()) {
aliasDeclar._blockHoist = 3;
}

exportDeclar.insertAfter(aliasDeclar);
exportDeclar.replaceWith(parentDeclar.node);
exportDeclar.insertAfter(aliasDeclar);
exportDeclar.replaceWith(parentDeclar.node);
}
}

maybeConvertFromClassFunctionDeclaration(path) {
Expand Down

0 comments on commit f859830

Please sign in to comment.