@@ -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
@@ -796,7 +798,7 @@ public struct BridgeJSLink {
796798 return printer. lines
797799 }
798800
799- private func generateTypeScript( data: LinkData ) throws -> String {
801+ private func generateTypeScript( data: LinkData ) -> String {
800802 let header = """
801803 // NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit,
802804 // DO NOT EDIT.
@@ -884,11 +886,10 @@ public struct BridgeJSLink {
884886 printer. write ( lines: generateImportedTypeDefinitions ( ) )
885887
886888 // Exports type
887- let hierarchicalExportLines = try namespaceBuilder. buildHierarchicalExportsType (
889+ let hierarchicalExportLines = namespaceBuilder. buildHierarchicalExportsType (
888890 exportedSkeletons: exportedSkeletons,
889891 renderClassEntry: { klass in
890- let ( _, _, dtsExportEntry) = try self . renderExportedClass ( klass)
891- return dtsExportEntry
892+ data. namespacedClassDtsExportEntries [ klass. name] ?? [ ]
892893 } ,
893894 renderFunctionSignature: { function in
894895 " \( function. name) \( self . renderTSSignature ( parameters: function. parameters, returnType: function. returnType, effects: function. effects) ) ; "
@@ -1095,7 +1096,7 @@ public struct BridgeJSLink {
10951096 }
10961097 let data = try collectLinkData ( )
10971098 let outputJs = try generateJavaScript ( data: data)
1098- let outputDts = try generateTypeScript ( data: data)
1099+ let outputDts = generateTypeScript ( data: data)
10991100 return ( outputJs, outputDts)
11001101 }
11011102
@@ -2647,16 +2648,16 @@ extension BridgeJSLink {
26472648
26482649 fileprivate func buildHierarchicalExportsType(
26492650 exportedSkeletons: [ ExportedSkeleton ] ,
2650- renderClassEntry: ( ExportedClass ) throws -> [ String ] ,
2651+ renderClassEntry: ( ExportedClass ) -> [ String ] ,
26512652 renderFunctionSignature: ( ExportedFunction ) -> String
2652- ) throws -> [ String ] {
2653+ ) -> [ String ] {
26532654 let printer = CodeFragmentPrinter ( )
26542655 let rootNode = NamespaceNode ( name: " " )
26552656
26562657 buildExportsTree ( rootNode: rootNode, exportedSkeletons: exportedSkeletons)
26572658
26582659 for (_, node) in rootNode. children {
2659- try populateTypeScriptExportLines (
2660+ populateTypeScriptExportLines (
26602661 node: node,
26612662 renderClassEntry: renderClassEntry,
26622663 renderFunctionSignature: renderFunctionSignature
@@ -2670,16 +2671,16 @@ extension BridgeJSLink {
26702671
26712672 private func populateTypeScriptExportLines(
26722673 node: NamespaceNode ,
2673- renderClassEntry: ( ExportedClass ) throws -> [ String ] ,
2674+ renderClassEntry: ( ExportedClass ) -> [ String ] ,
26742675 renderFunctionSignature: ( ExportedFunction ) -> String
2675- ) throws {
2676+ ) {
26762677 for function in node. content. functions {
26772678 let signature = renderFunctionSignature ( function)
26782679 node. content. functionDtsLines. append ( ( function. name, [ signature] ) )
26792680 }
26802681
26812682 for klass in node. content. classes {
2682- let entry = try renderClassEntry ( klass)
2683+ let entry = renderClassEntry ( klass)
26832684 node. content. classDtsLines. append ( ( klass. name, entry) )
26842685 }
26852686
@@ -2688,7 +2689,7 @@ extension BridgeJSLink {
26882689 }
26892690
26902691 for (_, childNode) in node. children {
2691- try populateTypeScriptExportLines (
2692+ populateTypeScriptExportLines (
26922693 node: childNode,
26932694 renderClassEntry: renderClassEntry,
26942695 renderFunctionSignature: renderFunctionSignature
0 commit comments