@@ -88,18 +88,35 @@ function patchTypes(pkg) {
8888 return false
8989 }
9090
91+ const isExported = new Set ( )
9192 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+
92106 // pass 1: remove internals + add exports
93107 for ( const node of ast . program . body ) {
94108 if (
95109 ( node . type === 'TSTypeAliasDeclaration' ||
96110 node . type === 'TSInterfaceDeclaration' ) &&
97111 ! node . id . name . startsWith ( `_` )
98112 ) {
99- shouldRemoveExport . add ( node . id . name )
113+ const name = node . id . name
114+ shouldRemoveExport . add ( name )
100115 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+ }
103120 // traverse further for internal properties
104121 if ( node . type === 'TSInterfaceDeclaration' ) {
105122 node . body . body . forEach ( removeInternal )
0 commit comments