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
9 changes: 2 additions & 7 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,9 @@ public class ExportSwift {
if function.effects.isStatic, let staticContext = function.staticContext {
let callName: String
switch staticContext {
case .className(let baseName), .enumName(let baseName), .structName(let baseName):
case .className(let baseName), .enumName(let baseName), .structName(let baseName),
.namespaceEnum(let baseName):
callName = "\(baseName).\(function.name)"
case .namespaceEnum:
if let namespace = function.namespace, !namespace.isEmpty {
callName = "\(namespace.joined(separator: ".")).\(function.name)"
} else {
callName = function.name
}
}
builder.call(name: callName, returnType: function.returnType)
} else {
Expand Down
8 changes: 6 additions & 2 deletions Plugins/BridgeJS/Sources/BridgeJSCore/SwiftToSkeleton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,8 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor {
}

let isNamespaceEnum = exportedEnumByName[enumKey]?.cases.isEmpty ?? true
staticContext = isNamespaceEnum ? .namespaceEnum : .enumName(enumName)
let swiftCallName = exportedEnumByName[enumKey]?.swiftCallName ?? enumName
staticContext = isNamespaceEnum ? .namespaceEnum(swiftCallName) : .enumName(enumName)
case .protocolBody(_, _):
return nil
case .structBody(let structName, _):
Expand Down Expand Up @@ -1187,7 +1188,10 @@ private final class ExportSwiftAPICollector: SyntaxAnyVisitor {
return .skipChildren
}
let isNamespaceEnum = exportedEnumByName[enumKey]?.cases.isEmpty ?? true
staticContext = isStatic ? (isNamespaceEnum ? .namespaceEnum : .enumName(enumName)) : nil
// Use swiftCallName for the full Swift call path (handles nested enums correctly)
let swiftCallName = exportedEnumByName[enumKey]?.swiftCallName ?? enumName
staticContext =
isStatic ? (isNamespaceEnum ? .namespaceEnum(swiftCallName) : .enumName(swiftCallName)) : nil
case .topLevel:
diagnose(node: node, message: "@JS var must be inside a @JS class or enum")
return .skipChildren
Expand Down
10 changes: 3 additions & 7 deletions Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public enum StaticContext: Codable, Equatable, Sendable {
case className(String)
case structName(String)
case enumName(String)
case namespaceEnum
case namespaceEnum(String)
}

// MARK: - Struct Skeleton
Expand Down Expand Up @@ -533,13 +533,9 @@ public struct ExportedProperty: Codable, Equatable, Sendable {
public func callName(prefix: String? = nil) -> String {
if let staticContext = staticContext {
switch staticContext {
case .className(let baseName), .enumName(let baseName), .structName(let baseName):
case .className(let baseName), .enumName(let baseName), .structName(let baseName),
.namespaceEnum(let baseName):
return "\(baseName).\(name)"
case .namespaceEnum:
if let namespace = namespace, !namespace.isEmpty {
let namespacePath = namespace.joined(separator: ".")
return "\(namespacePath).\(name)"
}
}
}
if let prefix = prefix {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ enum Internal {
}
}

// TODO: Add namespace enum with static functions when supported
@JS(namespace: "Services.Graph")
enum GraphOperations {
@JS static func createGraph(rootId: Int) -> Int {
return rootId * 10
}

@JS static func nodeCount(graphId: Int) -> Int {
return graphId
}

@JS static func validate(graphId: Int) throws(JSException) -> Bool {
return graphId > 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ export type Exports = {
},
},
},
Services: {
Graph: {
GraphOperations: {
createGraph(rootId: number): number;
nodeCount(graphId: number): number;
validate(graphId: number): boolean;
},
},
},
Utils: {
Converter: {
new(): Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,30 @@ export async function createInstantiator(options, swift) {
},
},
},
Services: {
Graph: {
GraphOperations: {
createGraph: function bjs_Services_Graph_GraphOperations_static_createGraph(rootId) {
const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_createGraph(rootId);
return ret;
},
nodeCount: function bjs_Services_Graph_GraphOperations_static_nodeCount(graphId) {
const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_nodeCount(graphId);
return ret;
},
validate: function bjs_Services_Graph_GraphOperations_static_validate(graphId) {
const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_validate(graphId);
if (tmpRetException) {
const error = swift.memory.getObject(tmpRetException);
swift.memory.release(tmpRetException);
tmpRetException = undefined;
throw error;
}
return ret !== 0;
},
},
},
},
Utils: {
Converter,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ declare global {
}
}
}
namespace Services {
namespace Graph {
namespace GraphOperations {
createGraph(rootId: number): number;
nodeCount(graphId: number): number;
validate(graphId: number): boolean;
}
}
}
namespace Utils {
class Converter {
constructor();
Expand Down Expand Up @@ -103,6 +112,15 @@ export type Exports = {
},
},
},
Services: {
Graph: {
GraphOperations: {
createGraph(rootId: number): number;
nodeCount(graphId: number): number;
validate(graphId: number): boolean;
},
},
},
Utils: {
Converter: {
new(): Converter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,15 @@ export async function createInstantiator(options, swift) {
if (typeof globalThis.Networking.APIV2.Internal === 'undefined') {
globalThis.Networking.APIV2.Internal = {};
}
if (typeof globalThis.Services === 'undefined') {
globalThis.Services = {};
}
if (typeof globalThis.Services.Graph === 'undefined') {
globalThis.Services.Graph = {};
}
if (typeof globalThis.Services.Graph.GraphOperations === 'undefined') {
globalThis.Services.Graph.GraphOperations = {};
}
if (typeof globalThis.Utils === 'undefined') {
globalThis.Utils = {};
}
Expand All @@ -369,6 +378,30 @@ export async function createInstantiator(options, swift) {
},
},
},
Services: {
Graph: {
GraphOperations: {
createGraph: function bjs_Services_Graph_GraphOperations_static_createGraph(rootId) {
const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_createGraph(rootId);
return ret;
},
nodeCount: function bjs_Services_Graph_GraphOperations_static_nodeCount(graphId) {
const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_nodeCount(graphId);
return ret;
},
validate: function bjs_Services_Graph_GraphOperations_static_validate(graphId) {
const ret = instance.exports.bjs_Services_Graph_GraphOperations_static_validate(graphId);
if (tmpRetException) {
const error = swift.memory.getObject(tmpRetException);
swift.memory.release(tmpRetException);
tmpRetException = undefined;
throw error;
}
return ret !== 0;
},
},
},
},
Utils: {
Converter,
},
Expand All @@ -377,6 +410,9 @@ export async function createInstantiator(options, swift) {
globalThis.Utils.Converter = exports.Utils.Converter;
globalThis.Networking.API.HTTPServer = exports.Networking.API.HTTPServer;
globalThis.Networking.APIV2.Internal.TestServer = exports.Networking.APIV2.Internal.TestServer;
globalThis.Services.Graph.GraphOperations.createGraph = exports.Services.Graph.GraphOperations.createGraph;
globalThis.Services.Graph.GraphOperations.nodeCount = exports.Services.Graph.GraphOperations.nodeCount;
globalThis.Services.Graph.GraphOperations.validate = exports.Services.Graph.GraphOperations.validate;
return exports;
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,129 @@
],
"swiftCallName" : "Internal.SupportedMethod",
"tsFullPath" : "Networking.APIV2.Internal.SupportedMethod"
},
{
"cases" : [

],
"emitStyle" : "const",
"name" : "GraphOperations",
"namespace" : [
"Services",
"Graph"
],
"staticMethods" : [
{
"abiName" : "bjs_Services_Graph_GraphOperations_static_createGraph",
"effects" : {
"isAsync" : false,
"isStatic" : true,
"isThrows" : false
},
"name" : "createGraph",
"namespace" : [
"Services",
"Graph",
"GraphOperations"
],
"parameters" : [
{
"label" : "rootId",
"name" : "rootId",
"type" : {
"int" : {

}
}
}
],
"returnType" : {
"int" : {

}
},
"staticContext" : {
"namespaceEnum" : {
"_0" : "GraphOperations"
}
}
},
{
"abiName" : "bjs_Services_Graph_GraphOperations_static_nodeCount",
"effects" : {
"isAsync" : false,
"isStatic" : true,
"isThrows" : false
},
"name" : "nodeCount",
"namespace" : [
"Services",
"Graph",
"GraphOperations"
],
"parameters" : [
{
"label" : "graphId",
"name" : "graphId",
"type" : {
"int" : {

}
}
}
],
"returnType" : {
"int" : {

}
},
"staticContext" : {
"namespaceEnum" : {
"_0" : "GraphOperations"
}
}
},
{
"abiName" : "bjs_Services_Graph_GraphOperations_static_validate",
"effects" : {
"isAsync" : false,
"isStatic" : true,
"isThrows" : true
},
"name" : "validate",
"namespace" : [
"Services",
"Graph",
"GraphOperations"
],
"parameters" : [
{
"label" : "graphId",
"name" : "graphId",
"type" : {
"int" : {

}
}
}
],
"returnType" : {
"bool" : {

}
},
"staticContext" : {
"namespaceEnum" : {
"_0" : "GraphOperations"
}
}
}
],
"staticProperties" : [

],
"swiftCallName" : "GraphOperations",
"tsFullPath" : "Services.Graph.GraphOperations"
}
],
"exposeToGlobal" : true,
Expand Down
Loading