|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | import * as ts from 'typescript';
|
|---|
| 2 | /** Wraps an AST node. Can be used as a tree using `children` or a linked list using `next` and `skip`. */
|
|---|
| 3 | export interface NodeWrap {
|
|---|
| 4 | /** The real AST node. */
|
|---|
| 5 | node: ts.Node;
|
|---|
| 6 | /** The SyntaxKind of `node`. */
|
|---|
| 7 | kind: ts.SyntaxKind;
|
|---|
| 8 | /** All immediate children of `node` that would be visited by `ts.forEachChild(node, cb)`. */
|
|---|
| 9 | children: NodeWrap[];
|
|---|
| 10 | /** Link to the next NodeWrap, depth-first. */
|
|---|
| 11 | next?: NodeWrap;
|
|---|
| 12 | /** Link to the next NodeWrap skipping all children of the current node. */
|
|---|
| 13 | skip?: NodeWrap;
|
|---|
| 14 | /** Link to the parent NodeWrap */
|
|---|
| 15 | parent?: NodeWrap;
|
|---|
| 16 | }
|
|---|
| 17 | export interface WrappedAst extends NodeWrap {
|
|---|
| 18 | node: ts.SourceFile;
|
|---|
| 19 | next: NodeWrap;
|
|---|
| 20 | skip: undefined;
|
|---|
| 21 | parent: undefined;
|
|---|
| 22 | }
|
|---|
| 23 | export interface ConvertedAst {
|
|---|
| 24 | /** nodes wrapped in a data structure with useful links */
|
|---|
| 25 | wrapped: WrappedAst;
|
|---|
| 26 | /** depth-first array of all nodes excluding SourceFile */
|
|---|
| 27 | flat: ReadonlyArray<ts.Node>;
|
|---|
| 28 | }
|
|---|
| 29 | /**
|
|---|
| 30 | * Takes a `ts.SourceFile` and creates data structures that are easier (or more performant) to traverse.
|
|---|
| 31 | * Note that there is only a performance gain if you can reuse these structures. It's not recommended for one-time AST walks.
|
|---|
| 32 | */
|
|---|
| 33 | export declare function convertAst(sourceFile: ts.SourceFile): ConvertedAst;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.