Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork57
BridgeJS: Swift -> JS Optionals support#444
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
BridgeJS: Swift -> JS Optionals support#444
Uh oh!
There was an error while loading.Please reload this page.
Conversation
BridgeJS: Optional case enum, optional raw enum supportBridgeJS: Simplify JS glue code as much as possible + basic docs
3f55206 to8ecbbd4Compare8ecbbd4 to6091dfcCompareThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull Request Overview
This PR adds comprehensive support for Swift Optional types when exporting Swift functionality to JavaScript/TypeScript using the BridgeJS plugin. Swift optionals are mapped toT | null union types in TypeScript, usingnull to represent the absence of a value which aligns with Swift'snil semantics.
Key changes include:
- Support for all optional syntax forms:
T?,Optional<T>,Swift.Optional<T>, and type aliases - Bidirectional optional handling for parameters, return values, and class properties
- New intrinsic functions for optional type bridging and lowering operations
Reviewed Changes
Copilot reviewed 57 out of 65 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/JavaScriptKit/BridgeJSInstrincics.swift | Adds extensive optional bridging support with new protocols and extension methods |
| Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Exporting-Swift/Exporting-Swift-Optional.md | Comprehensive documentation for optional types usage |
| Tests/BridgeJSRuntimeTests/ExportAPITests.swift | Test functions for all optional type scenarios |
| Plugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift | Updates type system to include optional case |
| Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift | Core optional type resolution and code generation logic |
Comments suppressed due to low confidence (1)
Sources/JavaScriptKit/BridgeJSInstrincics.swift:1
- The function should be marked as
consuminglike other similar functions in this file to match the pattern used elsewhere for bridge lowering functions.
/// BridgeJS IntrinsicsTip: Customize your code reviews with copilot-instructions.md.Create the file orlearn how to get started.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| @JSfunctest(name:String?)->String? {return name } | ||
| @JSfunctest(name:Optional<String>)->Optional<String> {return name } | ||
| @JSfunctest(name: Swift.Optional<String>)-> Swift.Optional<String> {return name } | ||
| @JSfunctest(name: Swift.Optional<String >)-> Swift.Optional<String. > {return name } |
CopilotAISep 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
There's a typo with an extra period before the closing angle bracket:String. > should beString >.
| @JS func test(name: Swift.Optional< String >) -> Swift.Optional< String. > { return name } | |
| @JS func test(name: Swift.Optional< String >) -> Swift.Optional< String > { return name } |
| tmpRetString=null; | ||
| }else{ | ||
| tmpRetString=swift.memory.getObject(objectId); |
CopilotAISep 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Wrong variable assignment: should assign totmpRetString for object return storage, but this should likely be a different variable for optional object returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Great job 👏
79a0a4e intoswiftwasm:mainUh oh!
There was an error while loading.Please reload this page.
Introduction
This PR adds support for Swift Optionals when exporting Swift funcionality to JS / TS using BridgeJS plugin.
Overview
T | nullunion, asnullexplicitly represents intentional absent of value, which aligns with Swift's nil.extension Optionalswere added toBridgeJSIntrinsicsto keep generated Swift glue code sparse and reuse existing patterns. This required new protocols for case and associated enum value types, which_swift_js_return_optional_<type>Examples
Generated TypeScript:
Testing
Added tests for different scenarios for all supported optional data types, including parameters, properties and return value usage.
Documentation
Extended current documentation with new
Exporting-Swift-Optional.md