watr v5.10.0

Compile WAT to WASM

WebAssembly text to binary WASM (wat2wasm) in plain JavaScript. For compilers, build tools, test suites and playgrounds.

$npm i watr repl
input.wat
output.wasm41 bytes

Spec-complete

Full spec and features. 60,380 official testsuite assertions.

Portable

ESM: no .wasm, no Emscripten. Bundlers, workers and blob URLs load as any other import.

Lightweight

44 KB minified, 14 KB gzipped, zero dependencies.

01

Performance

CompilerSizeThroughput
watr44 KB3,123 op/s
spec/wast.js216 KB1,509 op/s
wabt282 KB859 op/s
binaryen1,100 KB473 op/s
wat-compiler152 KB + wabt355 op/s
02

API

import watr from 'watr'

const { test } = watr`(func (export "test") (call ${console.log} (i32.const 42)))`
test()  // 42

parse

parse('(i32.const 42)')
// ['i32.const', '42']

print

print(src)
// indented, one op per line

minify

print(src, { indent: false, newline: false })
// (module(func(result i32)(i32.const 42)))

polyfill

import polyfill from 'watr/polyfill'
compile(polyfill(src))

API reference.

03

Optimizer

OptimizerTotal sizeBatchFootprint
watr/optimize19,734 B110 ms in-process149 KB
wasm-opt -Oz19,852 B990 ms via CLI1,100 KB
wasm-opt -O322,302 Bnot measured1,100 KB

Optimize docs.

04

Conformance

spec testsuite: passing features: phase 2–5

05

CLI

npx watr input.wat               # input.wasm
npx watr input.wat -o out.wasm   # custom output
npx watr input.wat --print       # pretty-print
npx watr input.wat --minify      # minify
npx watr input.wat --optimize    # fold, treeshake, inline, coalesce
npx watr input.wat --polyfill    # newer features to MVP
npx watr input.wat --source-map  # + input.wasm.map from ;;@ comments
06

Used by