File tree 2 files changed +18
-13
lines changed
2 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ export default function(program: ts.Program, pluginOptions?: unknown) {
5
5
return ( ctx : ts . TransformationContext ) => {
6
6
return ( sourceFile : ts . SourceFile ) => {
7
7
return ts . visitEachChild ( sourceFile , visitor , ctx ) ;
8
-
9
8
function visitor ( node : ts . Node ) : ts . Node {
10
9
if ( ! ts . isEnumDeclaration ( node ) ) {
11
10
return ts . visitEachChild ( node , visitor , ctx ) ;
@@ -16,7 +15,9 @@ export default function(program: ts.Program, pluginOptions?: unknown) {
16
15
}
17
16
18
17
if ( ! hasModifier ( node , ts . SyntaxKind . ExportKeyword ) ) {
19
- if ( ! getExportedNamesOfSource ( program , sourceFile ) . includes ( node . name . text ) ) {
18
+ const exportedNames = getExportedNamesOfSource ( program , sourceFile ) ;
19
+
20
+ if ( ! exportedNames . includes ( node . name . text ) ) {
20
21
return node ;
21
22
}
22
23
}
Original file line number Diff line number Diff line change @@ -76,22 +76,26 @@ export function hasModifier(node: ts.Node, modifier: ts.SyntaxKind) {
76
76
) ;
77
77
}
78
78
79
- const cachedMap = new WeakMap < ts . SourceFile , string [ ] > ( ) ;
79
+ const cachedNames = new WeakMap < ts . SourceFile , string [ ] > ( ) ;
80
80
export function getExportedNamesOfSource ( program : ts . Program , sourceFile : ts . SourceFile ) {
81
- const cached = cachedMap . get ( sourceFile ) ;
81
+ const cached = cachedNames . get ( sourceFile ) ;
82
82
if ( cached ) return cached ;
83
83
84
84
const typeChecker = program . getTypeChecker ( ) ;
85
85
const sourceSymbol = typeChecker . getSymbolAtLocation ( sourceFile ) ;
86
- if ( ! sourceSymbol ) return [ ] ;
86
+ let names : string [ ] ;
87
87
88
- const symbols = typeChecker . getExportsOfModule ( sourceSymbol ) . map ( s => {
89
- if ( s . flags & ts . SymbolFlags . Alias ) {
90
- return typeChecker . getAliasedSymbol ( s ) . name ;
91
- }
92
- return s . name ;
93
- } ) ;
88
+ if ( sourceSymbol ) {
89
+ names = typeChecker . getExportsOfModule ( sourceSymbol ) . map ( s => {
90
+ if ( s . flags & ts . SymbolFlags . Alias ) {
91
+ return typeChecker . getAliasedSymbol ( s ) . name ;
92
+ }
93
+ return s . name ;
94
+ } ) ;
95
+ } else {
96
+ names = [ ] ;
97
+ }
94
98
95
- cachedMap . set ( sourceFile , symbols ) ;
96
- return symbols ;
99
+ cachedNames . set ( sourceFile , names ) ;
100
+ return names ;
97
101
}
You can’t perform that action at this time.
0 commit comments