diff --git a/packages/babel-plugin-transform-es2015-function-name/src/index.js b/packages/babel-plugin-transform-es2015-function-name/src/index.js index ab403e6ec5f1..d0d870377f27 100644 --- a/packages/babel-plugin-transform-es2015-function-name/src/index.js +++ b/packages/babel-plugin-transform-es2015-function-name/src/index.js @@ -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()) { let replacement = nameFunction(path); diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/actual.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/actual.js new file mode 100644 index 000000000000..f56af5c6019b --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/actual.js @@ -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; diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/expected.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/expected.js new file mode 100644 index 000000000000..b842455daeea --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/expected.js @@ -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; \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/options.json b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/options.json new file mode 100644 index 000000000000..d66c99f2625e --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name", [ "transform-es2015-arrow-functions", { "spec": true } ]] +} diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/actual.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/actual.js new file mode 100644 index 000000000000..c1e980a79f76 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/actual.js @@ -0,0 +1,3 @@ +const x = () => x; +const y = x => x(); +const z = { z: () => y(x) }.z; diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/expected.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/expected.js new file mode 100644 index 000000000000..096e218d2d5d --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/expected.js @@ -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; \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/options.json b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/options.json new file mode 100644 index 000000000000..32ac45253fdc --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name", "transform-es2015-arrow-functions"] +} diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/actual.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/actual.js new file mode 100644 index 000000000000..c8b74de50e1d --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/actual.js @@ -0,0 +1,2 @@ +export const x = ({x}) => x; +export const y = function () {}; diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/expected.js b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/expected.js new file mode 100644 index 000000000000..e7a7ae72b464 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/expected.js @@ -0,0 +1,2 @@ +export const x = ({ x }) => x; +export const y = function y() {}; \ No newline at end of file diff --git a/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/options.json b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/options.json new file mode 100644 index 000000000000..f2178b7ef6bd --- /dev/null +++ b/packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-es2015-function-name"] +}