Skip to content

Commit bbfaa31

Browse files
committed
BridgeJS: Swift closure support
1 parent 689fdd2 commit bbfaa31

File tree

50 files changed

+7683
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+7683
-231
lines changed

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 329 additions & 35 deletions
Large diffs are not rendered by default.

Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ extension BridgeType {
433433
case .string: return .string
434434
case .jsObject: return .jsObject
435435
case .void: return .void
436+
case .closure:
437+
throw BridgeJSCoreError("Closure types are not yet supported in TypeScript imports")
436438
case .swiftHeapObject(let className):
437439
switch context {
438440
case .importTS:
@@ -442,7 +444,7 @@ extension BridgeType {
442444
Swift classes can only be used in @JS protocols where Swift owns the instance.
443445
"""
444446
)
445-
case .protocolExport:
447+
case .exportSwift:
446448
return LoweringParameterInfo(loweredParameters: [("pointer", .pointer)])
447449
}
448450
case .swiftProtocol:
@@ -451,22 +453,22 @@ extension BridgeType {
451453
switch context {
452454
case .importTS:
453455
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
454-
case .protocolExport:
456+
case .exportSwift:
455457
return LoweringParameterInfo(loweredParameters: [("value", .i32)])
456458
}
457459
case .rawValueEnum(_, let rawType):
458460
switch context {
459461
case .importTS:
460462
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
461-
case .protocolExport:
463+
case .exportSwift:
462464
// For protocol export we return .i32 for String raw value type instead of nil
463465
return LoweringParameterInfo(loweredParameters: [("value", rawType.wasmCoreType ?? .i32)])
464466
}
465467
case .associatedValueEnum:
466468
switch context {
467469
case .importTS:
468470
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
469-
case .protocolExport:
471+
case .exportSwift:
470472
return LoweringParameterInfo(loweredParameters: [("caseId", .i32)])
471473
}
472474
case .namespaceEnum:
@@ -475,7 +477,7 @@ extension BridgeType {
475477
switch context {
476478
case .importTS:
477479
throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports")
478-
case .protocolExport:
480+
case .exportSwift:
479481
let wrappedInfo = try wrappedType.loweringParameterInfo(context: context)
480482
var params = [("isSome", WasmCoreType.i32)]
481483
params.append(contentsOf: wrappedInfo.loweredParameters)
@@ -507,6 +509,8 @@ extension BridgeType {
507509
case .string: return .string
508510
case .jsObject: return .jsObject
509511
case .void: return .void
512+
case .closure:
513+
throw BridgeJSCoreError("Closure types are not yet supported in TypeScript imports")
510514
case .swiftHeapObject(let className):
511515
switch context {
512516
case .importTS:
@@ -516,7 +520,7 @@ extension BridgeType {
516520
JavaScript cannot create Swift heap objects.
517521
"""
518522
)
519-
case .protocolExport:
523+
case .exportSwift:
520524
return LiftingReturnInfo(valueToLift: .pointer)
521525
}
522526
case .swiftProtocol:
@@ -525,22 +529,22 @@ extension BridgeType {
525529
switch context {
526530
case .importTS:
527531
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
528-
case .protocolExport:
532+
case .exportSwift:
529533
return LiftingReturnInfo(valueToLift: .i32)
530534
}
531535
case .rawValueEnum(_, let rawType):
532536
switch context {
533537
case .importTS:
534538
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
535-
case .protocolExport:
539+
case .exportSwift:
536540
// For protocol export we return .i32 for String raw value type instead of nil
537541
return LiftingReturnInfo(valueToLift: rawType.wasmCoreType ?? .i32)
538542
}
539543
case .associatedValueEnum:
540544
switch context {
541545
case .importTS:
542546
throw BridgeJSCoreError("Enum types are not yet supported in TypeScript imports")
543-
case .protocolExport:
547+
case .exportSwift:
544548
return LiftingReturnInfo(valueToLift: .i32)
545549
}
546550
case .namespaceEnum:
@@ -549,7 +553,7 @@ extension BridgeType {
549553
switch context {
550554
case .importTS:
551555
throw BridgeJSCoreError("Optional types are not yet supported in TypeScript imports")
552-
case .protocolExport:
556+
case .exportSwift:
553557
let wrappedInfo = try wrappedType.liftingReturnInfo(context: context)
554558
return LiftingReturnInfo(valueToLift: wrappedInfo.valueToLift)
555559
}

0 commit comments

Comments
 (0)