Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,19 @@ public class ExportSwift {
func render(abiName: String) -> DeclSyntax {
let body: CodeBlockItemListSyntax
if effects.isAsync {
// Explicit closure type annotation needed when throws is present
// so Swift infers throws(JSException) instead of throws(any Error)
// See: https://github.com/swiftlang/swift/issues/76165
let closureHead: String
if effects.isThrows {
let hasReturn = self.body.contains { $0.description.contains("return ") }
let ret = hasReturn ? " -> JSValue" : ""
closureHead = " () async throws(JSException)\(ret) in"
} else {
closureHead = ""
}
body = """
let ret = JSPromise.async {
let ret = JSPromise.async {\(raw: closureHead)
\(CodeBlockItemListSyntax(self.body))
}.jsObject
return ret.bridgeJSLowerReturn()
Expand Down