Skip to content

Commit 57c1fd8

Browse files
committed
BridgeJS: Fix static property call expression for namespaced classes
Static properties on `@JS(namespace:)` classes used `property.callName()` to build the Swift call expression. That method consults `property.staticContext`, which is stored as `.className(abiName)` (e.g. `__Swift_Foundation_UUID`), and emits `\(abiName).\(propertyName)`. The ABI-mangled name is not a valid Swift identifier so the generated thunk failed to compile. Static methods were unaffected because `renderSingleExportedMethod` passes `klass.swiftCallName` directly. Fix `PropertyRenderingContext.callName(for:)` for the `.classStatic` case to bypass `property.callName()` and build the expression directly from `klass.swiftCallName`. This preserves the ABI symbol name (which still comes through `context.className` → `klass.abiName` → `property.getterAbiName(className:)`) while producing a valid Swift call expression in the thunk body. Also remove the now-unnecessary comment from `prelude.mjs` that described what the test was checking (the assertion itself is self-explanatory).
1 parent 575b2bf commit 57c1fd8

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,11 @@ public class ExportSwift {
433433
switch self {
434434
case .enumStatic(let enumDef):
435435
return property.callName(prefix: enumDef.swiftCallName)
436-
case .classStatic, .classInstance:
436+
case .classStatic(let klass):
437+
// property.callName() would use staticContext (the ABI name) as prefix;
438+
// use swiftCallName directly so the emitted expression is valid Swift.
439+
return "\(klass.swiftCallName).\(property.name)"
440+
case .classInstance:
437441
return property.callName()
438442
case .structStatic(let structDef):
439443
return property.callName(prefix: structDef.swiftCallName)

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.Global.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public func _bjs___Swift_Foundation_Greeter_static_makeDefault() -> UnsafeMutabl
5757
@_cdecl("bjs___Swift_Foundation_Greeter_static_defaultGreeting_get")
5858
public func _bjs___Swift_Foundation_Greeter_static_defaultGreeting_get() -> Void {
5959
#if arch(wasm32)
60-
let ret = __Swift_Foundation_Greeter.defaultGreeting
60+
let ret = Greeter.defaultGreeting
6161
return ret.bridgeJSLowerReturn()
6262
#else
6363
fatalError("Only available on WebAssembly")

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/Namespaces.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public func _bjs___Swift_Foundation_Greeter_static_makeDefault() -> UnsafeMutabl
5757
@_cdecl("bjs___Swift_Foundation_Greeter_static_defaultGreeting_get")
5858
public func _bjs___Swift_Foundation_Greeter_static_defaultGreeting_get() -> Void {
5959
#if arch(wasm32)
60-
let ret = __Swift_Foundation_Greeter.defaultGreeting
60+
let ret = Greeter.defaultGreeting
6161
return ret.bridgeJSLowerReturn()
6262
#else
6363
fatalError("Only available on WebAssembly")

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8617,7 +8617,7 @@ public func _bjs___Swift_Foundation_UUID_static_fromValue(_ valueBytes: Int32, _
86178617
@_cdecl("bjs___Swift_Foundation_UUID_static_placeholder_get")
86188618
public func _bjs___Swift_Foundation_UUID_static_placeholder_get() -> Void {
86198619
#if arch(wasm32)
8620-
let ret = __Swift_Foundation_UUID.placeholder
8620+
let ret = UUID.placeholder
86218621
return ret.bridgeJSLowerReturn()
86228622
#else
86238623
fatalError("Only available on WebAssembly")

Tests/prelude.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,6 @@ function BridgeJSRuntimeTests_runJsWorks(instance, exports) {
624624
roundTrippedUUID.release();
625625
uuid.release();
626626

627-
// Static method and property on a namespaced class (@JS(namespace:) + @JS static).
628-
// These must be callable via the namespace path, not as instance members.
629627
const uuidFromStatic = exports.__Swift.Foundation.UUID.fromValue("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
630628
assert.equal(uuidFromStatic.uuidString(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
631629
uuidFromStatic.release();

0 commit comments

Comments
 (0)