typescript-node-ids
Version:
TypeScript support for naming Nodes uniquely and query them per SourceFile. This really make sense in libraries like ts-simple-ast when modifying AST in a loop. Implementations for native typescript compiler API and ts-simple-ast library
17 lines (16 loc) • 676 B
JavaScript
;
// import { Node, SourceFile } from 'typescript'
// import * as ts from 'typescript'
// import { Id } from './index'
// export type Visitor = (node: Node, level: number, childIndex: number, parentNode: Node) => void
// export function visit_forEachChild(node: Node, visitor: Visitor, file: SourceFile, level: number = 0, childIndex: number = 0) {
// if (!node) {
// return
// }
// visitor(node, level, childIndex, node.parent||file)
// let index = 0
// node.forEachChild(child => visit_forEachChild(child, visitor, file, level + 1, index++))
// }
// export function getKindName(kind: ts.SyntaxKind) {
// return (ts as any).SyntaxKind[kind];
// }