File tree Expand file tree Collapse file tree 2 files changed +18
-13
lines changed
Expand file tree Collapse file tree 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) {
55 return ( ctx : ts . TransformationContext ) => {
66 return ( sourceFile : ts . SourceFile ) => {
77 return ts . visitEachChild ( sourceFile , visitor , ctx ) ;
8-
98 function visitor ( node : ts . Node ) : ts . Node {
109 if ( ! ts . isEnumDeclaration ( node ) ) {
1110 return ts . visitEachChild ( node , visitor , ctx ) ;
@@ -16,7 +15,9 @@ export default function(program: ts.Program, pluginOptions?: unknown) {
1615 }
1716
1817 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 ) ) {
2021 return node ;
2122 }
2223 }
Original file line number Diff line number Diff line change @@ -76,22 +76,26 @@ export function hasModifier(node: ts.Node, modifier: ts.SyntaxKind) {
7676 ) ;
7777}
7878
79- const cachedMap = new WeakMap < ts . SourceFile , string [ ] > ( ) ;
79+ const cachedNames = new WeakMap < ts . SourceFile , string [ ] > ( ) ;
8080export function getExportedNamesOfSource ( program : ts . Program , sourceFile : ts . SourceFile ) {
81- const cached = cachedMap . get ( sourceFile ) ;
81+ const cached = cachedNames . get ( sourceFile ) ;
8282 if ( cached ) return cached ;
8383
8484 const typeChecker = program . getTypeChecker ( ) ;
8585 const sourceSymbol = typeChecker . getSymbolAtLocation ( sourceFile ) ;
86- if ( ! sourceSymbol ) return [ ] ;
86+ let names : string [ ] ;
8787
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+ }
9498
95- cachedMap . set ( sourceFile , symbols ) ;
96- return symbols ;
99+ cachedNames . set ( sourceFile , names ) ;
100+ return names ;
97101}
You can’t perform that action at this time.
0 commit comments