Skip to content

Commit

Permalink
Introduce WrappedAst iterface to correctly model type of wrapped Sour…
Browse files Browse the repository at this point in the history
…ceFile
  • Loading branch information
ajafff committed Jan 16, 2018
1 parent 7287971 commit 02b1427
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions util/convert-ast.ts
Expand Up @@ -16,9 +16,15 @@ export interface NodeWrap {
parent?: NodeWrap;
}

export interface WrappedAst extends NodeWrap {
next: NodeWrap;
skip: undefined;
parent: undefined;
}

export interface ConvertedAst {
/** nodes wrapped in a data structure with useful links */
wrapped: NodeWrap;
wrapped: WrappedAst;
/** depth-first array of all nodes */
flat: ReadonlyArray<ts.Node>;
}
Expand All @@ -28,16 +34,16 @@ export interface ConvertedAst {
* Note that there is only a performance gain if you can reuse these structures. It's not recommended for one-time AST walks.
*/
export function convertAst(sourceFile: ts.SourceFile): ConvertedAst {
const wrapped: NodeWrap = {
const wrapped: WrappedAst = {
node: sourceFile,
parent: undefined,
kind: ts.SyntaxKind.SourceFile,
children: [],
next: undefined,
next: <any>undefined,
skip: undefined,
};
const flat: ts.Node[] = [];
let current = wrapped;
let current: NodeWrap = wrapped;
let previous = current;
ts.forEachChild(sourceFile, function wrap(node) {
flat.push(node);
Expand Down

0 comments on commit 02b1427

Please sign in to comment.