Skip to content

Conversation

@krodak
Copy link
Member

@krodak krodak commented Dec 19, 2025

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
Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

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!

@kateinoigakukun kateinoigakukun merged commit 9b2a6b1 into swiftwasm:main Dec 20, 2025
10 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