dry up types.getIds
This commit is contained in:
parent
12f66e852a
commit
40fdd2a828
@ -162,31 +162,17 @@ t.getIds = function (node, map) {
|
||||
|
||||
while (search.length) {
|
||||
var id = search.shift();
|
||||
if (!id) continue;
|
||||
|
||||
var nodeKey = t.getIds.nodes[id.type];
|
||||
var arrKey = t.getIds.arrays[id.type];
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
ids[id.name] = id;
|
||||
} else if (t.isArrayPattern(id)) {
|
||||
_.each(id.elements, function (elem) {
|
||||
search.push(elem);
|
||||
});
|
||||
} else if (t.isAssignmentExpression(id)) {
|
||||
search.push(id.left);
|
||||
} else if (t.isObjectPattern(id)) {
|
||||
_.each(id.properties, function (prop) {
|
||||
search.push(prop.value);
|
||||
});
|
||||
} else if (t.isVariableDeclaration(id)) {
|
||||
search = search.concat(id.declarations);
|
||||
} else if (t.isImportSpecifier(id) || t.isExportSpecifier(id) || t.isVariableDeclarator(id) || t.isFunctionDeclaration(id) || t.isClassDeclaration(id)) {
|
||||
search.push(id.id);
|
||||
} else if (t.isSpreadElement(id)) {
|
||||
search.push(id.argument);
|
||||
} else if (t.isExportDeclaration(id) || t.isImportDeclaration(id)) {
|
||||
search = search.concat(id.specifiers);
|
||||
} else if (t.isMemberExpression(id)) {
|
||||
search.push(id.object);
|
||||
} else if (t.isParenthesizedExpression(id)) {
|
||||
search.push(id.expression);
|
||||
} else if (nodeKey) {
|
||||
if (id[nodeKey]) search.push(id[nodeKey]);
|
||||
} else if (arrKey) {
|
||||
search = search.concat(id[arrKey] || []);
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,6 +180,27 @@ t.getIds = function (node, map) {
|
||||
return ids;
|
||||
};
|
||||
|
||||
t.getIds.nodes = {
|
||||
AssignmentExpression: "left",
|
||||
ImportSpecifier: "id",
|
||||
ExportSpecifier: "id",
|
||||
VariableDeclarator: "id",
|
||||
FunctionDeclaration: "id",
|
||||
ClassDeclaration: "id",
|
||||
ParenthesizedExpression: "expression",
|
||||
MemeberExpression: "object",
|
||||
SpreadElement: "argument",
|
||||
Property: "value"
|
||||
};
|
||||
|
||||
t.getIds.arrays = {
|
||||
ExportDeclaration: "specifiers",
|
||||
ImportDeclaration: "specifiers",
|
||||
VariableDeclaration: "declarations",
|
||||
ArrayPattern: "elements",
|
||||
ObjectPattern: "properties"
|
||||
};
|
||||
|
||||
t.inherits = function (child, parent) {
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user