@@ -88,18 +88,35 @@ function patchTypes(pkg) {
88
88
return false
89
89
}
90
90
91
+ const isExported = new Set ( )
91
92
const shouldRemoveExport = new Set ( )
93
+
94
+ // pass 0: check all exported types
95
+ for ( const node of ast . program . body ) {
96
+ if ( node . type === 'ExportNamedDeclaration' && ! node . source ) {
97
+ for ( let i = 0 ; i < node . specifiers . length ; i ++ ) {
98
+ const spec = node . specifiers [ i ]
99
+ if ( spec . type === 'ExportSpecifier' ) {
100
+ isExported . add ( spec . local . name )
101
+ }
102
+ }
103
+ }
104
+ }
105
+
92
106
// pass 1: remove internals + add exports
93
107
for ( const node of ast . program . body ) {
94
108
if (
95
109
( node . type === 'TSTypeAliasDeclaration' ||
96
110
node . type === 'TSInterfaceDeclaration' ) &&
97
111
! node . id . name . startsWith ( `_` )
98
112
) {
99
- shouldRemoveExport . add ( node . id . name )
113
+ const name = node . id . name
114
+ shouldRemoveExport . add ( name )
100
115
if ( ! removeInternal ( node ) ) {
101
- // @ts -ignore
102
- s . prependLeft ( node . start , `export ` )
116
+ if ( isExported . has ( name ) ) {
117
+ // @ts -ignore
118
+ s . prependLeft ( node . start , `export ` )
119
+ }
103
120
// traverse further for internal properties
104
121
if ( node . type === 'TSInterfaceDeclaration' ) {
105
122
node . body . body . forEach ( removeInternal )
0 commit comments