@@ -51,6 +51,8 @@ interface ModuleInfo {
5151 ast : ReturnType < typeof parseAst >
5252 bindings : Map < string , Binding >
5353 exports : Map < string , ExportEntry >
54+ // Track `export * from './module'` declarations for re-export resolution
55+ reExportAllSources : Array < string >
5456}
5557
5658export class ServerFnCompiler {
@@ -86,6 +88,7 @@ export class ServerFnCompiler {
8688 exports : new Map ( ) ,
8789 code : '' ,
8890 id : libId ,
91+ reExportAllSources : [ ] ,
8992 }
9093 this . moduleCache . set ( libId , rootModule )
9194 }
@@ -116,6 +119,7 @@ export class ServerFnCompiler {
116119
117120 const bindings = new Map < string , Binding > ( )
118121 const exports = new Map < string , ExportEntry > ( )
122+ const reExportAllSources : Array < string > = [ ]
119123
120124 // we are only interested in top-level bindings, hence we don't traverse the AST
121125 // instead we only iterate over the program body
@@ -178,6 +182,16 @@ export class ServerFnCompiler {
178182 ? sp . exported . name
179183 : sp . exported . value
180184 exports . set ( exported , { tag : 'Normal' , name : local } )
185+
186+ // When re-exporting from another module (export { foo } from './module'),
187+ // create an import binding so the server function can be resolved
188+ if ( node . source ) {
189+ bindings . set ( local , {
190+ type : 'import' ,
191+ source : node . source . value ,
192+ importedName : local ,
193+ } )
194+ }
181195 }
182196 }
183197 } else if ( t . isExportDefaultDeclaration ( node ) ) {
@@ -189,10 +203,21 @@ export class ServerFnCompiler {
189203 bindings . set ( synth , { type : 'var' , init : d as t . Expression } )
190204 exports . set ( 'default' , { tag : 'Default' , name : synth } )
191205 }
206+ } else if ( t . isExportAllDeclaration ( node ) ) {
207+ // Handle `export * from './module'` syntax
208+ // Track the source so we can look up exports from it when needed
209+ reExportAllSources . push ( node . source . value )
192210 }
193211 }
194212
195- const info : ModuleInfo = { code, id, ast, bindings, exports }
213+ const info : ModuleInfo = {
214+ code,
215+ id,
216+ ast,
217+ bindings,
218+ exports,
219+ reExportAllSources,
220+ }
196221 this . moduleCache . set ( id , info )
197222 return info
198223 }
@@ -343,7 +368,43 @@ export class ServerFnCompiler {
343368
344369 const importedModule = await this . getModuleInfo ( target )
345370
371+ // Try to find the export in the module's direct exports
346372 const moduleExport = importedModule . exports . get ( binding . importedName )
373+
374+ // If not found directly, check re-export-all sources (`export * from './module'`)
375+ if ( ! moduleExport && importedModule . reExportAllSources . length > 0 ) {
376+ for ( const reExportSource of importedModule . reExportAllSources ) {
377+ const reExportTarget = await this . options . resolveId (
378+ reExportSource ,
379+ importedModule . id ,
380+ )
381+ if ( reExportTarget ) {
382+ const reExportModule = await this . getModuleInfo ( reExportTarget )
383+ const reExportEntry = reExportModule . exports . get (
384+ binding . importedName ,
385+ )
386+ if ( reExportEntry ) {
387+ // Found the export in a re-exported module, resolve from there
388+ const reExportBinding = reExportModule . bindings . get (
389+ reExportEntry . name ,
390+ )
391+ if ( reExportBinding ) {
392+ if ( reExportBinding . resolvedKind ) {
393+ return reExportBinding . resolvedKind
394+ }
395+ const resolvedKind = await this . resolveBindingKind (
396+ reExportBinding ,
397+ reExportModule . id ,
398+ visited ,
399+ )
400+ reExportBinding . resolvedKind = resolvedKind
401+ return resolvedKind
402+ }
403+ }
404+ }
405+ }
406+ }
407+
347408 if ( ! moduleExport ) {
348409 return 'None'
349410 }
0 commit comments