@@ -1337,9 +1337,43 @@ function recordTypes(
13371337 }
13381338 } else if ( stmt . type === 'TSModuleDeclaration' && stmt . global ) {
13391339 for ( const s of ( stmt . body as TSModuleBlock ) . body ) {
1340- if ( s . type === 'ExportNamedDeclaration' && s . declaration ) {
1341- // Handle export declarations inside declare global
1342- recordType ( s . declaration , types , declares )
1340+ if ( s . type === 'ExportNamedDeclaration' ) {
1341+ if ( s . declaration ) {
1342+ // Handle export declarations inside declare global
1343+ recordType ( s . declaration , types , declares )
1344+ } else if ( s . source ) {
1345+ // Handle re-exports inside declare global, e.g.
1346+ // `export type { Foo } from './foo'`. Global lookup only checks
1347+ // `types`/`declares`, so resolve the source eagerly.
1348+ const sourceScope = importSourceToScope (
1349+ ctx ,
1350+ s . source ,
1351+ scope ,
1352+ s . source . value ,
1353+ )
1354+ for ( const spec of s . specifiers ) {
1355+ if ( spec . type === 'ExportSpecifier' ) {
1356+ const exported = getId ( spec . exported )
1357+ const local = spec . local . name
1358+ if ( sourceScope . exportedTypes [ local ] ) {
1359+ types [ exported ] = sourceScope . exportedTypes [ local ]
1360+ }
1361+ if ( sourceScope . exportedDeclares [ local ] ) {
1362+ declares [ exported ] = sourceScope . exportedDeclares [ local ]
1363+ }
1364+ }
1365+ }
1366+ }
1367+ } else if ( s . type === 'ExportAllDeclaration' && s . source ) {
1368+ // Handle `export * from './foo'` inside declare global
1369+ const sourceScope = importSourceToScope (
1370+ ctx ,
1371+ s . source ,
1372+ scope ,
1373+ s . source . value ,
1374+ )
1375+ Object . assign ( types , sourceScope . exportedTypes )
1376+ Object . assign ( declares , sourceScope . exportedDeclares )
13431377 } else {
13441378 recordType ( s , types , declares )
13451379 }
0 commit comments