Method names should not be bound to body

As an artificat of compiling methods to named function expressions the
function name is being considered a "local" binding in the function
body. This means that we will throw errors anytime someone would want to
create a new local binding with the same name.

This is solved by assigning a symbol to function Identifiers that
indicates that they should not be considered local bindings.
This commit is contained in:
Amjad Masad
2016-01-17 13:19:37 -08:00
parent 9d0a05ecde
commit 95c93dd22b
5 changed files with 32 additions and 2 deletions

View File

@@ -63,6 +63,11 @@ 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)) {
value.id[t.NOT_LOCAL_BINDING] = true
}
}
if (value) {