Skip to content

Commit a080925

Browse files
committed
feat: add JavaScript bindings generation and transpilation for WIT components
- Implemented `generateJsBindings` and `generateJsBindingsFromPath` for generating TypeScript bindings from WIT content. - Added `transpileJsHost` and `transpileJsHostFromPath` for transpiling WebAssembly components into JavaScript host modules. - Introduced interfaces and types for binding options and results. - Created tests for guest and host bindings generation, including complex WIT definitions and command contributions. - Ensured backward compatibility with deprecated aliases for guest and host bindings. - Implemented edge case tests for WitFormatter to ensure proper formatting of various input scenarios. - Added comprehensive tests for WitSyntaxValidator, covering error parsing and diagnostic creation. - Introduced file-based tests for WASM detection utilities to validate header reading and component identification. - Enhanced vitest configuration to include coverage reporting for better test insights. - Added a new command for running unit tests with coverage. Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent 892265a commit a080925

39 files changed

+4661
-1460
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [ubuntu-latest, windows-latest, macos-latest]
16-
node-version: [20, 22, 24]
16+
node-version: [22, 24]
1717
runs-on: ${{ matrix.os }}
1818
permissions:
1919
contents: read
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup Rust toolchain
3131
uses: dtolnay/rust-toolchain@stable
3232
with:
33-
targets: wasm32-unknown-unknown
33+
targets: wasm32-unknown-unknown,wasm32-wasip2
3434

3535
- name: Cache Rust dependencies
3636
uses: Swatinem/rust-cache@v2

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ typings/
7272
# Typescript Output
7373
dist/
7474

75+
# Rust build artifacts
76+
samples/target/
77+
7578
# VSCode extension development
7679
.vscode-test/
7780
*.vsix
@@ -80,3 +83,6 @@ dist/
8083
types/
8184
out/
8285
tmp/
86+
87+
# Test coverage
88+
coverage/

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dist/
1616
*.vsix
1717
wit-bindgen-wasm/pkg/
1818
wit-bindgen-wasm/target/
19+
samples/target/
1920

2021
# Test snapshots (these are auto-generated and shouldn't be manually formatted)
2122
*.snap

.vscode/launch.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "0.2.0",
77
"configurations": [
88
{
9-
"name": "Extension",
9+
"name": "default",
1010
"type": "extensionHost",
1111
"request": "launch",
1212
"runtimeExecutable": "${execPath}",
@@ -15,6 +15,17 @@
1515
"--extensionDevelopmentPath=${workspaceFolder}",
1616
"${workspaceRoot}/tests/grammar"
1717
]
18+
},
19+
{
20+
"name": "samples",
21+
"type": "extensionHost",
22+
"request": "launch",
23+
"runtimeExecutable": "${execPath}",
24+
"args": [
25+
"--disable-extensions",
26+
"--extensionDevelopmentPath=${workspaceFolder}",
27+
"${workspaceRoot}/samples"
28+
]
1829
}
1930
]
2031
}

README.md

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ _A comprehensive Visual Studio Code extension for WebAssembly Interface Type (WI
88
- 🎨 Full syntax highlighting and code completion
99
- ✅ Real-time syntax validation with detailed error diagnostics
1010
- 🔧 Automatic code formatting
11-
- 🌐 Generate bindings for Rust, C, C++, C#, Go, MoonBit, and Markdown
11+
- 🌐 Generate guest bindings for Rust, C, C++, C#, Go, MoonBit, and JavaScript
12+
- 🧱 Generate JavaScript host bindings from WIT or `.wasm` components
13+
- 📚 Generate Markdown documentation from WIT definitions
1214
- 🧩 WebAssembly component detection and WIT extraction
1315
- 📝 Context menu integration for quick access to tools
1416

@@ -50,19 +52,27 @@ Format WIT files with a single command:
5052

5153
Generate language bindings directly from WIT files or WebAssembly components:
5254

53-
#### Supported Languages
55+
#### Guest Bindings
5456
- **Rust**: Generate idiomatic Rust bindings with `wit-bindgen`
5557
- **C**: Generate C bindings for C projects
5658
- **C++**: Generate C++ bindings
5759
- **C#**: Generate C# bindings for .NET projects
5860
- **Go**: Generate Go bindings
5961
- **MoonBit**: Generate MoonBit bindings
62+
- **JavaScript**: Generate JavaScript/TypeScript guest-side bindings
63+
64+
#### Host Bindings
65+
- **JavaScript**: Generate host-side JavaScript output
66+
- For `.wit` files, generates host-oriented TypeScript declarations
67+
- For `.wasm` components, transpiles to runnable JavaScript host modules
68+
69+
#### Documentation Output
6070
- **Markdown**: Generate documentation in Markdown format
6171

6272
#### Binding Generation Features
63-
- **Context Menu Integration**: Right-click on `.wit` or `.wasm` files to generate bindings
64-
- **Multiple Targets**: Generate bindings for multiple languages at once
65-
- **Output to Folder**: Automatically creates language-specific output directories
73+
- **Context Menu Integration**: Right-click on `.wit` or `.wasm` files to generate outputs
74+
- **Structured Menus**: Separate submenus for guest bindings, host bindings, and documentation
75+
- **Output to Folder**: Preserves generated relative folder layout safely
6676
- **Progress Feedback**: Visual feedback during generation process
6777

6878
### WebAssembly Component Support
@@ -88,12 +98,16 @@ Right-click on files in the editor or Explorer for quick access to:
8898
**For `.wit` files:**
8999
- Check WIT Syntax
90100
- Format Document
91-
- Generate Bindings (with language submenu)
101+
- Generate Guest Bindings (submenu)
102+
- Generate Host Bindings (submenu)
103+
- Generate Documentation (submenu)
92104

93105
**For `.wasm` component files:**
94106
- Extract WIT
95107
- Extract Core Wasm
96-
- Generate Bindings (with language submenu)
108+
- Generate Guest Bindings (submenu)
109+
- Generate Host Bindings (submenu)
110+
- Generate Documentation (submenu)
97111

98112
## Available Commands
99113

@@ -115,31 +129,36 @@ Access these commands via the Command Palette (`Ctrl+Shift+P` or `Cmd+Shift+P`):
115129
- Applies consistent styling and indentation
116130

117131
### Binding Generation Commands
118-
- **WIT: Generate Language Bindings**
119-
- Opens a language selection menu
120-
- Available for `.wit` files and WebAssembly components
121-
122132
- **WIT: Generate Rust Bindings**
123-
- Generates Rust bindings using `wit-bindgen`
133+
- Generates Rust guest bindings using `wit-bindgen`
124134

125135
- **WIT: Generate C Bindings**
126-
- Generates C bindings for C projects
136+
- Generates C guest bindings for C projects
127137

128138
- **WIT: Generate C++ Bindings**
129-
- Generates C++ bindings
139+
- Generates C++ guest bindings
130140

131141
- **WIT: Generate C# Bindings**
132-
- Generates C# bindings for .NET projects
142+
- Generates C# guest bindings for .NET projects
133143

134144
- **WIT: Generate Go Bindings**
135-
- Generates Go bindings
145+
- Generates Go guest bindings
136146

137147
- **WIT: Generate MoonBit Bindings**
138-
- Generates MoonBit bindings
148+
- Generates MoonBit guest bindings
149+
150+
- **WIT: Generate JavaScript Bindings (Guest)**
151+
- Generates JavaScript/TypeScript guest bindings from `.wit` or extracted component WIT
152+
153+
- **WIT: Generate JavaScript Bindings (Host)**
154+
- Generates host-side JavaScript output
155+
- Uses host type generation for `.wit`, and component transpilation for `.wasm`
139156

140157
- **WIT: Generate Markdown Documentation**
141158
- Generates Markdown documentation from WIT definitions
142159

160+
> Note: legacy command IDs for `wit-idl.generateBindings*` are still supported as deprecated aliases for backward compatibility.
161+
143162
### WebAssembly Component Commands
144163
- **WIT: Extract WIT**
145164
- Extracts WIT definitions from a WebAssembly component file
@@ -248,6 +267,9 @@ npm test
248267
# Run unit tests only
249268
npm run test-unit
250269

270+
# Run unit tests with coverage report
271+
npm run test-unit-coverage
272+
251273
# Run tests in watch mode
252274
npm run test-unit-watch
253275
```

images/component-view-menu.png

40.3 KB
Loading

images/editor-menu.png

-4.33 KB
Loading

0 commit comments

Comments
 (0)