@@ -14,6 +14,7 @@ import { AstImport } from './AstImport';
14
14
import { MessageRouter } from '../collector/MessageRouter' ;
15
15
import { TypeScriptInternals , IGlobalVariableAnalyzer } from './TypeScriptInternals' ;
16
16
import { StringChecks } from './StringChecks' ;
17
+ import { SourceFileLocationFormatter } from './SourceFileLocationFormatter' ;
17
18
18
19
export type AstEntity = AstSymbol | AstImport ;
19
20
@@ -61,9 +62,11 @@ export interface IFetchAstSymbolOptions {
61
62
export class AstSymbolTable {
62
63
private readonly _program : ts . Program ;
63
64
private readonly _typeChecker : ts . TypeChecker ;
65
+ private readonly _messageRouter : MessageRouter ;
64
66
private readonly _globalVariableAnalyzer : IGlobalVariableAnalyzer ;
65
67
private readonly _packageMetadataManager : PackageMetadataManager ;
66
68
private readonly _exportAnalyzer : ExportAnalyzer ;
69
+ private readonly _alreadyWarnedGlobalNames : Set < string > ;
67
70
68
71
/**
69
72
* A mapping from ts.Symbol --> AstSymbol
@@ -90,6 +93,7 @@ export class AstSymbolTable {
90
93
91
94
this . _program = program ;
92
95
this . _typeChecker = typeChecker ;
96
+ this . _messageRouter = messageRouter ;
93
97
this . _globalVariableAnalyzer = TypeScriptInternals . getGlobalVariableAnalyzer ( program ) ;
94
98
this . _packageMetadataManager = new PackageMetadataManager ( packageJsonLookup , messageRouter ) ;
95
99
@@ -102,6 +106,8 @@ export class AstSymbolTable {
102
106
fetchAstSymbol : this . _fetchAstSymbol . bind ( this )
103
107
}
104
108
) ;
109
+
110
+ this . _alreadyWarnedGlobalNames = new Set < string > ( ) ;
105
111
}
106
112
107
113
/**
@@ -345,7 +351,13 @@ export class AstSymbolTable {
345
351
// that include interesting global variables in their API, but API Extractor doesn't support
346
352
// that yet; it would be a feature request.)
347
353
348
- // console.log(`Ignoring reference to global variable ${identifierNode.text}`);
354
+ if ( this . _messageRouter . showDiagnostics ) {
355
+ if ( ! this . _alreadyWarnedGlobalNames . has ( identifierNode . text ) ) {
356
+ this . _alreadyWarnedGlobalNames . add ( identifierNode . text ) ;
357
+ this . _messageRouter . logDiagnostic ( `Ignoring reference to global variable "${ identifierNode . text } "`
358
+ + ` in ` + SourceFileLocationFormatter . formatDeclaration ( identifierNode ) ) ;
359
+ }
360
+ }
349
361
} else {
350
362
// If you encounter this, please report a bug with a repro. We're interested to know
351
363
// how it can occur.
0 commit comments