Skip to content

Commit 9419743

Browse files
committed
BridgeJS: Module-qualify internal ABI names to fix cross-module type collisions
When two Swift modules in one BridgeJS build exported a `@JS` type with the same name, the generated glue collided silently: duplicated `@_expose(wasm, ...)` thunk names, duplicated `swift_js_struct_lower_<name>`/`swift_js_struct_lift_<name>` hooks, and colliding `structHelpers`/`enumHelpers` JS keys - last writer wins, causing silent data corruption. Fix by module-qualifying the internal ABI identity of exported Swift types while keeping the public JS/TS surface flat: - `BridgeType` payloads for exported Swift types are minted as `<Module>.<Nesting>.<Name>` (still a valid Swift call-site expression). - Type `abiName`s are derived from the module-qualified `swiftCallName` (dots replaced with underscores), so the JS helper key derived from a payload always equals the defining type's `abiName` by construction. - Top-level function thunk names gain the module name as namespace context; enum static contexts carry the qualified `swiftCallName` (sanitized inside `ABINameGenerator`). - `mangleTypeName` sanitizes dots since mangled names are embedded in Swift identifiers. - `ExternalModuleIndex` keeps indexing dependency types by their module-stripped dot path while carrying qualified payloads, so cross-module references resolve to the same ABI names. - Public JS class names, exports keys, and TS declarations stay flat via the new `BridgeType.dropModulePrefix` display accessor. - BridgeJSLink now fails with a clear diagnostic when two modules export the same public name at the same namespace path. Fixes swiftwasm#785
1 parent d58d2c6 commit 9419743

175 files changed

Lines changed: 13463 additions & 13331 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Benchmarks/Sources/Generated/BridgeJS.swift

Lines changed: 761 additions & 761 deletions
Large diffs are not rendered by default.

Benchmarks/Sources/Generated/JavaScript/BridgeJS.json

Lines changed: 191 additions & 191 deletions
Large diffs are not rendered by default.

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/BridgeJS.swift

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
@_spi(BridgeJS) import JavaScriptKit
1010

11-
extension PlayBridgeJSOutput: _BridgedSwiftStruct {
12-
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> PlayBridgeJSOutput {
11+
extension PlayBridgeJS.PlayBridgeJSOutput: _BridgedSwiftStruct {
12+
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> PlayBridgeJS.PlayBridgeJSOutput {
1313
let swiftGlue = String.bridgeJSStackPop()
1414
let importSwiftMacroDecls = String.bridgeJSStackPop()
1515
let outputDts = String.bridgeJSStackPop()
1616
let outputJs = String.bridgeJSStackPop()
17-
return PlayBridgeJSOutput(outputJs: outputJs, outputDts: outputDts, importSwiftMacroDecls: importSwiftMacroDecls, swiftGlue: swiftGlue)
17+
return PlayBridgeJS.PlayBridgeJSOutput(outputJs: outputJs, outputDts: outputDts, importSwiftMacroDecls: importSwiftMacroDecls, swiftGlue: swiftGlue)
1818
}
1919

2020
@_spi(BridgeJS) @_transparent public consuming func bridgeJSStackPush() {
@@ -25,50 +25,50 @@ extension PlayBridgeJSOutput: _BridgedSwiftStruct {
2525
}
2626

2727
init(unsafelyCopying jsObject: JSObject) {
28-
_bjs_struct_lower_PlayBridgeJSOutput(jsObject.bridgeJSLowerParameter())
28+
_bjs_struct_lower_PlayBridgeJS_PlayBridgeJSOutput(jsObject.bridgeJSLowerParameter())
2929
self = Self.bridgeJSStackPop()
3030
}
3131

3232
func toJSObject() -> JSObject {
3333
let __bjs_self = self
3434
__bjs_self.bridgeJSStackPush()
35-
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_PlayBridgeJSOutput()))
35+
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSOutput()))
3636
}
3737
}
3838

3939
#if arch(wasm32)
40-
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSOutput")
41-
fileprivate func _bjs_struct_lower_PlayBridgeJSOutput_extern(_ objectId: Int32) -> Void
40+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJS_PlayBridgeJSOutput")
41+
fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSOutput_extern(_ objectId: Int32) -> Void
4242
#else
43-
fileprivate func _bjs_struct_lower_PlayBridgeJSOutput_extern(_ objectId: Int32) -> Void {
43+
fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSOutput_extern(_ objectId: Int32) -> Void {
4444
fatalError("Only available on WebAssembly")
4545
}
4646
#endif
47-
@inline(never) fileprivate func _bjs_struct_lower_PlayBridgeJSOutput(_ objectId: Int32) -> Void {
48-
return _bjs_struct_lower_PlayBridgeJSOutput_extern(objectId)
47+
@inline(never) fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSOutput(_ objectId: Int32) -> Void {
48+
return _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSOutput_extern(objectId)
4949
}
5050

5151
#if arch(wasm32)
52-
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PlayBridgeJSOutput")
53-
fileprivate func _bjs_struct_lift_PlayBridgeJSOutput_extern() -> Int32
52+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PlayBridgeJS_PlayBridgeJSOutput")
53+
fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSOutput_extern() -> Int32
5454
#else
55-
fileprivate func _bjs_struct_lift_PlayBridgeJSOutput_extern() -> Int32 {
55+
fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSOutput_extern() -> Int32 {
5656
fatalError("Only available on WebAssembly")
5757
}
5858
#endif
59-
@inline(never) fileprivate func _bjs_struct_lift_PlayBridgeJSOutput() -> Int32 {
60-
return _bjs_struct_lift_PlayBridgeJSOutput_extern()
59+
@inline(never) fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSOutput() -> Int32 {
60+
return _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSOutput_extern()
6161
}
6262

63-
extension PlayBridgeJSDiagnostic: _BridgedSwiftStruct {
64-
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> PlayBridgeJSDiagnostic {
63+
extension PlayBridgeJS.PlayBridgeJSDiagnostic: _BridgedSwiftStruct {
64+
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> PlayBridgeJS.PlayBridgeJSDiagnostic {
6565
let endColumn = Int.bridgeJSStackPop()
6666
let endLine = Int.bridgeJSStackPop()
6767
let startColumn = Int.bridgeJSStackPop()
6868
let startLine = Int.bridgeJSStackPop()
6969
let message = String.bridgeJSStackPop()
7070
let file = String.bridgeJSStackPop()
71-
return PlayBridgeJSDiagnostic(file: file, message: message, startLine: startLine, startColumn: startColumn, endLine: endLine, endColumn: endColumn)
71+
return PlayBridgeJS.PlayBridgeJSDiagnostic(file: file, message: message, startLine: startLine, startColumn: startColumn, endLine: endLine, endColumn: endColumn)
7272
}
7373

7474
@_spi(BridgeJS) @_transparent public consuming func bridgeJSStackPush() {
@@ -81,46 +81,46 @@ extension PlayBridgeJSDiagnostic: _BridgedSwiftStruct {
8181
}
8282

8383
init(unsafelyCopying jsObject: JSObject) {
84-
_bjs_struct_lower_PlayBridgeJSDiagnostic(jsObject.bridgeJSLowerParameter())
84+
_bjs_struct_lower_PlayBridgeJS_PlayBridgeJSDiagnostic(jsObject.bridgeJSLowerParameter())
8585
self = Self.bridgeJSStackPop()
8686
}
8787

8888
func toJSObject() -> JSObject {
8989
let __bjs_self = self
9090
__bjs_self.bridgeJSStackPush()
91-
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_PlayBridgeJSDiagnostic()))
91+
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSDiagnostic()))
9292
}
9393
}
9494

9595
#if arch(wasm32)
96-
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSDiagnostic")
97-
fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic_extern(_ objectId: Int32) -> Void
96+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJS_PlayBridgeJSDiagnostic")
97+
fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSDiagnostic_extern(_ objectId: Int32) -> Void
9898
#else
99-
fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic_extern(_ objectId: Int32) -> Void {
99+
fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSDiagnostic_extern(_ objectId: Int32) -> Void {
100100
fatalError("Only available on WebAssembly")
101101
}
102102
#endif
103-
@inline(never) fileprivate func _bjs_struct_lower_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Void {
104-
return _bjs_struct_lower_PlayBridgeJSDiagnostic_extern(objectId)
103+
@inline(never) fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSDiagnostic(_ objectId: Int32) -> Void {
104+
return _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSDiagnostic_extern(objectId)
105105
}
106106

107107
#if arch(wasm32)
108-
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PlayBridgeJSDiagnostic")
109-
fileprivate func _bjs_struct_lift_PlayBridgeJSDiagnostic_extern() -> Int32
108+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PlayBridgeJS_PlayBridgeJSDiagnostic")
109+
fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSDiagnostic_extern() -> Int32
110110
#else
111-
fileprivate func _bjs_struct_lift_PlayBridgeJSDiagnostic_extern() -> Int32 {
111+
fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSDiagnostic_extern() -> Int32 {
112112
fatalError("Only available on WebAssembly")
113113
}
114114
#endif
115-
@inline(never) fileprivate func _bjs_struct_lift_PlayBridgeJSDiagnostic() -> Int32 {
116-
return _bjs_struct_lift_PlayBridgeJSDiagnostic_extern()
115+
@inline(never) fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSDiagnostic() -> Int32 {
116+
return _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSDiagnostic_extern()
117117
}
118118

119-
extension PlayBridgeJSResult: _BridgedSwiftStruct {
120-
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> PlayBridgeJSResult {
121-
let diagnostics = [PlayBridgeJSDiagnostic].bridgeJSStackPop()
122-
let output = Optional<PlayBridgeJSOutput>.bridgeJSStackPop()
123-
return PlayBridgeJSResult(output: output, diagnostics: diagnostics)
119+
extension PlayBridgeJS.PlayBridgeJSResult: _BridgedSwiftStruct {
120+
@_spi(BridgeJS) @_transparent public static func bridgeJSStackPop() -> PlayBridgeJS.PlayBridgeJSResult {
121+
let diagnostics = [PlayBridgeJS.PlayBridgeJSDiagnostic].bridgeJSStackPop()
122+
let output = Optional<PlayBridgeJS.PlayBridgeJSOutput>.bridgeJSStackPop()
123+
return PlayBridgeJS.PlayBridgeJSResult(output: output, diagnostics: diagnostics)
124124
}
125125

126126
@_spi(BridgeJS) @_transparent public consuming func bridgeJSStackPush() {
@@ -129,58 +129,58 @@ extension PlayBridgeJSResult: _BridgedSwiftStruct {
129129
}
130130

131131
init(unsafelyCopying jsObject: JSObject) {
132-
_bjs_struct_lower_PlayBridgeJSResult(jsObject.bridgeJSLowerParameter())
132+
_bjs_struct_lower_PlayBridgeJS_PlayBridgeJSResult(jsObject.bridgeJSLowerParameter())
133133
self = Self.bridgeJSStackPop()
134134
}
135135

136136
func toJSObject() -> JSObject {
137137
let __bjs_self = self
138138
__bjs_self.bridgeJSStackPush()
139-
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_PlayBridgeJSResult()))
139+
return JSObject(id: UInt32(bitPattern: _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSResult()))
140140
}
141141
}
142142

143143
#if arch(wasm32)
144-
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJSResult")
145-
fileprivate func _bjs_struct_lower_PlayBridgeJSResult_extern(_ objectId: Int32) -> Void
144+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lower_PlayBridgeJS_PlayBridgeJSResult")
145+
fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSResult_extern(_ objectId: Int32) -> Void
146146
#else
147-
fileprivate func _bjs_struct_lower_PlayBridgeJSResult_extern(_ objectId: Int32) -> Void {
147+
fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSResult_extern(_ objectId: Int32) -> Void {
148148
fatalError("Only available on WebAssembly")
149149
}
150150
#endif
151-
@inline(never) fileprivate func _bjs_struct_lower_PlayBridgeJSResult(_ objectId: Int32) -> Void {
152-
return _bjs_struct_lower_PlayBridgeJSResult_extern(objectId)
151+
@inline(never) fileprivate func _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSResult(_ objectId: Int32) -> Void {
152+
return _bjs_struct_lower_PlayBridgeJS_PlayBridgeJSResult_extern(objectId)
153153
}
154154

155155
#if arch(wasm32)
156-
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PlayBridgeJSResult")
157-
fileprivate func _bjs_struct_lift_PlayBridgeJSResult_extern() -> Int32
156+
@_extern(wasm, module: "bjs", name: "swift_js_struct_lift_PlayBridgeJS_PlayBridgeJSResult")
157+
fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSResult_extern() -> Int32
158158
#else
159-
fileprivate func _bjs_struct_lift_PlayBridgeJSResult_extern() -> Int32 {
159+
fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSResult_extern() -> Int32 {
160160
fatalError("Only available on WebAssembly")
161161
}
162162
#endif
163-
@inline(never) fileprivate func _bjs_struct_lift_PlayBridgeJSResult() -> Int32 {
164-
return _bjs_struct_lift_PlayBridgeJSResult_extern()
163+
@inline(never) fileprivate func _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSResult() -> Int32 {
164+
return _bjs_struct_lift_PlayBridgeJS_PlayBridgeJSResult_extern()
165165
}
166166

167-
@_expose(wasm, "bjs_PlayBridgeJS_init")
168-
@_cdecl("bjs_PlayBridgeJS_init")
169-
public func _bjs_PlayBridgeJS_init() -> UnsafeMutableRawPointer {
167+
@_expose(wasm, "bjs_PlayBridgeJS_PlayBridgeJS_init")
168+
@_cdecl("bjs_PlayBridgeJS_PlayBridgeJS_init")
169+
public func _bjs_PlayBridgeJS_PlayBridgeJS_init() -> UnsafeMutableRawPointer {
170170
#if arch(wasm32)
171-
let ret = PlayBridgeJS()
171+
let ret = PlayBridgeJS.PlayBridgeJS()
172172
return ret.bridgeJSLowerReturn()
173173
#else
174174
fatalError("Only available on WebAssembly")
175175
#endif
176176
}
177177

178-
@_expose(wasm, "bjs_PlayBridgeJS_updateDetailed")
179-
@_cdecl("bjs_PlayBridgeJS_updateDetailed")
180-
public func _bjs_PlayBridgeJS_updateDetailed(_ _self: UnsafeMutableRawPointer, _ swiftSourceBytes: Int32, _ swiftSourceLength: Int32, _ dtsSourceBytes: Int32, _ dtsSourceLength: Int32) -> Void {
178+
@_expose(wasm, "bjs_PlayBridgeJS_PlayBridgeJS_updateDetailed")
179+
@_cdecl("bjs_PlayBridgeJS_PlayBridgeJS_updateDetailed")
180+
public func _bjs_PlayBridgeJS_PlayBridgeJS_updateDetailed(_ _self: UnsafeMutableRawPointer, _ swiftSourceBytes: Int32, _ swiftSourceLength: Int32, _ dtsSourceBytes: Int32, _ dtsSourceLength: Int32) -> Void {
181181
#if arch(wasm32)
182182
do {
183-
let ret = try PlayBridgeJS.bridgeJSLiftParameter(_self).updateDetailed(swiftSource: String.bridgeJSLiftParameter(swiftSourceBytes, swiftSourceLength), dtsSource: String.bridgeJSLiftParameter(dtsSourceBytes, dtsSourceLength))
183+
let ret = try PlayBridgeJS.PlayBridgeJS.bridgeJSLiftParameter(_self).updateDetailed(swiftSource: String.bridgeJSLiftParameter(swiftSourceBytes, swiftSourceLength), dtsSource: String.bridgeJSLiftParameter(dtsSourceBytes, dtsSourceLength))
184184
return ret.bridgeJSLowerReturn()
185185
} catch let error {
186186
if let error = error.thrownValue.object {
@@ -200,35 +200,35 @@ public func _bjs_PlayBridgeJS_updateDetailed(_ _self: UnsafeMutableRawPointer, _
200200
#endif
201201
}
202202

203-
@_expose(wasm, "bjs_PlayBridgeJS_deinit")
204-
@_cdecl("bjs_PlayBridgeJS_deinit")
205-
public func _bjs_PlayBridgeJS_deinit(_ pointer: UnsafeMutableRawPointer) -> Void {
203+
@_expose(wasm, "bjs_PlayBridgeJS_PlayBridgeJS_deinit")
204+
@_cdecl("bjs_PlayBridgeJS_PlayBridgeJS_deinit")
205+
public func _bjs_PlayBridgeJS_PlayBridgeJS_deinit(_ pointer: UnsafeMutableRawPointer) -> Void {
206206
#if arch(wasm32)
207-
Unmanaged<PlayBridgeJS>.fromOpaque(pointer).release()
207+
Unmanaged<PlayBridgeJS.PlayBridgeJS>.fromOpaque(pointer).release()
208208
#else
209209
fatalError("Only available on WebAssembly")
210210
#endif
211211
}
212212

213-
extension PlayBridgeJS: ConvertibleToJSValue, _BridgedSwiftHeapObject, _BridgedSwiftProtocolExportable {
213+
extension PlayBridgeJS.PlayBridgeJS: ConvertibleToJSValue, _BridgedSwiftHeapObject, _BridgedSwiftProtocolExportable {
214214
var jsValue: JSValue {
215-
return .object(JSObject(id: UInt32(bitPattern: _bjs_PlayBridgeJS_wrap(Unmanaged.passRetained(self).toOpaque()))))
215+
return .object(JSObject(id: UInt32(bitPattern: _bjs_PlayBridgeJS_PlayBridgeJS_wrap(Unmanaged.passRetained(self).toOpaque()))))
216216
}
217217
consuming func bridgeJSLowerAsProtocolReturn() -> Int32 {
218-
_bjs_PlayBridgeJS_wrap(Unmanaged.passRetained(self).toOpaque())
218+
_bjs_PlayBridgeJS_PlayBridgeJS_wrap(Unmanaged.passRetained(self).toOpaque())
219219
}
220220
}
221221

222222
#if arch(wasm32)
223-
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_PlayBridgeJS_wrap")
224-
fileprivate func _bjs_PlayBridgeJS_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32
223+
@_extern(wasm, module: "PlayBridgeJS", name: "bjs_PlayBridgeJS_PlayBridgeJS_wrap")
224+
fileprivate func _bjs_PlayBridgeJS_PlayBridgeJS_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32
225225
#else
226-
fileprivate func _bjs_PlayBridgeJS_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32 {
226+
fileprivate func _bjs_PlayBridgeJS_PlayBridgeJS_wrap_extern(_ pointer: UnsafeMutableRawPointer) -> Int32 {
227227
fatalError("Only available on WebAssembly")
228228
}
229229
#endif
230-
@inline(never) fileprivate func _bjs_PlayBridgeJS_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 {
231-
return _bjs_PlayBridgeJS_wrap_extern(pointer)
230+
@inline(never) fileprivate func _bjs_PlayBridgeJS_PlayBridgeJS_wrap(_ pointer: UnsafeMutableRawPointer) -> Int32 {
231+
return _bjs_PlayBridgeJS_PlayBridgeJS_wrap_extern(pointer)
232232
}
233233

234234
#if arch(wasm32)

Examples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"classes" : [
77
{
88
"constructor" : {
9-
"abiName" : "bjs_PlayBridgeJS_init",
9+
"abiName" : "bjs_PlayBridgeJS_PlayBridgeJS_init",
1010
"effects" : {
1111
"isAsync" : false,
1212
"isStatic" : false,
@@ -18,7 +18,7 @@
1818
},
1919
"methods" : [
2020
{
21-
"abiName" : "bjs_PlayBridgeJS_updateDetailed",
21+
"abiName" : "bjs_PlayBridgeJS_PlayBridgeJS_updateDetailed",
2222
"documentation" : "Structured entry point used by the playground so JS doesn't need to parse diagnostics.",
2323
"effects" : {
2424
"isAsync" : false,
@@ -48,7 +48,7 @@
4848
],
4949
"returnType" : {
5050
"swiftStruct" : {
51-
"_0" : "PlayBridgeJSResult"
51+
"_0" : "PlayBridgeJS.PlayBridgeJSResult"
5252
}
5353
}
5454
}
@@ -57,7 +57,7 @@
5757
"properties" : [
5858

5959
],
60-
"swiftCallName" : "PlayBridgeJS"
60+
"swiftCallName" : "PlayBridgeJS.PlayBridgeJS"
6161
}
6262
],
6363
"enums" : [
@@ -118,7 +118,7 @@
118118
}
119119
}
120120
],
121-
"swiftCallName" : "PlayBridgeJSOutput"
121+
"swiftCallName" : "PlayBridgeJS.PlayBridgeJSOutput"
122122
},
123123
{
124124
"methods" : [
@@ -199,7 +199,7 @@
199199
}
200200
}
201201
],
202-
"swiftCallName" : "PlayBridgeJSDiagnostic"
202+
"swiftCallName" : "PlayBridgeJS.PlayBridgeJSDiagnostic"
203203
},
204204
{
205205
"methods" : [
@@ -215,7 +215,7 @@
215215
"nullable" : {
216216
"_0" : {
217217
"swiftStruct" : {
218-
"_0" : "PlayBridgeJSOutput"
218+
"_0" : "PlayBridgeJS.PlayBridgeJSOutput"
219219
}
220220
},
221221
"_1" : "null"
@@ -230,14 +230,14 @@
230230
"array" : {
231231
"_0" : {
232232
"swiftStruct" : {
233-
"_0" : "PlayBridgeJSDiagnostic"
233+
"_0" : "PlayBridgeJS.PlayBridgeJSDiagnostic"
234234
}
235235
}
236236
}
237237
}
238238
}
239239
],
240-
"swiftCallName" : "PlayBridgeJSResult"
240+
"swiftCallName" : "PlayBridgeJS.PlayBridgeJSResult"
241241
}
242242
]
243243
},

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ public class ExportSwift {
789789
try renderSingleExportedConstructor(
790790
constructor: constructor,
791791
callName: klass.swiftCallName,
792-
returnType: .swiftHeapObject(klass.name)
792+
returnType: .swiftHeapObject(klass.swiftCallName)
793793
)
794794
)
795795
}
@@ -1614,7 +1614,11 @@ extension BridgeType {
16141614
case .jsObject(let name?): return name
16151615
case .swiftHeapObject(let name): return name
16161616
case .unsafePointer(let ptr): return ptr.swiftType
1617-
case .swiftProtocol(let name): return "Any\(name)"
1617+
case .swiftProtocol(let name):
1618+
// The `Any<Proto>` wrapper struct is declared with the bare protocol name in
1619+
// the defining module's glue, so strip any module/namespace qualification.
1620+
let bareName = name.split(separator: ".").last.map(String.init) ?? name
1621+
return "Any\(bareName)"
16181622
case .void: return "Void"
16191623
case .nullable(let wrappedType, let kind):
16201624
return kind == .null ? "Optional<\(wrappedType.swiftType)>" : "JSUndefinedOr<\(wrappedType.swiftType)>"

0 commit comments

Comments
 (0)