File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ // to be used with typescript_walk_nodes.ts. Write stuff below, and see what nodes there are.
2
+
3
+
4
+ export interface LmaoInterface {
5
+
6
+ }
Original file line number Diff line number Diff line change
1
+ // sometimes it's useful to test with a target script and know what nodes there are
2
+
3
+
4
+ import * as fs from 'fs' ;
5
+ import * as path from 'path' ;
6
+ import * as ts from 'typescript' ;
7
+ import { visitNode , VisitResult } from 'typescript' ;
8
+
9
+ // visitor class
10
+ class MyVisitor {
11
+
12
+ readonly kinds : string [ ] ;
13
+
14
+ constructor ( ) {
15
+ this . kinds = [ ] ;
16
+ }
17
+
18
+ visit ( node : ts . Node ) : VisitResult < ts . Node > {
19
+ this . kinds . push ( ts . SyntaxKind [ node . kind ] ) ;
20
+ return node
21
+
22
+ }
23
+
24
+ }
25
+
26
+ const myVisitor = new MyVisitor ( )
27
+
28
+ // load & parse file
29
+ const fileName : string = path . resolve ( __dirname , 'target_test_script.ts' )
30
+ const sourceFile = ts . createSourceFile (
31
+ fileName ,
32
+ fs . readFileSync ( fileName , 'utf8' ) ,
33
+ ts . ScriptTarget . Latest ,
34
+ true ,
35
+ ) ;
36
+
37
+
38
+ // fixme: shouldn't pass in sourceFile here. Should convert sourceFile to a Node (maybe convert it to a Bundle first?)
39
+
40
+ // walk AST
41
+ visitNode ( sourceFile , n => myVisitor . visit ( n ) )
42
+
43
+ // show results
44
+ console . log ( myVisitor . kinds . join ( '\n' ) ) ;
You can’t perform that action at this time.
0 commit comments