44
55public protocol NamespacedExportedType {
66 var name : String { get }
7+ var jsName : String ? { get }
8+ /// The namespace using Swift declaration names, retained for ABI generation.
79 var namespace : [ String ] ? { get }
10+ /// The public namespace when an enclosing declaration has an exported name override.
11+ var jsNamespace : [ String ] ? { get }
812}
913
1014extension NamespacedExportedType {
15+ public var resolvedJSName : String { jsName ?? name }
16+ public var resolvedJSNamespace : [ String ] ? { jsNamespace ?? namespace }
17+
1118 public var abiName : String {
1219 if let namespace = namespace, !namespace. isEmpty {
1320 return ( namespace + [ name] ) . joined ( separator: " _ " )
@@ -16,7 +23,7 @@ extension NamespacedExportedType {
1623 }
1724
1825 public var tsPathComponents : [ String ] {
19- ( namespace ?? [ ] ) + [ name ]
26+ ( resolvedJSNamespace ?? [ ] ) + [ resolvedJSName ]
2027 }
2128
2229 public var tsFullPath : String {
@@ -778,31 +785,37 @@ public struct StructField: Codable, Equatable, Sendable {
778785
779786public struct ExportedStruct : Codable , Equatable , Sendable , NamespacedExportedType {
780787 public let name : String
788+ public let jsName : String ?
781789 public let swiftCallName : String
782790 public let explicitAccessControl : String ?
783791 public var properties : [ ExportedProperty ]
784792 public var constructor : ExportedConstructor ?
785793 public var methods : [ ExportedFunction ]
786794 public let namespace : [ String ] ?
795+ public let jsNamespace : [ String ] ?
787796 public var documentation : String ?
788797
789798 public init (
790799 name: String ,
800+ jsName: String ? = nil ,
791801 swiftCallName: String ,
792802 explicitAccessControl: String ? ,
793803 properties: [ ExportedProperty ] = [ ] ,
794804 constructor: ExportedConstructor ? = nil ,
795805 methods: [ ExportedFunction ] = [ ] ,
796806 namespace: [ String ] ? ,
807+ jsNamespace: [ String ] ? = nil ,
797808 documentation: String ? = nil
798809 ) {
799810 self . name = name
811+ self . jsName = jsName
800812 self . swiftCallName = swiftCallName
801813 self . explicitAccessControl = explicitAccessControl
802814 self . properties = properties
803815 self . constructor = constructor
804816 self . methods = methods
805817 self . namespace = namespace
818+ self . jsNamespace = jsNamespace
806819 self . documentation = documentation
807820 }
808821}
@@ -864,12 +877,14 @@ public struct ExportedEnum: Codable, Equatable, Sendable, NamespacedExportedType
864877 public static let objectSuffix = " Object "
865878
866879 public let name : String
880+ public let jsName : String ?
867881 public let swiftCallName : String
868882 public let tsFullPath : String
869883 public let explicitAccessControl : String ?
870884 public var cases : [ EnumCase ]
871885 public let rawType : SwiftEnumRawType ?
872886 public let namespace : [ String ] ?
887+ public let jsNamespace : [ String ] ?
873888 public let emitStyle : EnumEmitStyle
874889 public var staticMethods : [ ExportedFunction ]
875890 public var staticProperties : [ ExportedProperty ] = [ ]
@@ -885,33 +900,36 @@ public struct ExportedEnum: Codable, Equatable, Sendable, NamespacedExportedType
885900 }
886901
887902 public var valuesName : String {
888- emitStyle == . tsEnum ? name : " \( name ) \( Self . valuesSuffix) "
903+ emitStyle == . tsEnum ? resolvedJSName : " \( resolvedJSName ) \( Self . valuesSuffix) "
889904 }
890905
891906 public var objectTypeName : String {
892- " \( name ) \( Self . objectSuffix) "
907+ " \( resolvedJSName ) \( Self . objectSuffix) "
893908 }
894909
895910 public init (
896911 name: String ,
912+ jsName: String ? = nil ,
897913 swiftCallName: String ,
898- tsFullPath: String ,
899914 explicitAccessControl: String ? ,
900915 cases: [ EnumCase ] ,
901916 rawType: SwiftEnumRawType ? ,
902917 namespace: [ String ] ? ,
918+ jsNamespace: [ String ] ? = nil ,
903919 emitStyle: EnumEmitStyle ,
904920 staticMethods: [ ExportedFunction ] = [ ] ,
905921 staticProperties: [ ExportedProperty ] = [ ] ,
906922 documentation: String ? = nil
907923 ) {
908924 self . name = name
925+ self . jsName = jsName
909926 self . swiftCallName = swiftCallName
910- self . tsFullPath = tsFullPath
927+ self . tsFullPath = ( ( jsNamespace ?? namespace ?? [ ] ) + [ jsName ?? name ] ) . joined ( separator : " . " )
911928 self . explicitAccessControl = explicitAccessControl
912929 self . cases = cases
913930 self . rawType = rawType
914931 self . namespace = namespace
932+ self . jsNamespace = jsNamespace
915933 self . emitStyle = emitStyle
916934 self . staticMethods = staticMethods
917935 self . staticProperties = staticProperties
@@ -947,24 +965,30 @@ public struct ExportedProtocolProperty: Codable, Equatable, Sendable {
947965 }
948966}
949967
950- public struct ExportedProtocol : Codable , Equatable {
968+ public struct ExportedProtocol : Codable , Equatable , NamespacedExportedType {
951969 public let name : String
970+ public let jsName : String ?
952971 public let methods : [ ExportedFunction ]
953972 public let properties : [ ExportedProtocolProperty ]
954973 public let namespace : [ String ] ?
974+ public let jsNamespace : [ String ] ?
955975 public var documentation : String ?
956976
957977 public init (
958978 name: String ,
979+ jsName: String ? = nil ,
959980 methods: [ ExportedFunction ] ,
960981 properties: [ ExportedProtocolProperty ] = [ ] ,
961982 namespace: [ String ] ? = nil ,
983+ jsNamespace: [ String ] ? = nil ,
962984 documentation: String ? = nil
963985 ) {
964986 self . name = name
987+ self . jsName = jsName
965988 self . methods = methods
966989 self . properties = properties
967990 self . namespace = namespace
991+ self . jsNamespace = jsNamespace
968992 self . documentation = documentation
969993 }
970994}
@@ -1007,35 +1031,41 @@ public struct ExportedFunction: Codable, Equatable, Sendable {
10071031
10081032public struct ExportedClass : Codable , NamespacedExportedType {
10091033 public var name : String
1034+ public var jsName : String ?
10101035 public var swiftCallName : String
10111036 public var explicitAccessControl : String ?
10121037 public var constructor : ExportedConstructor ?
10131038 public var methods : [ ExportedFunction ]
10141039 public var properties : [ ExportedProperty ]
10151040 public var namespace : [ String ] ?
1041+ public var jsNamespace : [ String ] ?
10161042 public var identityMode : Bool ? // nil = use config default, true/false = override
10171043 public var documentation : String ?
10181044 public var isFinal : Bool ?
10191045
10201046 public init (
10211047 name: String ,
1048+ jsName: String ? = nil ,
10221049 swiftCallName: String ,
10231050 explicitAccessControl: String ? ,
10241051 constructor: ExportedConstructor ? = nil ,
10251052 methods: [ ExportedFunction ] ,
10261053 properties: [ ExportedProperty ] = [ ] ,
10271054 namespace: [ String ] ? = nil ,
1055+ jsNamespace: [ String ] ? = nil ,
10281056 identityMode: Bool ? = nil ,
10291057 documentation: String ? = nil ,
10301058 isFinal: Bool ? = nil
10311059 ) {
10321060 self . name = name
1061+ self . jsName = jsName
10331062 self . swiftCallName = swiftCallName
10341063 self . explicitAccessControl = explicitAccessControl
10351064 self . constructor = constructor
10361065 self . methods = methods
10371066 self . properties = properties
10381067 self . namespace = namespace
1068+ self . jsNamespace = jsNamespace
10391069 self . identityMode = identityMode
10401070 self . documentation = documentation
10411071 self . isFinal = isFinal
0 commit comments