Urara-Blog/node_modules/.pnpm-store/v3/files/0e/050bb6746e7fdc96fd9a5380ea4ff13bd0fac1c4893b89e3820d21fa14c21fabc7f3372e3c0ac1f4a8836680e90f46921d20067f0135904941ef96dfd1f831
2022-08-14 01:14:53 +08:00

33 lines
1.3 KiB
Text

import * as ts from 'typescript';
/** Wraps an AST node. Can be used as a tree using `children` or a linked list using `next` and `skip`. */
export interface NodeWrap {
/** The real AST node. */
node: ts.Node;
/** The SyntaxKind of `node`. */
kind: ts.SyntaxKind;
/** All immediate children of `node` that would be visited by `ts.forEachChild(node, cb)`. */
children: NodeWrap[];
/** Link to the next NodeWrap, depth-first. */
next?: NodeWrap;
/** Link to the next NodeWrap skipping all children of the current node. */
skip?: NodeWrap;
/** Link to the parent NodeWrap */
parent?: NodeWrap;
}
export interface WrappedAst extends NodeWrap {
node: ts.SourceFile;
next: NodeWrap;
skip: undefined;
parent: undefined;
}
export interface ConvertedAst {
/** nodes wrapped in a data structure with useful links */
wrapped: WrappedAst;
/** depth-first array of all nodes excluding SourceFile */
flat: ReadonlyArray<ts.Node>;
}
/**
* Takes a `ts.SourceFile` and creates data structures that are easier (or more performant) to traverse.
* Note that there is only a performance gain if you can reuse these structures. It's not recommended for one-time AST walks.
*/
export declare function convertAst(sourceFile: ts.SourceFile): ConvertedAst;