@@ -130,6 +130,7 @@ public struct BridgeJSLink {
130130 var classLines : [ String ] = [ ]
131131 var dtsExportLines : [ String ] = [ ]
132132 var dtsClassLines : [ String ] = [ ]
133+ var namespacedClassDtsExportEntries : [ String : [ String ] ] = [ : ]
133134 var topLevelTypeLines : [ String ] = [ ]
134135 var topLevelDtsTypeLines : [ String ] = [ ]
135136 var importObjectBuilders : [ ImportObjectBuilder ] = [ ]
@@ -161,13 +162,14 @@ public struct BridgeJSLink {
161162 for klass in skeleton . classes {
162163 let ( jsType , dtsType , dtsExportEntry ) = try renderExportedClass ( klass )
163164 data . classLines . append ( contentsOf : jsType )
165+ data . dtsClassLines . append ( contentsOf : dtsType )
164166
165167 if klass . namespace == nil {
166168 data . exportsLines . append ( " \( klass . name ) , " )
167169 data . dtsExportLines . append ( contentsOf : dtsExportEntry )
170+ } else {
171+ data . namespacedClassDtsExportEntries [ klass . name ] = dtsExportEntry
168172 }
169-
170- data . dtsClassLines . append ( contentsOf : dtsType )
171173 }
172174
173175 // Process enums - collect top-level definitions and export entries
@@ -884,32 +886,21 @@ public struct BridgeJSLink {
884886 printer . write ( lines : generateImportedTypeDefinitions ( ) )
885887
886888 // Exports type
889+ let hierarchicalExportLines = namespaceBuilder . buildHierarchicalExportsType (
890+ exportedSkeletons : exportedSkeletons ,
891+ renderClassEntry : { klass in
892+ data . namespacedClassDtsExportEntries [ klass . name ] ?? [ ]
893+ } ,
894+ renderFunctionSignature : { function in
895+ " \( function . name ) \( self . renderTSSignature ( parameters : function . parameters , returnType : function . returnType , effects : function . effects ) ) ; "
896+ }
897+ )
887898 printer . write ( " export type Exports = { " )
888899 printer . indent {
889900 // Add non-namespaced items
890901 printer . write ( lines : data . dtsExportLines )
891-
892902 // Add hierarchical namespaced items
893- let hierarchicalLines = namespaceBuilder . buildHierarchicalExportsType (
894- exportedSkeletons : exportedSkeletons ,
895- renderClassEntry : { klass in
896- let printer = CodeFragmentPrinter ( )
897- printer . write ( " \( klass . name ) : { " )
898- printer . indent {
899- if let constructor = klass . constructor {
900- printer . write (
901- " new \( self . renderTSSignature ( parameters : constructor . parameters , returnType : . swiftHeapObject ( klass . name ) , effects : constructor . effects ) ) ; "
902- )
903- }
904- }
905- printer . write ( " } " )
906- return printer . lines
907- } ,
908- renderFunctionSignature : { function in
909- " \( function . name ) \( self . renderTSSignature ( parameters : function . parameters , returnType : function . returnType , effects : function . effects ) ) ; "
910- }
911- )
912- printer . write ( lines : hierarchicalLines )
903+ printer . write ( lines : hierarchicalExportLines )
913904 }
914905 printer . write ( " } " )
915906
0 commit comments