Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,16 @@ extension BridgeJSLink {
"\(method.name)\(renderTSSignatureCallback(method.parameters, method.returnType, method.effects));"
printer.write(methodSignature)
}

let sortedProperties = klass.properties.filter { !$0.isStatic }.sorted {
$0.name < $1.name
}
for property in sortedProperties {
let readonly = property.isReadonly ? "readonly " : ""
printer.write("\(readonly)\(property.name): \(property.type.tsType);")
}

printer.write("release(): void;")
}
printer.write("}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ declare global {
class Converter {
constructor();
format(value: number): string;
release(): void;
}
}
namespace Networking {
namespace API {
class HTTPServer {
constructor();
call(method: Networking.API.MethodTag): void;
release(): void;
}
const MethodValues: {
readonly Get: 0;
Expand All @@ -55,6 +57,7 @@ declare global {
class TestServer {
constructor();
call(method: Networking.APIV2.Internal.SupportedMethodTag): void;
release(): void;
}
const SupportedMethodValues: {
readonly Get: 0;
Expand All @@ -77,6 +80,8 @@ declare global {
class Converter {
constructor();
toString(value: number): string;
precision: number;
release(): void;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare global {
class GlobalClass {
constructor();
greet(): string;
release(): void;
}
function globalFunction(): string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare global {
constructor();
addItem(item: Greeter): void;
getItems(): Greeter[];
release(): void;
}
}
namespace MyModule {
Expand All @@ -24,6 +25,7 @@ declare global {
class Converter {
constructor();
toString(value: number): string;
release(): void;
}
}
}
Expand All @@ -32,9 +34,11 @@ declare global {
class Greeter {
constructor(name: string);
greet(): string;
release(): void;
}
class UUID {
uuidString(): string;
release(): void;
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions Tests/BridgeJSGlobalTests/Generated/BridgeJS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ public func _bjs_GlobalUtils_PublicConverter_toString(_ _self: UnsafeMutableRawP
#endif
}

@_expose(wasm, "bjs_GlobalUtils_PublicConverter_precision_get")
@_cdecl("bjs_GlobalUtils_PublicConverter_precision_get")
public func _bjs_GlobalUtils_PublicConverter_precision_get(_ _self: UnsafeMutableRawPointer) -> Int32 {
#if arch(wasm32)
let ret = GlobalUtils.PublicConverter.bridgeJSLiftParameter(_self).precision
return ret.bridgeJSLowerReturn()
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_GlobalUtils_PublicConverter_precision_set")
@_cdecl("bjs_GlobalUtils_PublicConverter_precision_set")
public func _bjs_GlobalUtils_PublicConverter_precision_set(_ _self: UnsafeMutableRawPointer, _ value: Int32) -> Void {
#if arch(wasm32)
GlobalUtils.PublicConverter.bridgeJSLiftParameter(_self).precision = Int.bridgeJSLiftParameter(value)
#else
fatalError("Only available on WebAssembly")
#endif
}

@_expose(wasm, "bjs_GlobalUtils_PublicConverter_deinit")
@_cdecl("bjs_GlobalUtils_PublicConverter_deinit")
public func _bjs_GlobalUtils_PublicConverter_deinit(_ pointer: UnsafeMutableRawPointer) -> Void {
Expand Down
12 changes: 12 additions & 0 deletions Tests/BridgeJSGlobalTests/Generated/JavaScript/BridgeJS.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,19 @@
"GlobalUtils"
],
"properties" : [
{
"isReadonly" : false,
"isStatic" : false,
"name" : "precision",
"namespace" : [
"GlobalUtils"
],
"type" : {
"int" : {

}
}
}
],
"swiftCallName" : "GlobalUtils.PublicConverter"
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/BridgeJSGlobalTests/GlobalAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ enum Internal {

@JS enum GlobalUtils {
@JS class PublicConverter {
@JS var precision: Int = 2

@JS init() {}

@JS func toString(value: Int) -> String {
Expand Down
3 changes: 3 additions & 0 deletions Tests/prelude.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,9 @@ function BridgeJSGlobalTests_runJsWorksGlobal() {

const globalConverter = new globalThis.GlobalUtils.PublicConverter();
assert.equal(globalConverter.toString(99), "99");
assert.equal(globalConverter.precision, 2);
globalConverter.precision = 5;
assert.equal(globalConverter.precision, 5);
globalConverter.release();

const globalHttpServer = new globalThis.GlobalNetworking.API.TestHTTPServer();
Expand Down