From ccf2f56085708a9eac3c39fcf104473a5165b5e7 Mon Sep 17 00:00:00 2001 From: "Diogo Franco (Kovensky)" Date: Fri, 16 Dec 2016 11:14:39 +0900 Subject: [PATCH] Don't try to visit ArrowFunctionExpression, they cannot be named They will still be visited if the arrow functions are transformed to regular functions. Fixes #5004 --- .../src/index.js | 2 +- .../with-arrow-functions-transform/actual.js | 3 +++ .../with-arrow-functions-transform/expected.js | 9 +++++++++ .../with-arrow-functions-transform/options.json | 3 +++ .../test/fixtures/issues/5004/actual.js | 2 ++ .../test/fixtures/issues/5004/expected.js | 2 ++ .../test/fixtures/issues/5004/options.json | 3 +++ 7 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/actual.js create mode 100644 packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/expected.js create mode 100644 packages/babel-plugin-transform-es2015-function-name/test/fixtures/function-name/with-arrow-functions-transform/options.json create mode 100644 packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/actual.js create mode 100644 packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/expected.js create mode 100644 packages/babel-plugin-transform-es2015-function-name/test/fixtures/issues/5004/options.json 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 ab403e6ec5..d0d870377f 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/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 0000000000..c1e980a79f --- /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 0000000000..096e218d2d --- /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 0000000000..32ac45253f --- /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 0000000000..c8b74de50e --- /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 0000000000..e7a7ae72b4 --- /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 0000000000..f2178b7ef6 --- /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"] +}