@@ -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 }
@@ -1497,7 +1499,7 @@ public struct BridgeJSLink {
14971499 func renderExportedStruct(
14981500 _ structDefinition: ExportedStruct
14991501 ) throws -> ( js: [ String ] , dtsType: [ String ] , dtsExportEntry: [ String ] ) {
1500- let structName = structDefinition. name
1502+ let structName = structDefinition. abiName
15011503 let hasConstructor = structDefinition. constructor != nil
15021504 let staticMethods = structDefinition. methods. filter { $0. effects. isStatic }
15031505 let staticProperties = structDefinition. properties. filter { $0. isStatic }
@@ -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 ] ) ] = [ ]
@@ -2672,6 +2675,14 @@ extension BridgeJSLink {
26722675 currentNode. content. enums. append ( enumDef)
26732676 }
26742677
2678+ for structDef in skeleton. structs where structDef. namespace != nil {
2679+ var currentNode = rootNode
2680+ for part in structDef. namespace! {
2681+ currentNode = currentNode. addChild ( part)
2682+ }
2683+ currentNode. content. structs. append ( structDef)
2684+ }
2685+
26752686 for enumDef in skeleton. enums where enumDef. enumType == . namespace {
26762687 for property in enumDef. staticProperties {
26772688 let fullNamespace = ( enumDef. namespace ?? [ ] ) + [ enumDef. name]
@@ -2983,8 +2994,8 @@ extension BridgeJSLink {
29832994 renderTSSignatureCallback: @escaping ( [ Parameter ] , BridgeType , Effects ) -> String
29842995 ) {
29852996 func hasContent( node: NamespaceNode ) -> Bool {
2986- // Enums are always included
2987- if !node. content. enums. isEmpty {
2997+ // Enums and structs are always included
2998+ if !node. content. enums. isEmpty || !node . content . structs . isEmpty {
29882999 return true
29893000 }
29903001
@@ -3164,6 +3175,23 @@ extension BridgeJSLink {
31643175 }
31653176 }
31663177
3178+ // Generate struct interface definitions
3179+ let sortedStructs = childNode. content. structs. sorted { $0. name < $1. name }
3180+ for structDef in sortedStructs {
3181+ let instanceProps = structDef. properties. filter { !$0. isStatic }
3182+ printer. write ( " export interface \( structDef. name) { " )
3183+ printer. indent {
3184+ for property in instanceProps {
3185+ let tsType = BridgeJSLink . resolveTypeScriptType (
3186+ property. type,
3187+ exportedSkeletons: exportedSkeletons
3188+ )
3189+ printer. write ( " \( property. name) : \( tsType) ; " )
3190+ }
3191+ }
3192+ printer. write ( " } " )
3193+ }
3194+
31673195 // Only include functions and properties when exposeToGlobal is true
31683196 if exposeToGlobal {
31693197 let sortedFunctions = childNode. content. functions. sorted { $0. name < $1. name }
@@ -3610,7 +3638,7 @@ extension BridgeType {
36103638 case . associatedValueEnum( let name) :
36113639 return " \( name) Tag "
36123640 case . swiftStruct( let name) :
3613- return name. components ( separatedBy : " . " ) . last ?? name
3641+ return name
36143642 case . namespaceEnum( let name) :
36153643 return name
36163644 case . swiftProtocol( let name) :
0 commit comments