Move setting NOT_LOCAL_BINDING to the function name helper

This commit is contained in:
Amjad Masad 2016-01-22 14:07:57 -08:00
parent da106e2bf4
commit c1a7fc93d0
2 changed files with 6 additions and 9 deletions

View File

@ -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) {

View File

@ -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;
}