@@ -299,6 +299,15 @@ class ExportSwift {
299
299
self . effects = effects
300
300
}
301
301
302
+ private func append( _ item: CodeBlockItemSyntax ) {
303
+ var item = item
304
+ // Add a newline for items after the first one
305
+ if !self . body. isEmpty {
306
+ item = item. with ( \. leadingTrivia, . newline)
307
+ }
308
+ self . body. append ( item)
309
+ }
310
+
302
311
func liftParameter( param: Parameter ) {
303
312
switch param. type {
304
313
case . bool:
@@ -342,7 +351,7 @@ class ExportSwift {
342
351
return Int( \( raw: lengthLabel) )
343
352
}
344
353
"""
345
- body . append ( prepare)
354
+ append ( prepare)
346
355
abiParameterForwardings. append (
347
356
LabeledExprSyntax (
348
357
label: param. label,
@@ -404,7 +413,7 @@ class ExportSwift {
404
413
405
414
func call( name: String , returnType: BridgeType ) {
406
415
let item = renderCallStatement ( callee: " \( raw: name) " , returnType: returnType)
407
- body . append ( item)
416
+ append ( item)
408
417
}
409
418
410
419
func callMethod( klassName: String , methodName: String , returnType: BridgeType ) {
@@ -413,7 +422,7 @@ class ExportSwift {
413
422
callee: " \( raw: _selfParam) . \( raw: methodName) " ,
414
423
returnType: returnType
415
424
)
416
- body . append ( item)
425
+ append ( item)
417
426
}
418
427
419
428
func lowerReturnValue( returnType: BridgeType ) {
@@ -440,33 +449,33 @@ class ExportSwift {
440
449
switch returnType {
441
450
case . void: break
442
451
case . int, . float, . double:
443
- body . append ( " return \( raw: abiReturnType!. swiftType) (ret) " )
452
+ append ( " return \( raw: abiReturnType!. swiftType) (ret) " )
444
453
case . bool:
445
- body . append ( " return Int32(ret ? 1 : 0) " )
454
+ append ( " return Int32(ret ? 1 : 0) " )
446
455
case . string:
447
- body . append (
456
+ append (
448
457
"""
449
458
return ret.withUTF8 { ptr in
450
459
_swift_js_return_string(ptr.baseAddress, Int32(ptr.count))
451
460
}
452
461
"""
453
462
)
454
463
case . jsObject( nil ) :
455
- body . append (
464
+ append (
456
465
"""
457
466
return _swift_js_retain(Int32(bitPattern: ret.id))
458
467
"""
459
468
)
460
469
case . jsObject( _? ) :
461
- body . append (
470
+ append (
462
471
"""
463
472
return _swift_js_retain(Int32(bitPattern: ret.this.id))
464
473
"""
465
474
)
466
475
case . swiftHeapObject:
467
476
// Perform a manual retain on the object, which will be balanced by a
468
477
// release called via FinalizationRegistry
469
- body . append (
478
+ append (
470
479
"""
471
480
return Unmanaged.passRetained(ret).toOpaque()
472
481
"""
0 commit comments