当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript recast.visit函数代码示例

本文整理汇总了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;
}
开发者ID:Bestra,项目名称:ember-analyzer,代码行数:31,代码来源:routeGraph.ts

示例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;
  });
}
开发者ID:Bestra,项目名称:ember-analyzer,代码行数:32,代码来源:routeGraph.ts

示例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 || [];
}
开发者ID:Bestra,项目名称:ember-analyzer,代码行数:13,代码来源:ast.ts

示例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;
}
开发者ID:Bestra,项目名称:ember-analyzer,代码行数:15,代码来源:ast.ts

示例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;
}
开发者ID:Bestra,项目名称:ember-analyzer,代码行数:17,代码来源:ast.ts

示例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;
}
开发者ID:Bestra,项目名称:ember-analyzer,代码行数:19,代码来源:ast.ts

示例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;
}
开发者ID:Bestra,项目名称:ember-analyzer,代码行数:19,代码来源:ast.ts

示例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();
}
开发者ID:Bestra,项目名称:ember-analyzer,代码行数:20,代码来源:ast.ts


注:本文中的recast.visit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。