當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。