typescript#isImportDeclaration TypeScript Examples

The following examples show how to use typescript#isImportDeclaration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: collect-import-nodes.ts    From import-conductor with MIT License 6 votes vote down vote up
export function collectImportNodes(rootNode: Node): Node[] {
  const importNodes: Node[] = [];
  const traverse = (node: Node) => {
    if (isImportDeclaration(node)) {
      importNodes.push(node);
    }
  };
  rootNode.forEachChild(traverse);

  return importNodes;
}
Example #2
Source File: collect-non-import-nodes.ts    From import-conductor with MIT License 6 votes vote down vote up
export function collectNonImportNodes(rootNode: Node, lastImport: Node): Node[] {
  const nonImportNodes: Node[] = [];
  let importsEnded = false;
  const traverse = (node: Node) => {
    importsEnded = importsEnded || node === lastImport;
    if (!importsEnded) {
      if (!isImportDeclaration(node)) {
        nonImportNodes.push(node);
      }
    }
  };
  rootNode.forEachChild(traverse);

  return nonImportNodes;
}