Skip to content

Commit 3c520b0

Browse files
committed
BridgeJS: Emit static members in declare global class declarations
The `declare global { namespace ... }` class stub rendered every method without `static` and filtered properties to instance-only, so a `@JS static func` on a namespaced class was typed as an instance method and a `@JS static var` was omitted from the generated `.d.ts`. This was a type-only defect: the emitted JavaScript already exposes these members statically (and the class's namespace export entry types them correctly), so only TypeScript consumers were affected. Split static and instance members in this path: emit static methods with `static` and include static properties. This has been incorrect since the global namespace class stub was introduced, not a regression. The `Namespaces.Global` snapshot already exercises a namespaced class with `static func`/`static var` but had recorded the wrong output, so it is updated to the corrected declarations.
1 parent 2fc75d4 commit 3c520b0

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)