change NodePath#findParent to only call callback with path instead of node

This commit is contained in:
Sebastian McKenzie 2015-06-08 00:29:46 +01:00
parent c91baee4d5
commit 8cea575e2e
6 changed files with 6 additions and 6 deletions

View File

@ -8,7 +8,7 @@ function remap(path, key, create) {
// ensure that we're shadowed
if (!path.inShadow()) return;
var fnPath = path.findParent((node, path) => !node.shadow && (path.isFunction() || path.isProgram()));
var fnPath = path.findParent((path) => !path.is("shadow") && (path.isFunction() || path.isProgram()));
var cached = fnPath.getData(key);
if (cached) return cached;

View File

@ -44,7 +44,7 @@ export function ReferencedIdentifier(node, parent, scope) {
if (binding.path.scope.parent !== scope) return;
}
if (this.findParent((node) => node === replacement)) {
if (this.findParent((path) => path.node === replacement)) {
return;
}

View File

@ -26,7 +26,7 @@ export var Program = {
};
export function ThisExpression() {
if (!this.findParent((node) => !node.shadow && THIS_BREAK_KEYS.indexOf(node.type) >= 0)) {
if (!this.findParent((path) => !path.is("shadow") && THIS_BREAK_KEYS.indexOf(path.type) >= 0)) {
return t.identifier("undefined");
}
}

View File

@ -5,7 +5,7 @@
export function findParent(callback) {
var path = this;
while (path) {
if (callback(path.node, path)) return path;
if (callback(path)) return path;
path = path.parentPath;
}
return null;

View File

@ -158,7 +158,7 @@ export function replaceExpressionWithStatements(nodes: Array) {
for (var i = 0; i < last.length; i++) {
var lastNode = last[i];
if (lastNode.isExpressionStatement()) {
var loop = lastNode.findParent((node, path) => path.isLoop());
var loop = lastNode.findParent((path) => path.isLoop());
if (loop) {
var uid = this.get("callee").scope.generateDeclaredUidIdentifier("ret");
this.get("callee.body").pushContainer("body", t.returnStatement(uid));

View File

@ -160,7 +160,7 @@ export function _getTypeAnnotation(force?: boolean): ?Object {
}
if (this.isReturnStatement()) {
var funcPath = this.findParent((node, path) => path.isFunction());
var funcPath = this.findParent((path) => path.isFunction());
if (!funcPath) return;
var returnType = funcPath.node.returnType;