You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+127Lines changed: 127 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -464,6 +464,133 @@ See [schema.json](schema.json) for a JSON Schema of the output.
464
464
```
465
465
</details>
466
466
467
+
## Parsing Swift files with SwiftSyntax via WebAssembly (WASI)
468
+
469
+
If your project includes Swift code, you can parse it with full-fidelity **SwiftSyntax** instead of brittle regular expressions. Thanks to the official Swift WASI SDK this works completely inside a Node.js environment—no native Swift toolchain is required at runtime.
470
+
471
+
Below is a minimal, end-to-end recipe you can drop into your build docs or copy-paste into a README. It turns a tiny SwiftSyntax-based CLI into a `.wasm` module and shows how to execute it from JavaScript.
472
+
473
+
---
474
+
475
+
### 1. Set up a Swift toolchain that can target WASM
476
+
477
+
1. Install the latest Swift **development snapshot***and* the matching **Swift SDK for WASI** (one-liner provided on the [Swift downloads page](https://www.swift.org/download/)).
478
+
2. Verify the SDK ID:
479
+
480
+
```sh
481
+
swift sdk list # e.g. swift-6.2-20250720_wasm
482
+
```
483
+
3. Whenever you build, pass `--swift-sdk <id>` (or `--triple wasm32-unknown-wasi` if you prefer). The [official guide](https://www.swift.org/getting-started) shows the exact commands.
wasi.start(instance); // prints AST (or your JSON) to stdout
571
+
```
572
+
573
+
Run it:
574
+
575
+
```sh
576
+
node runner.js ./Example.swift > ast.json
577
+
```
578
+
579
+
---
580
+
581
+
### 5. Consume from your NPM package
582
+
583
+
Wrap the call above in a helper (e.g. `parseSwift(sourcePath)`), capture `stdout`, and feed the JSON into your existing JS analysis pipeline—exactly like we already do with Pyodide or the Ruby/Python/Go WASM binaries.
584
+
585
+
---
586
+
587
+
#### Why this works
588
+
***SwiftSyntax** itself is pure Swift → the Swift WASI SDK compiles it without native Apple frameworks.
589
+
***WASI** provides a portable POSIX-ish layer, so the wasm module runs unchanged on Node, Wasmer, or Wasmtime.
590
+
* The approach keeps Swift-side parsing isolated and lets your JS orchestrate everything else.
591
+
592
+
> **TL;DR** Install the Swift WASI SDK, write a ~30-line SwiftSyntax CLI, `swift build --swift-sdk …`, then load the resulting `.wasm` through Node’s `wasi` API and capture its output.
593
+
467
594
468
595
## Contribute
469
596
We're actively improving this package. Found a bug? Have a feature request? Open an issue or submit a pull request!
0 commit comments