@@ -45,6 +45,18 @@ function resolveImportSource(spec, fromFile) {
4545 return null ;
4646}
4747
48+ // A name may be exported both as a value and as a type with the same identifier
49+ // (e.g. `export const X = ...; export type X = typeof X`). When merging entries
50+ // for the same name, treat the export as a value if any declaration is a value.
51+ function setExport ( exports , name , entry ) {
52+ const existing = exports . get ( name ) ;
53+ if ( existing ) {
54+ exports . set ( name , { ...entry , isType : existing . isType && entry . isType } ) ;
55+ } else {
56+ exports . set ( name , entry ) ;
57+ }
58+ }
59+
4860function declarationNames ( decl ) {
4961 if ( ! decl ) return [ ] ;
5062 switch ( decl . type ) {
@@ -85,7 +97,7 @@ function getModuleExports(filepath, stack = new Set()) {
8597 else if ( stmt . type === 'ExportAllDeclaration' )
8698 collectStarExports ( stmt , exports , filepath , stack ) ;
8799 else if ( stmt . type === 'ExportDefaultDeclaration' ) {
88- exports . set ( 'default' , {
100+ setExport ( exports , 'default' , {
89101 source : filepath ,
90102 localName : 'default' ,
91103 isType : false ,
@@ -104,7 +116,7 @@ function collectNamedExports(stmt, exports, filepath, stack) {
104116
105117 if ( stmt . declaration ) {
106118 for ( const { name, isType } of declarationNames ( stmt . declaration ) ) {
107- exports . set ( name , {
119+ setExport ( exports , name , {
108120 source : filepath ,
109121 localName : name ,
110122 isType : isType || stmtIsType ,
@@ -117,7 +129,7 @@ function collectNamedExports(stmt, exports, filepath, stack) {
117129 if ( ! stmt . source ) {
118130 for ( const spec of stmt . specifiers ?? [ ] ) {
119131 if ( spec . type !== 'ExportSpecifier' ) continue ;
120- exports . set ( idOrStr ( spec . exported ) , {
132+ setExport ( exports , idOrStr ( spec . exported ) , {
121133 source : filepath ,
122134 localName : idOrStr ( spec . local ) ,
123135 isType : stmtIsType || spec . exportKind === 'type' ,
@@ -152,7 +164,7 @@ function collectNamedExports(stmt, exports, filepath, stack) {
152164 }
153165 }
154166
155- exports . set ( idOrStr ( spec . exported ) , {
167+ setExport ( exports , idOrStr ( spec . exported ) , {
156168 source,
157169 bareSource,
158170 localName : local ,
@@ -167,7 +179,7 @@ function collectStarExports(stmt, exports, filepath, stack) {
167179 const targetFile = resolveImportSource ( stmt . source . value , filepath ) ;
168180
169181 if ( stmt . exported ) {
170- exports . set ( idOrStr ( stmt . exported ) , {
182+ setExport ( exports , idOrStr ( stmt . exported ) , {
171183 source : targetFile ,
172184 isType : stmtIsType ,
173185 kind : 'namespace' ,
0 commit comments