add BindingIdentifier virtual type

This commit is contained in:
Sebastian McKenzie 2015-06-14 20:21:02 +01:00
parent 708879ff1b
commit 52c3c143f9
3 changed files with 23 additions and 5 deletions

View File

@ -20,11 +20,8 @@ var visitor = {
visitIdentifier(this, node, scope, state);
},
AssignmentExpression(node, parent, scope, state) {
var ids = this.getBindingIdentifiers();
for (var name in ids) {
visitIdentifier(this, ids[name], scope, state);
}
BindingIdentifier(node, parent, scope, state) {
visitIdentifier(this, node, scope, state);
}
};

View File

@ -18,6 +18,13 @@ export var ReferencedIdentifier = {
}
};
export var BindingIdentifier = {
types: ["Identifier"],
checkPath({ node, parent }, opts) {
return t.isBinding(node, parent);
}
};
export var Expression = {
types: ["Expression"],
checkPath(path) {

View File

@ -1,6 +1,20 @@
import { getBindingIdentifiers } from "./retrievers";
import esutils from "esutils";
import * as t from "./index";
/**
*
*/
export function isBinding(node: Object, parent: Object): boolean {
var bindingKey = getBindingIdentifiers.keys[parent.type];
if (bindingKey) {
return parent[bindingKey] === node;
} else {
return false;
}
}
/**
* Check if the input `node` is a reference to a bound variable.
*/