Avoid renaming this bindings in simple arrow function cases.

This commit is contained in:
Logan Smyth
2016-03-06 17:06:19 -08:00
parent db3a43869c
commit 51ddeade8a
2 changed files with 46 additions and 39 deletions

View File

@@ -30,6 +30,7 @@ function remap(path, key, create) {
let shadowFunction = path.node._shadowedFunctionLiteral;
let currentFunction;
let passedShadowFunction = false;
let fnPath = path.findParent(function (path) {
if (path.isProgram() || path.isFunction()) {
@@ -38,13 +39,18 @@ function remap(path, key, create) {
}
if (path.isProgram()) {
passedShadowFunction = true;
return true;
} else if (path.isFunction() && !path.isArrowFunctionExpression()) {
if (shadowFunction) {
return path === shadowFunction || path.node === shadowFunction.node;
if (path === shadowFunction || path.node === shadowFunction.node) return true;
} else {
return !path.is("shadow");
if (!path.is("shadow")) return true;
}
passedShadowFunction = true;
return false;
}
return false;
@@ -53,6 +59,10 @@ function remap(path, key, create) {
// no point in realiasing if we're in this function
if (fnPath === currentFunction) return;
// If the only functions that were encountered are arrow functions, skip remapping the
// binding since arrow function syntax already does that.
if (!passedShadowFunction) return;
let cached = fnPath.getData(key);
if (cached) return path.replaceWith(cached);