Merge pull request #5008 from babel/fix-5004

Don't try to visit ArrowFunctionExpression, they cannot be named
This commit is contained in:
Logan Smyth
2017-01-15 11:47:52 -08:00
committed by GitHub
10 changed files with 47 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ import nameFunction from "babel-helper-function-name";
export default function () {
return {
visitor: {
"ArrowFunctionExpression|FunctionExpression": {
FunctionExpression: {
exit(path) {
if (path.key !== "value" && !path.parentPath.isObjectProperty()) {
const replacement = nameFunction(path);

View File

@@ -0,0 +1,5 @@
// I don't know if this is a bug with arrow-functions spec: true
// or with function-name, but the functions are missing their names.
const x = () => x;
const y = x => x();
const z = { z: () => y(x) }.z;

View File

@@ -0,0 +1,16 @@
var _this = this;
// I don't know if this is a bug with arrow-functions spec: true
// or with function-name, but the functions are missing their names.
const x = function () {
babelHelpers.newArrowCheck(this, _this);
return x;
}.bind(this);
const y = function (x) {
babelHelpers.newArrowCheck(this, _this);
return x();
}.bind(this);
const z = { z: function z() {
babelHelpers.newArrowCheck(this, _this);
return y(x);
}.bind(this) }.z;

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-function-name", [ "transform-es2015-arrow-functions", { "spec": true } ]]
}

View File

@@ -0,0 +1,3 @@
const x = () => x;
const y = x => x();
const z = { z: () => y(x) }.z;

View File

@@ -0,0 +1,9 @@
const x = function x() {
return x;
};
const y = function y(x) {
return x();
};
const z = { z: function z() {
return y(x);
} }.z;

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-arrow-functions"]
}

View File

@@ -0,0 +1,2 @@
export const x = ({x}) => x;
export const y = function () {};

View File

@@ -0,0 +1,2 @@
export const x = ({ x }) => x;
export const y = function y() {};

View File

@@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-function-name"]
}