diff --git a/packages/babel-helper-define-map/src/index.js b/packages/babel-helper-define-map/src/index.js index 4e1b7eccf5..43c5c5a1c2 100644 --- a/packages/babel-helper-define-map/src/index.js +++ b/packages/babel-helper-define-map/src/index.js @@ -63,15 +63,6 @@ export function push(mutatorMap: Object, node: Object, kind: string, file, scope // infer function name if (scope && t.isStringLiteral(key) && (kind === "value" || kind === "initializer") && t.isFunctionExpression(value)) { value = nameFunction({ id: key, node: value, scope }); - - // Class methods don't have their name bound in the funciton body. - if (t.isClassMethod(node)) { - if (value.id) { - value.id[t.NOT_LOCAL_BINDING] = true; - } else if (t.isCallExpression(value) && t.isFunctionExpression(value.callee) && value.callee.id) { - value.callee.id[t.NOT_LOCAL_BINDING] = true; - } - } } if (value) { diff --git a/packages/babel-helper-function-name/src/index.js b/packages/babel-helper-function-name/src/index.js index ef06bb0993..544c504a6e 100644 --- a/packages/babel-helper-function-name/src/index.js +++ b/packages/babel-helper-function-name/src/index.js @@ -141,6 +141,7 @@ export default function ({ node, parent, scope, id }) { if (binding && binding.constant && scope.getBinding(id.name) === binding) { // always going to reference this method node.id = id; + node.id[t.NOT_LOCAL_BINDING] = true; return; } } @@ -163,6 +164,11 @@ export default function ({ node, parent, scope, id }) { name = t.toBindingIdentifierName(name); id = t.identifier(name); + // The id shouldn't be considered a local binding to the function because + // we are simply trying to set the function name and not actually create + // a local binding. + id[t.NOT_LOCAL_BINDING] = true; + let state = visit(node, name, scope); return wrap(state, node, id, scope) || node; }