Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,21 @@ public final class SwiftToSkeleton {
return lookupType(for: attributedType.baseType, errors: &errors)
}

// any P
if let existentialType = type.as(SomeOrAnyTypeSyntax.self),
existentialType.someOrAnySpecifier.tokenKind == .keyword(.any)
{
return lookupType(for: existentialType.constraint, errors: &errors)
}

// (T)
if let tupleType = type.as(TupleTypeSyntax.self),
tupleType.elements.count == 1,
let element = tupleType.elements.first
{
return lookupType(for: element.type, errors: &errors)
}

// JSTypedArray<T>
if let identifierType = type.as(IdentifierTypeSyntax.self),
identifierType.name.text == "JSTypedArray",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ import JavaScriptKit
var delegate: MyViewControllerDelegate

@JS
var secondDelegate: MyViewControllerDelegate?
var secondDelegate: (any MyViewControllerDelegate)?

@JS init(delegate: MyViewControllerDelegate) {
@JS init(delegate: any MyViewControllerDelegate) {
self.delegate = delegate
}

Expand Down Expand Up @@ -103,7 +103,7 @@ import JavaScriptKit
var delegates: [MyViewControllerDelegate]

@JS
var delegatesByName: [String: MyViewControllerDelegate]
var delegatesByName: [String: any MyViewControllerDelegate]

@JS init(delegates: [MyViewControllerDelegate]) {
self.delegates = delegates
Expand All @@ -117,7 +117,7 @@ import JavaScriptKit
}
}

@JS func processDelegates(_ delegates: [MyViewControllerDelegate]) -> [MyViewControllerDelegate]
@JS func processDelegates(_ delegates: [any MyViewControllerDelegate]) -> [any MyViewControllerDelegate]

@JS func processDelegatesByName(
_ delegates: [String: MyViewControllerDelegate]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ import JavaScriptKit

@JS func processRenderable(_ item: Renderable, transform: (Renderable) -> String) -> String
@JS func makeRenderableFactory(defaultName: String) -> () -> Renderable
@JS func roundtripRenderable(_ callback: (Renderable) -> Renderable) -> (Renderable) -> Renderable
@JS func processOptionalRenderable(_ callback: (Renderable?) -> String) -> String
@JS func roundtripRenderable(_ callback: (any Renderable) -> any Renderable) -> (any Renderable) -> any Renderable
@JS func processOptionalRenderable(_ callback: ((any Renderable)?) -> String) -> String
2 changes: 1 addition & 1 deletion Tests/BridgeJSRuntimeTests/ArraySupportTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ final class ArraySupportTests: XCTestCase {
@JS static func roundTripStructArray(_ v: [DataPoint]) -> [DataPoint] { v }
@JS static func roundTripSwiftClassArray(_ v: [Greeter]) -> [Greeter] { v }
@JS static func roundTripNamespacedSwiftClassArray(_ v: [Utils.Converter]) -> [Utils.Converter] { v }
@JS static func roundTripProtocolArray(_ v: [ArrayElementProtocol]) -> [ArrayElementProtocol] { v }
@JS static func roundTripProtocolArray(_ v: [any ArrayElementProtocol]) -> [any ArrayElementProtocol] { v }
@JS static func roundTripJSClassArray(_ v: [ArrayElementObject]) -> [ArrayElementObject] { v }

@JS static func roundTripOptionalIntArray(_ v: [Int?]) -> [Int?] { v }
Expand Down
16 changes: 8 additions & 8 deletions Tests/BridgeJSRuntimeTests/ExportAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,9 @@ enum GraphOperations {
@JS class DataProcessorManager {

@JS var processor: DataProcessor
@JS var backupProcessor: DataProcessor?
@JS var backupProcessor: (any DataProcessor)?

@JS init(processor: DataProcessor) {
@JS init(processor: any DataProcessor) {
self.processor = processor
self.backupProcessor = nil
}
Expand Down Expand Up @@ -1124,23 +1124,23 @@ enum GraphOperations {
return SwiftDataProcessor()
}

@JS static func createNativeProcessorOptional() -> DataProcessor? {
@JS static func createNativeProcessorOptional() -> (any DataProcessor)? {
return SwiftDataProcessor()
}

@JS static func createNativeProcessorNil() -> DataProcessor? {
return nil
}

@JS static func createNativeProcessorArray() -> [DataProcessor] {
@JS static func createNativeProcessorArray() -> [any DataProcessor] {
let p1 = SwiftDataProcessor()
p1.count = 10
let p2 = SwiftDataProcessor()
p2.count = 20
return [p1, p2]
}

@JS static func createNativeProcessorDictionary() -> [String: DataProcessor] {
@JS static func createNativeProcessorDictionary() -> [String: any DataProcessor] {
let p1 = SwiftDataProcessor()
p1.count = 10
let p2 = SwiftDataProcessor()
Expand Down Expand Up @@ -1317,12 +1317,12 @@ enum GraphOperations {
}

@JS func roundtripDataProcessor(
_ callback: @escaping (DataProcessor) -> DataProcessor
) -> (DataProcessor) -> DataProcessor {
_ callback: @escaping (any DataProcessor) -> any DataProcessor
) -> (any DataProcessor) -> any DataProcessor {
return callback
}

@JS func processOptionalDataProcessor(_ callback: (DataProcessor?) -> String) -> String {
@JS func processOptionalDataProcessor(_ callback: ((any DataProcessor)?) -> String) -> String {
let processor = SwiftDataProcessor()
processor.increment(by: 7)
return callback(processor) + " | " + callback(nil)
Expand Down
Loading