Porffor

raw JSON →
0.61.13 verified Fri May 01 auth: no javascript

An experimental from-scratch AOT JavaScript/TypeScript compiler that compiles to WebAssembly or native binaries. Current version 0.61.13, with rapid development. Unlike JIT-based engines, it is fully ahead-of-time compiled with zero runtime prelude, and generates Wasm without using Binaryen. It supports limited JS features and is a research project not intended for production use. Key differentiators: custom Wasm binary generation, sub- and super-set of JavaScript, and ability to compile to C via its 2c sub-engine.

error Error: Unsupported syntax: ...
cause Porffor does not support the given JavaScript syntax
fix
Rewrite code to use only supported subset (e.g., no eval, no generators, limited async).
error TypeError: Porffor is not a constructor
cause Importing the package incorrectly (e.g., using CommonJS require)
fix
Use ESM import: import Porffor from 'porffor'
error Error: No parser was found for the given file type
cause Parser not installed or unsupported file extension
fix
Ensure acorn is installed, or specify a different parser with --parser.
gotcha Porffor supports only a limited subset of JavaScript. Many language features (e.g., classes, generators, full async) are not implemented or have bugs.
fix Check the source or benchmarks for supported patterns; avoid unsupported features.
breaking Versioning is unique: minor version equals Test262 pass percentage. No semantic versioning guarantees.
fix Pin to exact version if reproducibility is needed.
deprecated The `--parser` option default may change in future versions. Currently defaults to 'acorn'.
fix Explicitly specify parser via options if you rely on behavior of a specific parser.
gotcha Compiling to native binaries requires the experimental 2c sub-engine, which is unstable and may produce incorrect output.
fix Prefer compiling to Wasm; test native binaries thoroughly.
gotcha The programmatic API is not documented and may change without notice. Use the CLI for stability.
fix Use CLI (npx porf) instead of programmatic imports.
npm install porffor
yarn add porffor
pnpm add porffor

Demonstrates programmatic compilation of a JavaScript snippet to WebAssembly using Porffor's API.

import Porffor from 'porffor';

const compiler = new Porffor();
const code = 'console.log("Hello, world!");';
try {
  const wasmBytes = await compiler.compile(code, { target: 'wasm' });
  // wasmBytes is Uint8Array
  console.log('Compilation succeeded, wasm size:', wasmBytes.length);
} catch (err) {
  console.error('Compilation failed:', err);
}