@@ -22,19 +22,43 @@ class TypeWriterWalker {
22
22
}
23
23
24
24
private visitNode ( node : ts . Node ) : void {
25
- if ( node . kind === ts . SyntaxKind . Identifier ) {
26
- var identifier = < ts . Identifier > node ;
27
- if ( ! this . isLabel ( identifier ) ) {
28
- var type = this . getTypeOfIdentifier ( identifier ) ;
29
- this . log ( node , type ) ;
30
- }
31
- }
32
- else if ( node . kind === ts . SyntaxKind . ThisKeyword ) {
33
- this . log ( node , undefined ) ;
34
- }
35
- else {
36
- ts . forEachChild ( node , child => this . visitNode ( child ) ) ;
25
+ switch ( node . kind ) {
26
+ // Should always log expressions that are not tokens
27
+ // Also, always log the "this" keyword
28
+ // TODO: Ideally we should log all expressions, but to compare to the
29
+ // old typeWriter baselines, suppress tokens
30
+ case ts . SyntaxKind . ThisKeyword :
31
+ case ts . SyntaxKind . RegularExpressionLiteral :
32
+ case ts . SyntaxKind . ArrayLiteral :
33
+ case ts . SyntaxKind . ObjectLiteral :
34
+ case ts . SyntaxKind . PropertyAccess :
35
+ case ts . SyntaxKind . IndexedAccess :
36
+ case ts . SyntaxKind . CallExpression :
37
+ case ts . SyntaxKind . NewExpression :
38
+ case ts . SyntaxKind . TypeAssertion :
39
+ case ts . SyntaxKind . ParenExpression :
40
+ case ts . SyntaxKind . FunctionExpression :
41
+ case ts . SyntaxKind . ArrowFunction :
42
+ case ts . SyntaxKind . PrefixOperator :
43
+ case ts . SyntaxKind . PostfixOperator :
44
+ case ts . SyntaxKind . BinaryExpression :
45
+ case ts . SyntaxKind . ConditionalExpression :
46
+ this . log ( node , this . getTypeOfNode ( node ) ) ;
47
+ break ;
48
+
49
+ // Should not change expression status (maybe expressions)
50
+ // TODO: Again, ideally should log number and string literals too,
51
+ // but to be consistent with the old typeWriter, just log identifiers
52
+ case ts . SyntaxKind . Identifier :
53
+ var identifier = < ts . Identifier > node ;
54
+ if ( ! this . isLabel ( identifier ) ) {
55
+ var type = this . getTypeOfNode ( identifier ) ;
56
+ this . log ( node , type ) ;
57
+ }
58
+ break ;
37
59
}
60
+
61
+ ts . forEachChild ( node , child => this . visitNode ( child ) ) ;
38
62
}
39
63
40
64
private isLabel ( identifier : ts . Identifier ) : boolean {
@@ -63,10 +87,8 @@ class TypeWriterWalker {
63
87
} ) ;
64
88
}
65
89
66
- private getTypeOfIdentifier ( node : ts . Identifier ) : ts . Type {
67
- var identifierSymbol = this . checker . getSymbolInfo ( node ) ;
68
- ts . Debug . assert ( identifierSymbol , "symbol doesn't exist" ) ;
69
- var type = this . checker . getTypeOfSymbol ( identifierSymbol ) ;
90
+ private getTypeOfNode ( node : ts . Node ) : ts . Type {
91
+ var type = this . checker . getTypeOfNode ( node , /*apparentType*/ false ) ;
70
92
ts . Debug . assert ( type , "type doesn't exist" ) ;
71
93
return type ;
72
94
}
0 commit comments