Skip to main content
The default command compiles and executes JavaScript or TypeScript files using Porffor’s AOT compiler.

Usage

porf [flags] path/to/script.js [...args]
You can optionally use the explicit run command:
porf run [flags] path/to/script.js [...args]

Examples

porf script.js

Execution Options

--no-run
flag
Compile without executing (useful for checking compilation errors)
-e, --eval
string
Evaluate JavaScript expression instead of reading from file
porf -e "console.log('Hello, World!')"
-p, --print
string
Evaluate expression and print the result
porf -p "2 + 2"  # Outputs: 4
porf -p "Math.sqrt(16)"  # Outputs: 4

Source Options

path/to/script.js
string
required
Path to JavaScript or TypeScript file to execute
https://...
string
URL to JavaScript file (HTTPS only)
porf https://example.com/script.js

Performance Flags

-t
flag
Display timing information after executionShows:
  • Total compilation + execution time
  • Execution time only
-b
flag
Display compiled Wasm binary size
porf -b script.js
# Outputs: wasm size: 1234 bytes

Common Flags

All global flags are supported:
  • -On: Optimization level
  • -d: Debug mode
  • --module: Parse as ES module
  • --parse-types: Enable TypeScript parsing
  • --opt-types: Use type hints for optimization

Output Examples

$ porf hello.js
Hello, World!

Script Arguments

Pass arguments to your script after the filename:
porf script.js arg1 arg2 --flag value
Access them in your code via process.argv:
script.js
// process.argv[0] is 'porf'
// process.argv[1] is 'script.js'
// process.argv[2] is 'arg1'
console.log(process.argv.slice(2));

Error Handling

Errors are displayed differently based on debug mode:
$ porf script.js
ReferenceError: foo is not defined

TypeScript Support

porf -t script.ts
Porffor parses TypeScript syntax but does not perform type checking. Type annotations can be used as optimization hints with --opt-types.

Module Support

Parse file as ES module:
porf --module script.js

Remote Execution

Execute JavaScript from HTTPS URLs:
porf https://example.com/script.js
Only HTTPS URLs are supported for security. The script is downloaded and executed without confirmation.

Performance Tips

  1. Use optimization flags: -O2 or -O3 for better runtime performance
  2. Enable type hints: --opt-types with TypeScript annotations
  3. Profile first: Use porf profile to identify bottlenecks
  4. Consider native: For maximum performance, compile to native binary

Limitations

Current limitations when running JavaScript:
  • Limited async support (Promise and await have known bugs)
  • No variables between scopes (except args and globals)
  • No eval() or Function() (AOT compilation)
  • Limited standard library support

Profile

Analyze performance bottlenecks

Debug

Interactive debugging

Wasm

Compile to WebAssembly

Native

Compile to native binary

Build docs developers (and LLMs) love