Skip to content

Commit a931787

Browse files
Documentation tweaks
1 parent 6682a2e commit a931787

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

Plugins/BridgeJS/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
BridgeJS provides easy interoperability between Swift and JavaScript/TypeScript. It enables:
1212

13-
1. **Export Swift to JavaScript** Expose Swift functions, classes, and types to JavaScript; the plugin generates TypeScript definitions (`.d.ts`) for the exported API.
14-
2. **Import JavaScript into Swift** Make JavaScript/TypeScript APIs callable from Swift with macro-annotated bindings or bindings generated from a TypeScript declaration file (`bridge-js.d.ts`).
13+
1. **Export Swift to JavaScript** - Expose Swift functions, classes, and types to JavaScript; the plugin generates TypeScript definitions (`.d.ts`) for the exported API.
14+
2. **Import JavaScript into Swift** - Make JavaScript/TypeScript APIs callable from Swift with macro-annotated bindings or bindings generated from a TypeScript declaration file (`bridge-js.d.ts`).
1515

1616
The workflow is:
1717

@@ -174,7 +174,7 @@ For detailed semantics, see the [How It Works sections](https://swiftpackageinde
174174
`BridgeJSToolInternal` exposes pipeline stages for debugging:
175175

176176
- `emit-skeleton` - Parse Swift files (or `-` for stdin) and print the BridgeJS skeleton as JSON.
177-
- `emit-swift-thunks` Read skeleton JSON (from a file or `-` for stdin) and print the generated Swift glue (export and import thunks).
177+
- `emit-swift-thunks` - Read skeleton JSON (from a file or `-` for stdin) and print the generated Swift glue (export and import thunks).
178178
- `emit-js` / `emit-dts` - Read skeleton JSON files (or `-` for stdin) and print the .js/.d.ts
179179

180180
Use these to inspect parser output and generated code without running the full generate/link pipeline.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ _ = document.body.appendChild(button)
4848
4949
BridgeJS provides easy interoperability between Swift and JavaScript/TypeScript. It enables:
5050

51-
- **Export Swift to JavaScript** Expose Swift functions, classes, and types to JavaScript; the plugin also generates TypeScript definitions (`.d.ts`) for the exported API.
52-
- **Import JavaScript into Swift** Make JavaScript/TypeScript APIs (functions, classes, globals like `document` or `console`) callable from Swift with type-safe bindings. You can declare bindings with macros in Swift or generate them from a TypeScript declaration file (`bridge-js.d.ts`).
51+
- **Export Swift to JavaScript** - Expose Swift functions, classes, and types to JavaScript; the plugin also generates TypeScript definitions (`.d.ts`) for the exported API.
52+
- **Import JavaScript into Swift** - Make JavaScript/TypeScript APIs (functions, classes, globals like `document` or `console`) callable from Swift with type-safe bindings. You can declare bindings with macros in Swift or generate them from a TypeScript declaration file (`bridge-js.d.ts`).
5353

5454
For architecture details, see the [BridgeJS Plugin README](Plugins/BridgeJS/README.md). For package and build setup, see [Setting up BridgeJS](https://swiftpackageindex.com/swiftwasm/JavaScriptKit/documentation/javascriptkit/setting-up-bridgejs) in the documentation.
5555

5656
### Exporting Swift to JavaScript
5757

58-
Mark Swift code with `@JS` (the ``JS(namespace:enumStyle:)`` attribute) to make it callable from JavaScript:
58+
Mark Swift code with `@JS` to make it callable from JavaScript:
5959

6060
```swift
6161
import JavaScriptKit

Sources/JavaScriptKit/Documentation.docc/Articles/BridgeJS/Introducing-BridgeJS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Introducing BridgeJS
22

3-
Faster, easier SwiftJavaScript bridging for WebAssembly.
3+
Faster, easier Swift-JavaScript bridging for WebAssembly.
44

55
## Overview
66

7-
**BridgeJS** is a layer underneath JavaScriptKit that makes SwiftJavaScript interop **faster and easier**: you declare the shape of the API in Swift (or in TypeScript, which generates Swift), and the tool generates glue code.
7+
**BridgeJS** is a layer underneath JavaScriptKit that makes Swift-JavaScript interop **faster and easier**: you declare the shape of the API in Swift (or in TypeScript, which generates Swift), and the tool generates glue code.
88

99
Benefits over the dynamic `JSObject` / `JSValue` APIs include:
1010

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Unsupported Features in BridgeJS
2+
3+
Limitations and unsupported patterns when using BridgeJS.
4+
5+
## Overview
6+
7+
BridgeJS generates glue code per Swift target (module). Some patterns that are valid in Swift or TypeScript are not supported across the bridge today. This article summarizes the main limitations so you can design your APIs accordingly.
8+
9+
## Type usage crossing module boundary
10+
11+
BridgeJS does **not** support using a type across module boundaries in the following situations.
12+
13+
### Exporting Swift: types from another Swift module
14+
15+
If you have multiple Swift targets (e.g. a library and an app), you **cannot** use a type defined in one target in an exported API of another target.
16+
17+
**Unsupported example:** Module `App` exports a function that takes or returns a type defined in module `Lib`:
18+
19+
```swift
20+
// In module Lib
21+
@JS public struct LibPoint {
22+
let x: Double
23+
let y: Double
24+
}
25+
26+
// In module App (depends on Lib) - unsupported
27+
@JS public func transform(_ p: LibPoint) -> LibPoint { ... }
28+
```

Sources/JavaScriptKit/Documentation.docc/Articles/FAQ.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Initialization is asynchronous because the runtime must **fetch and instantiate
99
1. **Fetching** the `.wasm` binary (e.g. over the network or from disk).
1010
2. **Instantiating** it with `WebAssembly.instantiate()` (or `instantiateStreaming()`), which compiles the module and allocates the linear memory and table.
1111

12-
Until that completes, there is no WebAssembly instance to call into, so the entry point that sets up the SwiftJavaScript bridge has to be `async` and must be `await`ed from the JavaScript host (e.g. in your `index.js` or HTML script). This matches the standard WebAssembly JavaScript API, which is promise-based.
12+
Until that completes, there is no WebAssembly instance to call into, so the entry point that sets up the Swift-JavaScript bridge has to be `async` and must be `await`ed from the JavaScript host (e.g. in your `index.js` or HTML script). This matches the standard WebAssembly JavaScript API, which is promise-based.
1313

1414
## Why does every imported JavaScript interface via BridgeJS declare `throws(JSException)`?
1515

@@ -25,4 +25,4 @@ That can lead to **inconsistent memory state** and **resource leaks**. To avoid
2525
- You explicitly decide how to react to JavaScript exceptions (e.g. `try`/`catch`, or propagating `throws`).
2626
- Epilogues and cleanup run in a well-defined way when you handle the error in Swift.
2727

28-
So the “everything throws” rule is there to keep behavior predictable and safe when crossing the SwiftJavaScript boundary.
28+
So the “everything throws” rule is there to keep behavior predictable and safe when crossing the Swift-JavaScript boundary.

Sources/JavaScriptKit/Documentation.docc/Documentation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Check out the [examples](https://github.com/swiftwasm/JavaScriptKit/tree/main/Ex
7272
- <doc:Supported-Types>
7373
- <doc:BridgeJS-Configuration>
7474
- <doc:Ahead-of-Time-Code-Generation>
75+
- <doc:Unsupported-Features>
7576
- <doc:BridgeJS-Internals>
7677
- ``JS(namespace:enumStyle:)``
7778
- ``JSFunction(jsName:from:)``

0 commit comments

Comments
 (0)