@@ -10,7 +10,7 @@ import { SymbolAnalyzer, IFollowAliasesResult } from './SymbolAnalyzer';
1010import { TypeScriptHelpers } from '../../utils/TypeScriptHelpers' ;
1111import { AstSymbol } from './AstSymbol' ;
1212import { AstImport } from './AstImport' ;
13- import { AstEntryPoint , IAstNamedExport } from './AstEntryPoint' ;
13+ import { AstEntryPoint , IExportedMember } from './AstEntryPoint' ;
1414
1515export class AstSymbolTable {
1616 private _typeChecker : ts . TypeChecker ;
@@ -40,15 +40,6 @@ export class AstSymbolTable {
4040 private readonly _astEntryPointsBySourceFile : Map < ts . SourceFile , AstEntryPoint >
4141 = new Map < ts . SourceFile , AstEntryPoint > ( ) ;
4242
43- /**
44- * A mapping from a source filename to a list of type declaration references.
45- *
46- * For example, the file path "/project1/lib/example.d.ts" might map to an array
47- * such as [ "node", "es6-promise" ].
48- */
49- private readonly _typeDirectiveReferencesByFilePath : Map < string , ReadonlyArray < string > >
50- = new Map < string , ReadonlyArray < string > > ( ) ;
51-
5243 public constructor ( typeChecker : ts . TypeChecker ) {
5344 this . _typeChecker = typeChecker ;
5445 }
@@ -64,10 +55,10 @@ export class AstSymbolTable {
6455
6556 const exportSymbols : ts . Symbol [ ] = this . _typeChecker . getExportsOfModule ( rootFileSymbol ) || [ ] ;
6657
67- const exports : IAstNamedExport [ ] = [ ] ;
58+ const exportedMembers : IExportedMember [ ] = [ ] ;
6859
6960 for ( const exportSymbol of exportSymbols ) {
70- const astSymbol : AstSymbol | undefined = this . _fetchAstSymbol ( exportSymbol ) ;
61+ const astSymbol : AstSymbol | undefined = this . _fetchAstSymbol ( exportSymbol , true ) ;
7162
7263 if ( ! astSymbol ) {
7364 throw new Error ( 'Unsupported export: ' + exportSymbol . name ) ;
@@ -80,10 +71,10 @@ export class AstSymbolTable {
8071 console . log ( d . getDump ( ) ) ;
8172 }
8273
83- exports . push ( { name : exportSymbol . name , astSymbol : astSymbol } ) ;
74+ exportedMembers . push ( { name : exportSymbol . name , astSymbol : astSymbol } ) ;
8475 }
8576
86- astEntryPoint = new AstEntryPoint ( { exports } ) ;
77+ astEntryPoint = new AstEntryPoint ( { exportedMembers } ) ;
8778 this . _astEntryPointsBySourceFile . set ( sourceFile , astEntryPoint ) ;
8879 }
8980 return astEntryPoint ;
@@ -120,6 +111,7 @@ export class AstSymbolTable {
120111 case ts . SyntaxKind . ClassDeclaration :
121112 case ts . SyntaxKind . MethodDeclaration :
122113 case ts . SyntaxKind . PropertySignature :
114+ case ts . SyntaxKind . PropertyDeclaration :
123115 case ts . SyntaxKind . InterfaceDeclaration :
124116 case ts . SyntaxKind . FunctionDeclaration :
125117 case ts . SyntaxKind . ModuleDeclaration :
@@ -128,10 +120,14 @@ export class AstSymbolTable {
128120 return false ;
129121 }
130122
131- public tryGetSymbolForAstDeclaration ( node : ts . Node ) : ts . Symbol | undefined {
123+ public tryGetSymbolForNode ( node : ts . Node ) : ts . Symbol | undefined {
132124 return TypeScriptHelpers . getSymbolForDeclaration ( node as ts . Declaration ) ;
133125 }
134126
127+ public tryGetAstSymbol ( symbol : ts . Symbol ) : AstSymbol | undefined {
128+ return this . _fetchAstSymbol ( symbol , false ) ;
129+ }
130+
135131 /**
136132 * Used by analyze to recursively analyze the entire child tree.
137133 */
@@ -168,15 +164,15 @@ export class AstSymbolTable {
168164 return undefined ;
169165 }
170166
171- const symbol : ts . Symbol | undefined = this . tryGetSymbolForAstDeclaration ( node ) ;
167+ const symbol : ts . Symbol | undefined = this . tryGetSymbolForNode ( node ) ;
172168 if ( ! symbol ) {
173169 throw new Error ( 'Program Bug: Unable to find symbol for node' ) ;
174170 }
175171
176- return this . _fetchAstSymbol ( symbol ) ;
172+ return this . _fetchAstSymbol ( symbol , true ) ;
177173 }
178174
179- private _fetchAstSymbol ( symbol : ts . Symbol ) : AstSymbol | undefined {
175+ private _fetchAstSymbol ( symbol : ts . Symbol , addIfMissing : boolean ) : AstSymbol | undefined {
180176 const followAliasesResult : IFollowAliasesResult = SymbolAnalyzer . followAliases ( symbol , this . _typeChecker ) ;
181177
182178 const followedSymbol : ts . Symbol = followAliasesResult . followedSymbol ;
@@ -240,21 +236,18 @@ export class AstSymbolTable {
240236 let parentAstSymbol : AstSymbol | undefined = undefined ;
241237
242238 if ( arbitaryParent ) {
243- const parentSymbol : ts . Symbol | undefined = this . tryGetSymbolForAstDeclaration ( arbitaryParent ) ;
239+ const parentSymbol : ts . Symbol | undefined = this . tryGetSymbolForNode ( arbitaryParent ) ;
244240 if ( ! parentSymbol ) {
245241 throw new Error ( 'Program bug: missing parent symbol for declaration' ) ;
246242 }
247243
248- parentAstSymbol = this . _fetchAstSymbol ( parentSymbol ) ;
244+ parentAstSymbol = this . _fetchAstSymbol ( parentSymbol , addIfMissing ) ;
249245 }
250246
251247 // Okay, now while creating the declarations we will wire them up to the
252248 // their corresopnding parent declarations
253249 for ( const declaration of followedSymbol . declarations || [ ] ) {
254250
255- const typeDirectiveReferences : ReadonlyArray < string >
256- = this . _getTypeDirectiveReferences ( declaration ) ;
257-
258251 let parentAstDeclaration : AstDeclaration | undefined = undefined ;
259252 if ( parentAstSymbol ) {
260253 const parentDeclaration : ts . Node | undefined
@@ -271,7 +264,7 @@ export class AstSymbolTable {
271264 }
272265
273266 const astDeclaration : AstDeclaration = new AstDeclaration ( {
274- declaration, astSymbol, typeDirectiveReferences , parentAstDeclaration} ) ;
267+ declaration, astSymbol, parentAstDeclaration} ) ;
275268
276269 this . _astDeclarationsByDeclaration . set ( declaration , astDeclaration ) ;
277270 }
@@ -294,30 +287,4 @@ export class AstSymbolTable {
294287 }
295288 return undefined ;
296289 }
297-
298- private _getTypeDirectiveReferences ( node : ts . Node ) : ReadonlyArray < string > {
299- const sourceFile : ts . SourceFile = node . getSourceFile ( ) ;
300- if ( ! sourceFile || ! sourceFile . fileName ) {
301- return [ ] ;
302- }
303-
304- const cachedList : ReadonlyArray < string > | undefined
305- = this . _typeDirectiveReferencesByFilePath . get ( sourceFile . fileName ) ;
306- if ( cachedList ) {
307- return cachedList ;
308- }
309-
310- const list : string [ ] = [ ] ;
311-
312- for ( const typeReferenceDirective of sourceFile . typeReferenceDirectives ) {
313- const name : string = sourceFile . text . substring ( typeReferenceDirective . pos , typeReferenceDirective . end ) ;
314- if ( list . indexOf ( name ) < 0 ) {
315- list . push ( name ) ;
316- }
317- }
318-
319- this . _typeDirectiveReferencesByFilePath . set ( sourceFile . fileName , list ) ;
320- return list ;
321- }
322-
323290}
0 commit comments