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,39 @@ 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 ,
898914 tsFullPath: String ,
899915 explicitAccessControl: String ? ,
900916 cases: [ EnumCase ] ,
901917 rawType: SwiftEnumRawType ? ,
902918 namespace: [ String ] ? ,
919+ jsNamespace: [ String ] ? = nil ,
903920 emitStyle: EnumEmitStyle ,
904921 staticMethods: [ ExportedFunction ] = [ ] ,
905922 staticProperties: [ ExportedProperty ] = [ ] ,
906923 documentation: String ? = nil
907924 ) {
908925 self . name = name
926+ self . jsName = jsName
909927 self . swiftCallName = swiftCallName
910- self . tsFullPath = tsFullPath
928+ self . tsFullPath =
929+ jsName != nil || jsNamespace != nil
930+ ? ( ( jsNamespace ?? namespace ?? [ ] ) + [ jsName ?? name] ) . joined ( separator: " . " ) : tsFullPath
911931 self . explicitAccessControl = explicitAccessControl
912932 self . cases = cases
913933 self . rawType = rawType
914934 self . namespace = namespace
935+ self . jsNamespace = jsNamespace
915936 self . emitStyle = emitStyle
916937 self . staticMethods = staticMethods
917938 self . staticProperties = staticProperties
@@ -947,24 +968,30 @@ public struct ExportedProtocolProperty: Codable, Equatable, Sendable {
947968 }
948969}
949970
950- public struct ExportedProtocol : Codable , Equatable {
971+ public struct ExportedProtocol : Codable , Equatable , NamespacedExportedType {
951972 public let name : String
973+ public let jsName : String ?
952974 public let methods : [ ExportedFunction ]
953975 public let properties : [ ExportedProtocolProperty ]
954976 public let namespace : [ String ] ?
977+ public let jsNamespace : [ String ] ?
955978 public var documentation : String ?
956979
957980 public init (
958981 name: String ,
982+ jsName: String ? = nil ,
959983 methods: [ ExportedFunction ] ,
960984 properties: [ ExportedProtocolProperty ] = [ ] ,
961985 namespace: [ String ] ? = nil ,
986+ jsNamespace: [ String ] ? = nil ,
962987 documentation: String ? = nil
963988 ) {
964989 self . name = name
990+ self . jsName = jsName
965991 self . methods = methods
966992 self . properties = properties
967993 self . namespace = namespace
994+ self . jsNamespace = jsNamespace
968995 self . documentation = documentation
969996 }
970997}
@@ -1007,35 +1034,41 @@ public struct ExportedFunction: Codable, Equatable, Sendable {
10071034
10081035public struct ExportedClass : Codable , NamespacedExportedType {
10091036 public var name : String
1037+ public var jsName : String ?
10101038 public var swiftCallName : String
10111039 public var explicitAccessControl : String ?
10121040 public var constructor : ExportedConstructor ?
10131041 public var methods : [ ExportedFunction ]
10141042 public var properties : [ ExportedProperty ]
10151043 public var namespace : [ String ] ?
1044+ public var jsNamespace : [ String ] ?
10161045 public var identityMode : Bool ? // nil = use config default, true/false = override
10171046 public var documentation : String ?
10181047 public var isFinal : Bool ?
10191048
10201049 public init (
10211050 name: String ,
1051+ jsName: String ? = nil ,
10221052 swiftCallName: String ,
10231053 explicitAccessControl: String ? ,
10241054 constructor: ExportedConstructor ? = nil ,
10251055 methods: [ ExportedFunction ] ,
10261056 properties: [ ExportedProperty ] = [ ] ,
10271057 namespace: [ String ] ? = nil ,
1058+ jsNamespace: [ String ] ? = nil ,
10281059 identityMode: Bool ? = nil ,
10291060 documentation: String ? = nil ,
10301061 isFinal: Bool ? = nil
10311062 ) {
10321063 self . name = name
1064+ self . jsName = jsName
10331065 self . swiftCallName = swiftCallName
10341066 self . explicitAccessControl = explicitAccessControl
10351067 self . constructor = constructor
10361068 self . methods = methods
10371069 self . properties = properties
10381070 self . namespace = namespace
1071+ self . jsNamespace = jsNamespace
10391072 self . identityMode = identityMode
10401073 self . documentation = documentation
10411074 self . isFinal = isFinal
0 commit comments