make shadowed function findParent target finder more reliable
This commit is contained in:
parent
a265c3f25c
commit
6359675a4f
@ -38,7 +38,7 @@ export var visitor = {
|
||||
|
||||
//
|
||||
var argsIdentifier = t.identifier("arguments");
|
||||
argsIdentifier._shadowedFunctionLiteral = node;
|
||||
argsIdentifier._shadowedFunctionLiteral = this;
|
||||
|
||||
// push a default parameter definition
|
||||
function pushDefNode(left, right, i) {
|
||||
|
||||
@ -84,7 +84,7 @@ export var visitor = {
|
||||
var argsId = t.identifier("arguments");
|
||||
|
||||
// otherwise `arguments` will be remapped in arrow functions
|
||||
argsId._shadowedFunctionLiteral = node;
|
||||
argsId._shadowedFunctionLiteral = this;
|
||||
|
||||
// support patterns
|
||||
if (t.isPattern(rest)) {
|
||||
|
||||
@ -211,7 +211,7 @@ class TailCallTransformer {
|
||||
var decl = t.variableDeclarator(this.argumentsId);
|
||||
if (this.argumentsId) {
|
||||
decl.init = t.identifier("arguments");
|
||||
decl.init._shadowedFunctionLiteral = node;
|
||||
decl.init._shadowedFunctionLiteral = this.path;
|
||||
}
|
||||
topVars.push(decl);
|
||||
}
|
||||
|
||||
@ -9,15 +9,31 @@ function remap(path, key, create) {
|
||||
if (!path.inShadow()) return;
|
||||
|
||||
var shadowed = path.node._shadowedFunctionLiteral;
|
||||
var currentFunction;
|
||||
|
||||
var fnPath = path.findParent(function (path) {
|
||||
if (shadowed) {
|
||||
return path.node === shadowed;
|
||||
// only match our shadowed function parent
|
||||
if (path === shadowed) {
|
||||
// found our target reference function
|
||||
currentFunction = path;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (path.isFunction() || path.isProgram()) {
|
||||
// catch current function in case this is the shadowed one
|
||||
if (!currentFunction) currentFunction = path;
|
||||
|
||||
return !path.is("shadow");
|
||||
} else {
|
||||
return !path.is("shadow") && (path.isFunction() || path.isProgram());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// no point in realiasing if we're in this function
|
||||
if (fnPath === currentFunction) return;
|
||||
|
||||
var cached = fnPath.getData(key);
|
||||
if (cached) return cached;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user