add yes/no comments to describe what we're actually testing for in types.isReferenced

This commit is contained in:
Sebastian McKenzie
2015-01-28 20:21:25 +11:00
parent 2a47afebde
commit 3affa543ef

View File

@@ -234,22 +234,30 @@ t.prependToMemberExpression = function (member, append) {
*/
t.isReferenced = function (node, parent) {
// yes: { [NODE]: "" }
if (t.isProperty(parent)) {
return parent.key === node && parent.computed;
}
// no: function foo(...NODE) {}
if (t.isRestElement(parent)) {
return false;
}
// no: [NODE = foo] = [];
// yes: [foo = NODE] = [];
if (t.isAssignmentPattern(parent)) {
return parent.right !== node;
}
// no: [NODE] = [];
// no: ({ NODE }) = [];
if (t.isPattern(parent)) {
return false;
}
// no: function NODE() {}
// no: function foo(NODE) {}
if (t.isFunction(parent)) {
for (var i = 0; i < parent.params.length; i++) {
var param = parent.params[i];
@@ -259,38 +267,49 @@ t.isReferenced = function (node, parent) {
return parent.id !== node;
}
// no: class NODE {}
if (t.isClass(parent)) {
return parent.id !== node;
}
// yes: class { [NODE](){} }
if (t.isMethodDefinition(parent)) {
return parent.key === node && parent.computed;
}
// no: import NODE from "bar";
if (t.isImportSpecifier(parent)) {
return false;
}
// no: import * as NODE from "foo";
if (t.isImportBatchSpecifier(parent)) {
return false;
}
// no: NODE: for (;;) {}
if (t.isLabeledStatement(parent)) {
return false;
}
// no: try {} catch (NODE) {}
if (t.isCatchClause(parent)) {
return parent.param !== node;
}
// no: var NODE = init;
// yes: var id = NODE;
if (t.isVariableDeclarator(parent)) {
return parent.id !== node;
}
// yes: PARENT[NODE]
// yes: NODE.child
// no: parent.CHILD
if (t.isMemberExpression(parent)) {
if (parent.property === node && parent.computed) { // PARENT[NODE]
if (parent.property === node && parent.computed) {
return true;
} else if (parent.object === node) { // NODE.child
} else if (parent.object === node) {
return true;
} else {
return false;