Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BridgeJS: Enum export support for case / raw / empty enums#418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@krodak
Copy link
Member

Introduction

This PR adds basic enum export support to the BridgeJS plugin.

Feature Overview

Supported Enum Types

  • Case Enums
  • Raw Value Enums
  • Namespace Enums - empty enums used for organizing types into hierarchical namespaces

Enum Output Styles

New@JS(enumStyle: .tsEnum) parameter allows choosing between:

  • .const (default): Generates const objects with union types for maximum compatibility
  • .tsEnum: Generates native TypeScript enum declarations (available for case enums and raw value enums with String or numeric raw types only)

Examples

Case Enum with Both Styles

@JSenumDirection{case north, south, east, west}@JS(enumStyle:.tsEnum)enumTSDirection{case north, south, east, west}

Generated TypeScript:

// Const object style (default)constDirection:{readonlyNorth:0;readonlySouth:1;readonlyEast:2;readonlyWest:3;};typeDirection=typeofDirection[keyoftypeofDirection];// If@JS(enumStyle: .tsEnum) would be definedenumTSDirection{North=0,South=1,East=2,West=3,}

Raw Value Enum

@JSenumTheme:String{case light="light"case dark="dark"case auto="auto"}
// Const object style (default)constTheme:{readonlyLight:"light";readonlyDark:"dark";readonlyAuto:"auto";};typeTheme=typeofTheme[keyoftypeofTheme];// If@JS(enumStyle: .tsEnum) would be definedenumTheme{Light="light",Dark="dark",Auto="auto",}

Namespace Enum

@JSenumNetworking{@JSenumAPI{@JSenumMethod{case getcase postcase putcase delete}        // Invalid to declare @JS(namespace) here as it would be conflicting with nesting@JSclassHTTPServer{@JSinit(){}@JSfunc call(_ method:Method)}}}// Top level enums can use namespace@JS(namespace:"Networking.APIV2")enumInternal{@JSenumSupportedMethod{case getcase post}@JSclassTestServer{@JSinit(){}@JSfunc call(_ method:SupportedMethod)}}
namespaceNetworking{namespaceAPI{classHTTPServer{constructor();call(method:Networking.API.Method):void;}constMethod:{readonlyGet:0;readonlyPost:1;readonlyPut:2;readonlyDelete:3;};typeMethod=typeofMethod[keyoftypeofMethod];}namespaceAPIV2{namespaceInternal{classTestServer{constructor();call(method:Internal.SupportedMethod):void;}constSupportedMethod:{readonlyGet:0;readonlyPost:1;};typeSupportedMethod=typeofSupportedMethod[keyoftypeofSupportedMethod];}}}

What's Not Supported

  • Associated value enums (will be tackled as next step)
  • Computed properties or methods within enums

Testing

  • EnumCase.swift - Case enum tests with both output styles
  • EnumRawType.swift - Raw value enum tests for all supported types
  • EnumNamespace.swift - Namespace enums with mixing same namespace as enum and@JS(namespace)

Docs

Docs updated with example for each enum type, new macro parameter and basic relevant usage guide.

@krodakkrodak self-assigned thisAug 21, 2025
@kateinoigakukun
Copy link
Member

Thanks! I'lll take a closer look tomorrow but meanwhile would you mind adding runtime test in Tests/BridgeJSRuntimeTests?

krodak reacted with thumbs up emoji

Copy link
Member

@kateinoigakukunkateinoigakukun 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 looks good to me!

krodak reacted with rocket emoji
@krodakkrodakforce-pushed thefeat/enum-support branch 2 times, most recently fromda01493 to0ef902dCompareAugust 22, 2025 11:15
@kateinoigakukunkateinoigakukun merged commit79a9c1b intoswiftwasm:mainAug 22, 2025
9 checks passed
@kateinoigakukunkateinoigakukun linked an issueAug 23, 2025 that may beclosed by this pull request
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kateinoigakukunkateinoigakukunkateinoigakukun approved these changes

Assignees

@krodakkrodak

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

BridgeJS: Support enum as parameter/return type

2 participants

@krodak@kateinoigakukun

[8]ページ先頭

©2009-2025 Movatter.jp