Skip to content

dy/jz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jz stability test

JZ is minimal modern functional JS subset that compiles to WebAssembly (WASM).
Think of it as tiny JavaScript to WASM compiler.

Reference

  • Numbers: 0.1, 1.2e+3, 0xabc, 0b101, 0o357
  • Strings: "abc", 'abc'
  • Values: true, false, null, NaN, Infinity, undefined
  • Access: a.b, a[b], a(b)
  • Arithmetic:+a, -a, a + b, a - b, a * b, a / b, a % b, a ** b
  • Comparison: a < b, a <= b, a > b, a >= b, a == b, a != b, a === b, a !== b
  • Bitwise: ~a, a & b, a ^ b, a | b, a << b, a >> b, a >>> b
  • Logic: !a, a && b, a || b, a ? b : c
  • Increments: a++, a--, ++a, --a
  • Assignment: a = b, a += b, a -= b, a *= b, a /= b, a %= b, a **= b, a <<= b, a >>= b, a >>>= b
  • Logical Assignment: a ||= b, a &&= b, a ??= b
  • Arrays: [a, b], ...a (no objects yet)
  • Declarations: let a, b, const c (no var)
  • Functions: (a, b) => c (no function keyword)
  • Comments: // foo, /* bar */
  • Control Flow: if (a) {...} else if (b) {...} else {}, for (a;b;c) {...}, while (a) {...}
  • Exceptions: try {...} catch (e) {...}
  • Modules: import, export

Usage

import jz from 'jz'

// compile JS (function multiplying 2 numbers) - it returns WASM buffer
const buf = jz(`export x = (a, b) => a * b`)

// compile WASM module and create an instance
const mod = new WebAssembly.Module(buf)
const { exports: { x } } = new WebAssembly.Instance(mod, { ...imports })

// use exported WASM function
x(2,3) === 6

Coming soon: CLI with jz a.js → a.wasm and batch compilation.

Examples

Coming soon.

Why?

JS has grown complex with legacy features (var, OOP) and niche additions (generators, async loops, etc).
JZ is inspired by floatbeats/bytebeats, it focuses on a minimal, modern, essential subset that ties to WebAssembly features.

  • No classes/prototypes – use functions & closures.
  • No old syntax – use modern ES5+.
  • No regrets – drop undefined.
  • No computed props - objects are structs.
  • No autosemicolons - keep syntax ordered.
  • No async – keep code plain & simple.

Goals

  • lightweight – embed anywhere, from websites to microcontrollers.
  • fast – compiles to WASM faster than eval parses.
  • tiny WASM output – no runtime, no heap, no wrappers.
  • seamless JS integration – export / import, same func signatures.

Why not porf?

Porffor is brilliant, but aligns to TC39 and hesitant on full WASM. JZ stays small and flexible.

AssemblyScript is built on TypeScript, while JZ stays pure JS.

Why not piezo?

Piezo offers extra features like groups, pipes, units, ranges and extra operators. It might become a solid niche language, but takes time for R&D.
JZ is possible first step for it.

Why jz?

JZ stands for JavasSript Zero – a return to core, stripped to essentials. Also jazzy vibe.

🕉

About

Minimal JS subset compiling to WASM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published