Skip to content

Commit ebbde04

Browse files
authored
Merge pull request swiftwasm#772 from PassiveLogic/kr/global-namespace-static-members
BridgeJS: Emit static members in declare global class declarations
2 parents 2fc75d4 + 3c520b0 commit ebbde04

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,17 +3143,19 @@ extension BridgeJSLink {
31433143

31443144
let sortedMethods = klass.methods.sorted { $0.name < $1.name }
31453145
for method in sortedMethods {
3146+
let staticKeyword = method.effects.isStatic ? "static " : ""
31463147
let methodSignature =
3147-
"\(method.name)\(renderTSSignatureCallback(method.parameters, method.returnType, method.effects));"
3148+
"\(staticKeyword)\(method.name)\(renderTSSignatureCallback(method.parameters, method.returnType, method.effects));"
31483149
printer.write(methodSignature)
31493150
}
31503151

3151-
let sortedProperties = klass.properties.filter { !$0.isStatic }.sorted {
3152-
$0.name < $1.name
3153-
}
3152+
let sortedProperties = klass.properties.sorted { $0.name < $1.name }
31543153
for property in sortedProperties {
3154+
let staticKeyword = property.isStatic ? "static " : ""
31553155
let readonly = property.isReadonly ? "readonly " : ""
3156-
printer.write("\(readonly)\(property.name): \(property.type.tsType);")
3156+
printer.write(
3157+
"\(staticKeyword)\(readonly)\(property.name): \(property.type.tsType);"
3158+
)
31573159
}
31583160

31593161
printer.write("release(): void;")

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Namespaces.Global.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ declare global {
3434
class Greeter {
3535
constructor(name: string);
3636
greet(): string;
37-
makeDefault(): Greeter;
37+
static makeDefault(): Greeter;
38+
static readonly defaultGreeting: string;
3839
release(): void;
3940
}
4041
class UUID {

0 commit comments

Comments
 (0)