Add experimental AstServiceParser

This commit is contained in:
Kim Biesbjerg
2017-01-28 15:22:08 +01:00
parent 303fb1b6de
commit 1c3915ff43
6 changed files with 349 additions and 5 deletions

19
src/utils/ast-utils.ts Normal file
View File

@@ -0,0 +1,19 @@
import * as ts from 'typescript';
export function printAllChildren(sourceFile: ts.SourceFile, node: ts.Node, depth = 0) {
console.log(
new Array(depth + 1).join('----'),
`[${node.kind}]`,
syntaxKindToName(node.kind),
`[pos: ${node.pos}-${node.end}]`,
':\t\t\t',
node.getFullText(sourceFile).trim()
);
depth++;
node.getChildren(sourceFile).forEach(childNode => printAllChildren(sourceFile, childNode, depth));
}
export function syntaxKindToName(kind: ts.SyntaxKind) {
return ts.SyntaxKind[kind];
}