Skip to content

BridgeJS: Swift struct support - #479

Merged
kateinoigakukun merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:feat/struct
Dec 20, 2025
Merged

kateinoigakukun merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:feat/struct

Conversation

@krodak

@krodak krodak commented Dec 19, 2025

Copy link
Copy Markdown
Member

Introduction

This PR adds ability to export Swift structs to JS / TS using BridgeJS plugin.

Example

@JS struct Point {
    var x: Double
    var y: Double

    @JS init(x: Double, y: Double) {
        self.x = x
        self.y = y
    }
}

In JavaScript:

const point = exports.Point.init(10.0, 20.0);
console.log(point.x); // 10.0

TypeScript:

export interface Point {
    x: number;
    y: number;
}

export type Exports = {
    Point: {
        init(x: number, y: number): Point;
    }
}

Additional Changes

  • refactored code around static methods / properties to keep it DRY after struct introduction
  • some additional code organisation around code gen on Swift side

Testing

Added comprehensive snapshot and runtime tests for struct.

Documentation

Extended current documentation with new Exporting-Swift-Struct.md. It also covers differences between class and struct initialization.

Next steps

Will issue additional PRs with:

  • struct benchmarks
  • default value support for struct type
@krodak krodak self-assigned this Dec 19, 2025

@kateinoigakukun kateinoigakukun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall approach seems well thought out, let's incubate it on the main branch. Thank you for your huge effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants