Skip to content

Commit 02b5c26

Browse files
BridgeJS: Add newline trivia before each item
This suppresses warnings from swift-syntax
1 parent 5244bbf commit 02b5c26

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ class ExportSwift {
299299
self.effects = effects
300300
}
301301

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+
302311
func liftParameter(param: Parameter) {
303312
switch param.type {
304313
case .bool:
@@ -342,7 +351,7 @@ class ExportSwift {
342351
return Int(\(raw: lengthLabel))
343352
}
344353
"""
345-
body.append(prepare)
354+
append(prepare)
346355
abiParameterForwardings.append(
347356
LabeledExprSyntax(
348357
label: param.label,
@@ -404,7 +413,7 @@ class ExportSwift {
404413

405414
func call(name: String, returnType: BridgeType) {
406415
let item = renderCallStatement(callee: "\(raw: name)", returnType: returnType)
407-
body.append(item)
416+
append(item)
408417
}
409418

410419
func callMethod(klassName: String, methodName: String, returnType: BridgeType) {
@@ -413,7 +422,7 @@ class ExportSwift {
413422
callee: "\(raw: _selfParam).\(raw: methodName)",
414423
returnType: returnType
415424
)
416-
body.append(item)
425+
append(item)
417426
}
418427

419428
func lowerReturnValue(returnType: BridgeType) {
@@ -440,33 +449,33 @@ class ExportSwift {
440449
switch returnType {
441450
case .void: break
442451
case .int, .float, .double:
443-
body.append("return \(raw: abiReturnType!.swiftType)(ret)")
452+
append("return \(raw: abiReturnType!.swiftType)(ret)")
444453
case .bool:
445-
body.append("return Int32(ret ? 1 : 0)")
454+
append("return Int32(ret ? 1 : 0)")
446455
case .string:
447-
body.append(
456+
append(
448457
"""
449458
return ret.withUTF8 { ptr in
450459
_swift_js_return_string(ptr.baseAddress, Int32(ptr.count))
451460
}
452461
"""
453462
)
454463
case .jsObject(nil):
455-
body.append(
464+
append(
456465
"""
457466
return _swift_js_retain(Int32(bitPattern: ret.id))
458467
"""
459468
)
460469
case .jsObject(_?):
461-
body.append(
470+
append(
462471
"""
463472
return _swift_js_retain(Int32(bitPattern: ret.this.id))
464473
"""
465474
)
466475
case .swiftHeapObject:
467476
// Perform a manual retain on the object, which will be balanced by a
468477
// release called via FinalizationRegistry
469-
body.append(
478+
append(
470479
"""
471480
return Unmanaged.passRetained(ret).toOpaque()
472481
"""

0 commit comments

Comments
 (0)