Skip to content

BridgeJS: Fix issues exporting nested types#783

Open
wfltaylor wants to merge 1 commit into
swiftwasm:mainfrom
wfltaylor:js-merge-structs
Open

BridgeJS: Fix issues exporting nested types#783
wfltaylor wants to merge 1 commit into
swiftwasm:mainfrom
wfltaylor:js-merge-structs

Conversation

@wfltaylor

Copy link
Copy Markdown
Contributor

There are currently a few issues with the JS/TS code generation, due to a lack of merging. For example, the following Swift code:

@JS struct Control {
    @JS enum Variant: String { case button, slider }

    @JS struct Layout {
        @JS enum Alignment: String { case leading, trailing }
        var padding: Int
    }

    var name: String

    @JS init(name: String) { self.name = name }
}

generates a .d.ts:

export type Exports = {
    Control: {
        init(name: string): Control;
    },
    Control: {
        Variant: VariantObject,
        Layout: {
            Alignment: AlignmentObject
        }
    }
}

This doesn’t type check correctly. Similar issues occur with the emitted .js, except instead of failing to type check, these will cause runtime issues (since keys are overwritten instead of merged).

This PR is a bit of a refactor of BridgeJSLink to address this. Instead of being a member of a NamespaceNode, each class and struct becomes its own NamespaceNode. This makes it much easier to merge everything together so it can be emitted as one unit.

@kateinoigakukun kateinoigakukun requested a review from krodak June 30, 2026 06:41
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.

1 participant