@@ -29,8 +29,19 @@ export async function collectModuleExports(
2929 collectTypeOnlyLocals ( node , info . typeOnlyLocals )
3030 }
3131
32- for ( const node of nodes ) {
33- await collectExportInfo ( context , node , id , info )
32+ // Resolve every export source concurrently. Resolving a source module loads
33+ // it, so a barrel file with many re-exports would otherwise load them one by
34+ // one and delay generating their declarations.
35+ const sources = await Promise . all (
36+ nodes . map ( ( node ) =>
37+ node . type === 'ExportNamedDeclaration' ||
38+ ( node . type === 'ExportAllDeclaration' && ! node . exported )
39+ ? resolveExportSource ( context , node . source , id )
40+ : undefined ,
41+ ) ,
42+ )
43+ for ( const [ i , node ] of nodes . entries ( ) ) {
44+ collectExportInfo ( node , sources [ i ] , info )
3445 }
3546
3647 return info
@@ -107,12 +118,11 @@ function isTypeOnlyExport(
107118 return node . exportKind === 'type' || specifier . exportKind === 'type'
108119}
109120
110- async function collectExportInfo (
111- context : TransformPluginContext ,
121+ function collectExportInfo (
112122 node : t . ProgramStatement ,
113- id : string ,
123+ source : string | undefined ,
114124 info : ModuleExports ,
115- ) : Promise < void > {
125+ ) : void {
116126 if ( node . type === 'ExportNamedDeclaration' ) {
117127 if ( node . declaration ) {
118128 for ( const name of collectDeclarationNames ( node . declaration ) ) {
@@ -121,7 +131,6 @@ async function collectExportInfo(
121131 return
122132 }
123133
124- const source = await resolveExportSource ( context , node . source , id )
125134 for ( const specifier of node . specifiers ) {
126135 const typeOnly = isTypeOnlyExport ( node , specifier )
127136
@@ -149,7 +158,7 @@ async function collectExportInfo(
149158 }
150159
151160 info . exportAlls . push ( {
152- source : await resolveExportSource ( context , node . source , id ) ,
161+ source,
153162 rawSource : node . source . value ,
154163 typeOnly : node . exportKind === 'type' ,
155164 } )
0 commit comments