@@ -232,7 +232,9 @@ public struct BridgeJSLink {
232232 var structExportEntries : [ ( js: [ String ] , dts: [ String ] ) ] = [ ]
233233 for structDefinition in skeleton. structs {
234234 let ( jsStruct, dtsType, dtsExportEntry) = try renderExportedStruct ( structDefinition)
235- data. topLevelDtsTypeLines. append ( contentsOf: dtsType)
235+ if structDefinition. namespace == nil {
236+ data. topLevelDtsTypeLines. append ( contentsOf: dtsType)
237+ }
236238
237239 if structDefinition. namespace == nil && ( !jsStruct. isEmpty || !dtsExportEntry. isEmpty) {
238240 structExportEntries. append ( ( js: jsStruct, dts: dtsExportEntry) )
@@ -492,15 +494,15 @@ public struct BridgeJSLink {
492494 printer. write ( " bjs[ \" swift_js_struct_lower_ \( structDef. abiName) \" ] = function(objectId) { " )
493495 printer. indent {
494496 printer. write (
495- " \( JSGlueVariableScope . reservedStructHelpers) . \( structDef. name ) .lower( \( JSGlueVariableScope . reservedSwift) .memory.getObject(objectId)); "
497+ " \( JSGlueVariableScope . reservedStructHelpers) . \( structDef. abiName ) .lower( \( JSGlueVariableScope . reservedSwift) .memory.getObject(objectId)); "
496498 )
497499 }
498500 printer. write ( " } " )
499501
500502 printer. write ( " bjs[ \" swift_js_struct_lift_ \( structDef. abiName) \" ] = function() { " )
501503 printer. indent {
502504 printer. write (
503- " const value = \( JSGlueVariableScope . reservedStructHelpers) . \( structDef. name ) .lift(); "
505+ " const value = \( JSGlueVariableScope . reservedStructHelpers) . \( structDef. abiName ) .lift(); "
504506 )
505507 printer. write ( " return \( JSGlueVariableScope . reservedSwift) .memory.retain(value); " )
506508 }
@@ -1005,7 +1007,7 @@ public struct BridgeJSLink {
10051007 let structScope = JSGlueVariableScope ( intrinsicRegistry: intrinsicRegistry)
10061008 let fragment = IntrinsicJSFragment . structHelper ( structDefinition: structDef, allStructs: allStructs)
10071009 _ = try fragment. printCode (
1008- [ structDef. name ] ,
1010+ [ structDef. abiName ] ,
10091011 IntrinsicJSFragment . PrintCodeContext (
10101012 scope: structScope,
10111013 printer: structPrinter,
@@ -1159,10 +1161,10 @@ public struct BridgeJSLink {
11591161 for skeleton in skeletons. compactMap ( \. exported) {
11601162 for structDef in skeleton. structs {
11611163 printer. write (
1162- " const \( structDef. name ) Helpers = __bjs_create \( structDef. name ) Helpers(); "
1164+ " const \( structDef. abiName ) Helpers = __bjs_create \( structDef. abiName ) Helpers(); "
11631165 )
11641166 printer. write (
1165- " \( JSGlueVariableScope . reservedStructHelpers) . \( structDef. name ) = \( structDef. name ) Helpers; "
1167+ " \( JSGlueVariableScope . reservedStructHelpers) . \( structDef. abiName ) = \( structDef. abiName ) Helpers; "
11661168 )
11671169 printer. nextLine ( )
11681170 }
@@ -2616,6 +2618,7 @@ extension BridgeJSLink {
26162618 var functions : [ ExportedFunction ] = [ ]
26172619 var classes : [ ExportedClass ] = [ ]
26182620 var enums : [ ExportedEnum ] = [ ]
2621+ var structs : [ ExportedStruct ] = [ ]
26192622 var staticProperties : [ ExportedProperty ] = [ ]
26202623 var functionJsLines : [ ( name: String , lines: [ String ] ) ] = [ ]
26212624 var functionDtsLines : [ ( name: String , lines: [ String ] ) ] = [ ]
@@ -2664,6 +2667,14 @@ extension BridgeJSLink {
26642667 currentNode. content. classes. append ( klass)
26652668 }
26662669
2670+ for structDef in skeleton. structs where structDef. namespace != nil {
2671+ var currentNode = rootNode
2672+ for part in structDef. namespace! {
2673+ currentNode = currentNode. addChild ( part)
2674+ }
2675+ currentNode. content. structs. append ( structDef)
2676+ }
2677+
26672678 for enumDef in skeleton. enums where enumDef. namespace != nil && enumDef. enumType != . namespace {
26682679 var currentNode = rootNode
26692680 for part in enumDef. namespace! {
@@ -2845,8 +2856,18 @@ extension BridgeJSLink {
28452856 }
28462857 }
28472858
2859+ private func hasExportContent( node: NamespaceNode ) -> Bool {
2860+ if !node. content. classDtsLines. isEmpty || !node. content. enumDtsLines. isEmpty
2861+ || !node. content. functionDtsLines. isEmpty || !node. content. staticProperties. isEmpty
2862+ {
2863+ return true
2864+ }
2865+ return node. children. values. contains ( where: { hasExportContent ( node: $0) } )
2866+ }
2867+
28482868 private func printExportsTypeHierarchy( node: NamespaceNode , printer: CodeFragmentPrinter ) {
28492869 for (childName, childNode) in node. children. sorted ( by: { $0. key < $1. key } ) {
2870+ guard hasExportContent ( node: childNode) else { continue }
28502871 printer. write ( " \( childName) : { " )
28512872 printer. indent {
28522873 for (_, lines) in childNode. content. classDtsLines. sorted ( by: { $0. name < $1. name } ) {
@@ -2983,8 +3004,8 @@ extension BridgeJSLink {
29833004 renderTSSignatureCallback: @escaping ( [ Parameter ] , BridgeType , Effects ) -> String
29843005 ) {
29853006 func hasContent( node: NamespaceNode ) -> Bool {
2986- // Enums are always included
2987- if !node. content. enums. isEmpty {
3007+ // Enums and structs are always included
3008+ if !node. content. enums. isEmpty || !node . content . structs . isEmpty {
29883009 return true
29893010 }
29903011
@@ -3164,6 +3185,23 @@ extension BridgeJSLink {
31643185 }
31653186 }
31663187
3188+ // Generate struct interface definitions
3189+ let sortedStructs = childNode. content. structs. sorted { $0. name < $1. name }
3190+ for structDef in sortedStructs {
3191+ let instanceProps = structDef. properties. filter { !$0. isStatic }
3192+ printer. write ( " export interface \( structDef. name) { " )
3193+ printer. indent {
3194+ for property in instanceProps {
3195+ let tsType = BridgeJSLink . resolveTypeScriptType (
3196+ property. type,
3197+ exportedSkeletons: exportedSkeletons
3198+ )
3199+ printer. write ( " \( property. name) : \( tsType) ; " )
3200+ }
3201+ }
3202+ printer. write ( " } " )
3203+ }
3204+
31673205 // Only include functions and properties when exposeToGlobal is true
31683206 if exposeToGlobal {
31693207 let sortedFunctions = childNode. content. functions. sorted { $0. name < $1. name }
@@ -3610,7 +3648,7 @@ extension BridgeType {
36103648 case . associatedValueEnum( let name) :
36113649 return " \( name) Tag "
36123650 case . swiftStruct( let name) :
3613- return name. components ( separatedBy : " . " ) . last ?? name
3651+ return name
36143652 case . namespaceEnum( let name) :
36153653 return name
36163654 case . swiftProtocol( let name) :
0 commit comments