From 66aae8b9c05b7f776203579453b4550dcc618e8a Mon Sep 17 00:00:00 2001 From: Krzysztof Rodak Date: Thu, 9 Apr 2026 12:10:31 +0200 Subject: [PATCH] BridgeJS: Emit protocol array for-loop as a single CodeBlockItemSyntax The protocol array lowering built its for-loop from separate CodeBlockItemSyntax fragments ('for ... {', body, '}'), which is not a well-formed statement unit. swift-syntax 603's formatter then rendered the closing brace glued to the previous line in the generated output. Combine the for-loop into a single multi-line CodeBlockItemSyntax, matching the pattern already used for nullable protocol return lowering, so the formatter produces consistent output across swift-syntax 600-603. --- .../Sources/BridgeJSCore/ExportSwift.swift | 16 ++++++++-------- .../BridgeJSCodegenTests/Protocol.swift | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift index ca7bdc3c2..d5485d8bf 100644 --- a/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift +++ b/Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift @@ -827,15 +827,15 @@ struct StackCodegen { accessor: String, varPrefix: String ) -> [CodeBlockItemSyntax] { - var statements: [CodeBlockItemSyntax] = [] let elemVar = "__bjs_elem_\(varPrefix)" - statements.append("for \(raw: elemVar) in \(raw: accessor) {") - statements.append( - " _swift_js_push_i32((\(raw: elemVar) as! _BridgedSwiftProtocolExportable).bridgeJSLowerAsProtocolReturn())" - ) - statements.append("}") - statements.append("_swift_js_push_i32(Int32(\(raw: accessor).count))") - return statements + return [ + """ + for \(raw: elemVar) in \(raw: accessor) { + _swift_js_push_i32((\(raw: elemVar) as! _BridgedSwiftProtocolExportable).bridgeJSLowerAsProtocolReturn()) + } + """, + "_swift_js_push_i32(Int32(\(raw: accessor).count))", + ] } private func lowerDictionaryStatements( diff --git a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift index cf7464cc3..2a565ef5a 100644 --- a/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift +++ b/Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Protocol.swift @@ -698,7 +698,8 @@ public func _bjs_processDelegates() -> Void { #if arch(wasm32) let ret = processDelegates(_: [AnyMyViewControllerDelegate].bridgeJSStackPop()) for __bjs_elem_ret in ret { - _swift_js_push_i32((__bjs_elem_ret as! _BridgedSwiftProtocolExportable).bridgeJSLowerAsProtocolReturn())} + _swift_js_push_i32((__bjs_elem_ret as! _BridgedSwiftProtocolExportable).bridgeJSLowerAsProtocolReturn()) + } _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly") @@ -955,7 +956,8 @@ public func _bjs_DelegateManager_delegates_get(_ _self: UnsafeMutableRawPointer) #if arch(wasm32) let ret = DelegateManager.bridgeJSLiftParameter(_self).delegates for __bjs_elem_ret in ret { - _swift_js_push_i32((__bjs_elem_ret as! _BridgedSwiftProtocolExportable).bridgeJSLowerAsProtocolReturn())} + _swift_js_push_i32((__bjs_elem_ret as! _BridgedSwiftProtocolExportable).bridgeJSLowerAsProtocolReturn()) + } _swift_js_push_i32(Int32(ret.count)) #else fatalError("Only available on WebAssembly")