本文整理汇总了TypeScript中recast.visit函数的典型用法代码示例。如果您正苦于以下问题:TypeScript visit函数的具体用法?TypeScript visit怎么用?TypeScript visit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了visit函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: findRoutes
export default function findRoutes(routerAst): RouteNode {
let routeFn;
let isRouteMap = _.matches({
callee: {
object: { name: 'Router' },
property: { name: 'map' }
}
});
recast.visit(routerAst, {
visitCallExpression(path) {
let node = path.node;
if (isRouteMap(node)) {
routeFn = node;
}
return false;
}
});
let appRoute: RouteNode = {
node: routeFn,
parent: null,
children: null,
moduleName: 'application',
name: 'application'
};
appRoute.children = findChildRoutes(routeFn, appRoute);
return appRoute;
}
示例2: findChildRoutes
function findChildRoutes(routeFnNode: ESTree.FunctionExpression, parentRoute) {
let routeNodes: any[] = [];
let isRoute = _.matches({
callee: {
object: { type: 'ThisExpression' },
property: { name: 'route' }
}
});
recast.visit(routeFnNode, {
visitCallExpression(path) {
if (isRoute(path.node) && path.node !== parentRoute.node) {
routeNodes.push(path.node);
return false;
} else {
this.traverse(path);
}
}
});
return routeNodes.map(routeCallNode => {
let child: RouteNode = {
node: routeCallNode,
parent: parentRoute,
children: [],
moduleName: routeCallNode.arguments[0].value,
name: routeCallNode.arguments[0].value
};
child.children = findChildRoutes(routeCallNode, child);
return child;
});
}
示例3: defaultExportProps
export function defaultExportProps(ast) {
let directProps: ObjectProperty[] = [];
recast.visit(ast, {
visitExportDefaultDeclaration: function({ node: { declaration } }) {
let args = declaration.arguments;
if (args && args.length) {
directProps = _.last<any>(args).properties;
}
return false;
}
});
return directProps || [];
}
示例4: superClassIdentifier
export function superClassIdentifier(ast) {
let name: string | null = null;
recast.visit(ast, {
visitExportDefaultDeclaration: function({ node: { declaration } }) {
if (declaration.callee) {
let typeExpr = declaration.callee.object;
name = rootIdentifier(typeExpr);
} else {
name = null;
}
return false;
}
});
return name;
}
示例5: findImportPathForIdentifier
export function findImportPathForIdentifier(ast, name: string): string | null {
let importPath: string | null = null;
recast.visit(ast, {
//for some reason the nodePath here conforms to a different spec than the other
//paths, hence the funny business
visitImportDefaultSpecifier: function(path) {
if (
path.value.local.type === 'Identifier' &&
path.value.local.name === name
) {
importPath = path.parentPath.node.source.value;
}
return false;
}
});
return importPath;
}
示例6: findConsumedKeys
export function findConsumedKeys(astNode): string[] {
let isGet = _.matches({
callee: {
object: { type: 'ThisExpression' },
property: { name: 'get' }
}
});
let keys: string[] = [];
recast.visit(astNode, {
visitCallExpression(path) {
let getter = path.node;
if (isGet(getter)) {
keys.push(getter.arguments[0].value);
}
this.traverse(path);
}
});
return keys;
}
示例7: findThisGets
export function findThisGets(astNode, s: 'get' | 'set') {
let isGet = _.matches({
callee: {
object: { type: 'ThisExpression' },
property: { name: s }
}
});
let nodes: ESTree.CallExpression[] = [];
recast.visit(astNode, {
visitCallExpression(path) {
let getter = path.node;
if (isGet(getter)) {
nodes.push(getter);
}
this.traverse(path);
}
});
return nodes;
}
示例8: extractMixinIdentifiers
export function extractMixinIdentifiers(ast): string[] {
let mixinArgs: any[] = [];
recast.visit(ast, {
visitExportDefaultDeclaration: function({ node: { declaration } }) {
let args: any[] = declaration.arguments;
if (args && args.length > 1) {
mixinArgs = args.slice(0, -1);
} else {
mixinArgs = [];
}
return false;
}
});
return _(mixinArgs)
.filter({ type: 'Identifier' })
.map<string>('name')
.value();
}