watr

Light & fast WAT compiler
docs · demo
Usage
import watr, { compile, parse, print } from 'watr'
const binary = compile('(func (export "f") (result f64) (f64.const 1))', {
polyfill: false,
optimize: true
})
const module = new WebAssembly.Module(binary)
const { f } = new WebAssembly.Instance(module).exports
parse('(i32.const 42)')
print('(module(func(result i32)i32.const 42))')
const { add } = watr`(func (export "add") (param i32 i32) (result i32)
(i32.add (local.get 0) (local.get 1))
)`
add(2, 3)
const { test } = watr`(func (export "test") (call ${console.log} (i32.const 42)))`
test()
CLI
npx watr input.wat
npx watr input.wat -o out.wasm
npx watr input.wat --print
npx watr input.wat --minify
npx watr input.wat --optimize
npx watr input.wat --polyfill
Metrics
Used by
- jz – minimal static JS subset
ॐ