@@ -100,6 +100,15 @@ public class ExportSwift {
100100 }
101101 }
102102 }
103+
104+ withSpan ( " Render Aliases " ) { [ self ] in
105+ let aliasCodegen = AliasCodegen ( )
106+ for alias in skeleton. aliases {
107+ if let aliasExtension = aliasCodegen. renderAliasConformance ( alias) {
108+ decls. append ( aliasExtension)
109+ }
110+ }
111+ }
103112 return withSpan ( " Format Export Glue " ) {
104113 return decls. map { $0. description } . joined ( separator: " \n \n " )
105114 }
@@ -877,7 +886,7 @@ struct StackCodegen {
877886 switch type {
878887 case . string, . integer, . bool, . float, . double,
879888 . jsObject( nil ) , . jsValue, . swiftStruct, . swiftHeapObject, . unsafePointer,
880- . swiftProtocol, . caseEnum, . associatedValueEnum, . rawValueEnum, . array, . dictionary:
889+ . swiftProtocol, . caseEnum, . associatedValueEnum, . rawValueEnum, . array, . dictionary, . alias :
881890 return " \( raw: type. swiftType) .bridgeJSStackPop() "
882891 case . jsObject( let className? ) :
883892 return " \( raw: className) (unsafelyWrapping: JSObject.bridgeJSStackPop()) "
@@ -895,7 +904,7 @@ struct StackCodegen {
895904 switch wrappedType {
896905 case . string, . integer, . bool, . float, . double, . jsObject( nil ) , . jsValue,
897906 . swiftStruct, . swiftHeapObject, . caseEnum, . associatedValueEnum, . rawValueEnum,
898- . array, . dictionary:
907+ . array, . dictionary, . alias :
899908 return " \( raw: typeName) < \( raw: wrappedType. swiftType) >.bridgeJSStackPop() "
900909 case . jsObject( let className? ) :
901910 return " \( raw: typeName) <JSObject>.bridgeJSStackPop().map { \( raw: className) (unsafelyWrapping: $0) } "
@@ -918,7 +927,7 @@ struct StackCodegen {
918927 switch type {
919928 case . string, . integer, . bool, . float, . double, . jsValue,
920929 . jsObject( nil ) , . swiftHeapObject, . unsafePointer, . closure,
921- . caseEnum, . rawValueEnum, . associatedValueEnum, . swiftStruct, . nullable:
930+ . caseEnum, . rawValueEnum, . associatedValueEnum, . swiftStruct, . nullable, . alias :
922931 return [ " \( raw: accessor) .bridgeJSStackPush() " ]
923932 case . jsObject( _? ) :
924933 return [ " \( raw: accessor) .jsObject.bridgeJSStackPush() " ]
@@ -1339,10 +1348,9 @@ struct StructCodegen {
13391348 let instanceProps = structDef. properties. filter { !$0. isStatic }
13401349
13411350 for property in instanceProps {
1342- let accessor = " self. \( property. name) "
13431351 let statements = stackCodegen. lowerStatements (
13441352 for: property. type,
1345- accessor: accessor ,
1353+ accessor: " self. \( property . name ) " ,
13461354 varPrefix: property. name
13471355 )
13481356 for statement in statements {
@@ -1354,6 +1362,18 @@ struct StructCodegen {
13541362 }
13551363}
13561364
1365+ // MARK: - AliasCodegen
1366+
1367+ struct AliasCodegen {
1368+ func renderAliasConformance( _ alias: ExportedAlias ) -> DeclSyntax ? {
1369+ guard let protocols = alias. underlying. aliasConformanceProtocols else {
1370+ return nil
1371+ }
1372+ let conformances = ( [ " _BridgedSwiftAlias " ] + protocols) . joined ( separator: " , " )
1373+ return " extension \( raw: alias. swiftCallName) : \( raw: conformances) {} "
1374+ }
1375+ }
1376+
13571377// MARK: - ProtocolCodegen
13581378
13591379struct ProtocolCodegen {
@@ -1565,6 +1585,23 @@ extension UnsafePointerType {
15651585}
15661586
15671587extension BridgeType {
1588+ var aliasConformanceProtocols : [ String ] ? {
1589+ switch self {
1590+ case . swiftHeapObject, . jsObject, . integer, . float, . double, . bool, . string, . jsValue:
1591+ return [ " _BridgedSwiftStackType " ]
1592+ case . swiftStruct:
1593+ return [ " _BridgedSwiftStruct " ]
1594+ case . caseEnum:
1595+ return [ " _BridgedSwiftCaseEnum " ]
1596+ case . associatedValueEnum:
1597+ return [ " _BridgedSwiftAssociatedValueEnum " ]
1598+ case . rawValueEnum, . void, . unsafePointer, . namespaceEnum,
1599+ . swiftProtocol, . closure, . nullable, . array, . dictionary, . alias:
1600+ // Not supported yet.
1601+ return nil
1602+ }
1603+ }
1604+
15681605 var swiftType : String {
15691606 switch self {
15701607 case . bool: return " Bool "
@@ -1593,6 +1630,7 @@ extension BridgeType {
15931630 let effectsStr = ( signature. isAsync ? " async " : " " ) + ( signature. isThrows ? " throws " : " " )
15941631 let closureType = " ( \( paramTypes) ) \( effectsStr) -> \( signature. returnType. swiftType) "
15951632 return useJSTypedClosure ? " JSTypedClosure< \( closureType) > " : closureType
1633+ case . alias( let name, _) : return name
15961634 }
15971635 }
15981636
@@ -1617,6 +1655,8 @@ extension BridgeType {
16171655 return true
16181656 case . nullable( let wrapped, _) :
16191657 return wrapped. isStackUsingParameter
1658+ case . alias( _, let underlying) :
1659+ return underlying. isStackUsingParameter
16201660 default :
16211661 return false
16221662 }
@@ -1675,6 +1715,8 @@ extension BridgeType {
16751715 return LiftingIntrinsicInfo ( parameters: [ ( " callbackId " , . i32) ] )
16761716 case . array, . dictionary:
16771717 return LiftingIntrinsicInfo ( parameters: [ ] )
1718+ case . alias( _, let underlying) :
1719+ return try underlying. liftParameterInfo ( )
16781720 }
16791721 }
16801722
@@ -1726,6 +1768,8 @@ extension BridgeType {
17261768 return . jsObject
17271769 case . array, . dictionary:
17281770 return . array
1771+ case . alias( _, let underlying) :
1772+ return try underlying. loweringReturnInfo ( )
17291773 }
17301774 }
17311775}
0 commit comments