Skip to content

Commit 549b727

Browse files
committed
BridgeJS: Fix closures with struct return
1 parent 824c051 commit 549b727

10 files changed

Lines changed: 782 additions & 0 deletions

File tree

Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/SwiftClosure.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@ import JavaScriptKit
88
}
99
}
1010

11+
@JS public struct Animal {
12+
public let type: String
13+
14+
@JS public init(type: String) {
15+
self.type = type
16+
}
17+
}
18+
1119
@JS class TestProcessor {
1220
@JS init(transform: @escaping (String) -> String) {}
1321
}
1422

23+
@JS func roundtripAnimal(_ animalClosure: (Animal) -> Animal) -> (Animal) -> Animal
24+
@JS func roundtripOptionalAnimal(_ animalClosure: (Animal?) -> Animal?) -> (Animal?) -> Animal?
25+
1526
@JS func roundtripString(_ stringClosure: (String) -> String) -> (String) -> String
1627
@JS func roundtripInt(_ intClosure: (Int) -> Int) -> (Int) -> Int
1728
@JS func roundtripBool(_ boolClosure: (Bool) -> Bool) -> (Bool) -> Bool

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/SwiftClosure.json

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,152 @@
284284
],
285285
"exposeToGlobal" : false,
286286
"functions" : [
287+
{
288+
"abiName" : "bjs_roundtripAnimal",
289+
"effects" : {
290+
"isAsync" : false,
291+
"isStatic" : false,
292+
"isThrows" : false
293+
},
294+
"name" : "roundtripAnimal",
295+
"parameters" : [
296+
{
297+
"label" : "_",
298+
"name" : "animalClosure",
299+
"type" : {
300+
"closure" : {
301+
"_0" : {
302+
"isAsync" : false,
303+
"isThrows" : false,
304+
"mangleName" : "10TestModule6AnimalV_6AnimalV",
305+
"moduleName" : "TestModule",
306+
"parameters" : [
307+
{
308+
"swiftStruct" : {
309+
"_0" : "Animal"
310+
}
311+
}
312+
],
313+
"returnType" : {
314+
"swiftStruct" : {
315+
"_0" : "Animal"
316+
}
317+
},
318+
"sendingParameters" : false
319+
},
320+
"useJSTypedClosure" : false
321+
}
322+
}
323+
}
324+
],
325+
"returnType" : {
326+
"closure" : {
327+
"_0" : {
328+
"isAsync" : false,
329+
"isThrows" : false,
330+
"mangleName" : "10TestModule6AnimalV_6AnimalV",
331+
"moduleName" : "TestModule",
332+
"parameters" : [
333+
{
334+
"swiftStruct" : {
335+
"_0" : "Animal"
336+
}
337+
}
338+
],
339+
"returnType" : {
340+
"swiftStruct" : {
341+
"_0" : "Animal"
342+
}
343+
},
344+
"sendingParameters" : false
345+
},
346+
"useJSTypedClosure" : false
347+
}
348+
}
349+
},
350+
{
351+
"abiName" : "bjs_roundtripOptionalAnimal",
352+
"effects" : {
353+
"isAsync" : false,
354+
"isStatic" : false,
355+
"isThrows" : false
356+
},
357+
"name" : "roundtripOptionalAnimal",
358+
"parameters" : [
359+
{
360+
"label" : "_",
361+
"name" : "animalClosure",
362+
"type" : {
363+
"closure" : {
364+
"_0" : {
365+
"isAsync" : false,
366+
"isThrows" : false,
367+
"mangleName" : "10TestModuleSq6AnimalV_Sq6AnimalV",
368+
"moduleName" : "TestModule",
369+
"parameters" : [
370+
{
371+
"nullable" : {
372+
"_0" : {
373+
"swiftStruct" : {
374+
"_0" : "Animal"
375+
}
376+
},
377+
"_1" : "null"
378+
}
379+
}
380+
],
381+
"returnType" : {
382+
"nullable" : {
383+
"_0" : {
384+
"swiftStruct" : {
385+
"_0" : "Animal"
386+
}
387+
},
388+
"_1" : "null"
389+
}
390+
},
391+
"sendingParameters" : false
392+
},
393+
"useJSTypedClosure" : false
394+
}
395+
}
396+
}
397+
],
398+
"returnType" : {
399+
"closure" : {
400+
"_0" : {
401+
"isAsync" : false,
402+
"isThrows" : false,
403+
"mangleName" : "10TestModuleSq6AnimalV_Sq6AnimalV",
404+
"moduleName" : "TestModule",
405+
"parameters" : [
406+
{
407+
"nullable" : {
408+
"_0" : {
409+
"swiftStruct" : {
410+
"_0" : "Animal"
411+
}
412+
},
413+
"_1" : "null"
414+
}
415+
}
416+
],
417+
"returnType" : {
418+
"nullable" : {
419+
"_0" : {
420+
"swiftStruct" : {
421+
"_0" : "Animal"
422+
}
423+
},
424+
"_1" : "null"
425+
}
426+
},
427+
"sendingParameters" : false
428+
},
429+
"useJSTypedClosure" : false
430+
}
431+
}
432+
},
287433
{
288434
"abiName" : "bjs_roundtripString",
289435
"effects" : {
@@ -1872,7 +2018,45 @@
18722018

18732019
],
18742020
"structs" : [
2021+
{
2022+
"constructor" : {
2023+
"abiName" : "bjs_Animal_init",
2024+
"effects" : {
2025+
"isAsync" : false,
2026+
"isStatic" : false,
2027+
"isThrows" : false
2028+
},
2029+
"parameters" : [
2030+
{
2031+
"label" : "type",
2032+
"name" : "type",
2033+
"type" : {
2034+
"string" : {
18752035

2036+
}
2037+
}
2038+
}
2039+
]
2040+
},
2041+
"explicitAccessControl" : "public",
2042+
"methods" : [
2043+
2044+
],
2045+
"name" : "Animal",
2046+
"properties" : [
2047+
{
2048+
"isReadonly" : true,
2049+
"isStatic" : false,
2050+
"name" : "type",
2051+
"type" : {
2052+
"string" : {
2053+
2054+
}
2055+
}
2056+
}
2057+
],
2058+
"swiftCallName" : "Animal"
2059+
}
18762060
]
18772061
},
18782062
"moduleName" : "TestModule",

0 commit comments

Comments
 (0)