@@ -957,6 +957,10 @@ extension BridgeType {
957957 }
958958 case . namespaceEnum:
959959 throw BridgeJSCoreError ( " Namespace enums cannot be used as parameters " )
960+ case . nullable( . swiftStruct, _) where context == . importTS:
961+ // Optional `@JS struct`s bridge through the stack (isSome discriminator + fields),
962+ // like optional arrays/dictionaries, rather than the non-optional object-id ABI.
963+ return LoweringParameterInfo ( loweredParameters: [ ( " isSome " , . i32) ] )
960964 case . nullable( let wrappedType, _) :
961965 let wrappedInfo = try wrappedType. loweringParameterInfo ( context: context)
962966 var params = [ ( " isSome " , WasmCoreType . i32) ]
@@ -1034,10 +1038,14 @@ extension BridgeType {
10341038 case . namespaceEnum:
10351039 throw BridgeJSCoreError ( " Namespace enums cannot be used as return values " )
10361040 case . nullable( let wrappedType, _) :
1037- // jsObject uses stack ABI for optionals — returns void, value goes through stacks
1041+ // jsObject and `@JS struct` use the stack ABI for optionals — the thunk returns
1042+ // void and the value (plus isSome discriminator) flows through the stacks.
10381043 if case . jsObject = wrappedType {
10391044 return LiftingReturnInfo ( valueToLift: nil )
10401045 }
1046+ if case . swiftStruct = wrappedType, context == . importTS {
1047+ return LiftingReturnInfo ( valueToLift: nil )
1048+ }
10411049 let wrappedInfo = try wrappedType. liftingReturnInfo ( context: context)
10421050 return LiftingReturnInfo ( valueToLift: wrappedInfo. valueToLift)
10431051 case . array, . dictionary:
0 commit comments