Skip to content

BridgeJS: Fix namespace enum with @JS(namespace:) attribute#562

Merged
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:krodak/static-func-fix
Feb 3, 2026
Merged

BridgeJS: Fix namespace enum with @JS(namespace:) attribute#562
kateinoigakukun merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:krodak/static-func-fix

Conversation

@krodak
Copy link
Member

@krodak krodak commented Feb 3, 2026

Overview

Fixes a bug where namespace enums with explicit @JS(namespace:) attribute generated incorrect Swift code that failed to compile.

Issue

When using @JS(namespace: "Services.Graph") on a namespace enum:

@JS(namespace: "Services.Graph")
enum GraphOperations {
    @JS static func createGraph(rootId: Int) -> Int {
        return rootId * 10
    }
}

The generated Swift code incorrectly used the JavaScript namespace path as the Swift call path:

let ret = Services.Graph.GraphOperations.createGraph(rootId: ...)
//        ^^^^^^^^^^^^^^ - doesn't exist in Swift!

Fix

Changed StaticContext.namespaceEnum to carry the actual Swift type name (swiftCallName) instead of relying on the JavaScript namespace path.

Now generates correct Swift code:

let ret = GraphOperations.createGraph(rootId: ...)

The JavaScript namespace organization is preserved separately and doesn't affect the Swift call site.

Testing

  • Added snapshot tests for namespace enum with @JS(namespace:) attribute
  • Added E2E tests for Services.Graph.GraphOperations namespace
  • Added tests for nested namespace enums (Utils.StringUtils) which was missing

@krodak krodak self-assigned this Feb 3, 2026
@kateinoigakukun kateinoigakukun merged commit 4fa48cf into swiftwasm:main Feb 3, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants