| Crates.io | probar-js-gen |
| lib.rs | probar-js-gen |
| version | 1.0.0 |
| created_at | 2026-01-08 23:12:54.955355+00 |
| updated_at | 2026-01-08 23:12:54.955355+00 |
| description | NASA/DO-178B-grade Rust DSL for type-safe JavaScript generation |
| homepage | |
| repository | https://github.com/paiml/probar |
| max_upload_size | |
| id | 2031280 |
| size | 182,840 |
NASA/DO-178B-grade Rust DSL for type-safe JavaScript generation.
Zero raw JavaScript. Zero manual editing. Zero defects.
Raw JavaScript strings in Rust codebases are a liability:
This crate solves all three with a typed DSL, hash manifests, and property-based testing.
| Feature | Guarantee | Verification |
|---|---|---|
| Type Safety | Invalid JS is unrepresentable | Compile-time |
| Identifier Validation | Reserved words rejected | Runtime + Tests |
| Immutability | Blake3 hash manifests | verify() function |
| Determinism | Same input = same output | Property tests |
| No Forbidden Patterns | window, eval, etc. blocked | Static analysis |
use probar_js_gen::prelude::*;
// Build a JavaScript module
let module = JsModuleBuilder::new()
.comment("Generated by probar-js-gen - DO NOT EDIT")
.let_decl("x", Expr::num(42))?
.const_decl("msg", Expr::str("hello"))?
.build();
// Generate JavaScript code
let js = generate(&module);
// Write with manifest for immutability verification
write_with_manifest(
Path::new("./output.js"),
&js,
GenerationMetadata {
tool: "my-tool".to_string(),
version: "1.0.0".to_string(),
input_hash: "abc123".to_string(),
timestamp: "2024-01-01T00:00:00Z".to_string(),
regenerate_cmd: "my-tool gen".to_string(),
},
)?;
// Later, verify the file wasn't tampered with
verify(Path::new("./output.js"))?;
This crate implements the Toyota Production System principles for software:
| Metric | Minimum | Target |
|---|---|---|
| Test Coverage | 90% | 95% |
| Mutation Score | 85% | 90% |
| Property Tests | 1000 cases/property | 10000 |
| Clippy Warnings | 0 | 0 |
| Doc Coverage | 100% | 100% |
# Unit + property tests
cargo test
# Coverage
cargo llvm-cov --html
# Mutation testing
cargo mutants
# Clippy (pedantic)
cargo clippy -- -D warnings
See FALSIFICATION.md for the complete Popperian falsification checklist. Each of the 100 claims is:
┌─────────────────────────────────────────────────────────────┐
│ User Code │
│ │
│ JsModuleBuilder::new() │
│ .let_decl("x", Expr::num(42))? │
│ .build() │
└─────────────────────┬───────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ HIR (Type-Safe AST) │
│ │
│ JsModule { statements: [Stmt::Let { name, value }] } │
│ │
│ Validation: Identifier::new() rejects reserved words │
└─────────────────────┬───────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Code Generation │
│ │
│ generate(&module) → "let x = 42;" │
│ │
│ Deterministic: Same HIR → Same output (always) │
└─────────────────────┬───────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Manifest System │
│ │
│ write_with_manifest() → output.js + output.js.manifest │
│ verify() → Err if hash mismatch (file was edited!) │
│ │
│ Blake3 hash ensures no undetected modifications │
└─────────────────────────────────────────────────────────────┘
The validator rejects generated code containing these patterns:
| Pattern | Reason | Context |
|---|---|---|
window. |
Workers have no window | Worker |
document. |
Workers have no document | Worker |
importScripts |
Use dynamic import() |
Worker |
eval( |
Security risk | All |
Function( |
Security risk | All |
with( |
Deprecated | All |
__proto__ |
Prototype pollution | All |
let module = JsModuleBuilder::new()
.comment("Transcription Worker")
.let_decl("wasm", Expr::null())?
.stmt(Stmt::on_message(vec![
// Handle messages from main thread
]))
.build();
let js = generate(&module);
let errors = validator::validate_worker_js(&js);
assert!(errors.is_empty());
let class = JsClassBuilder::new("MyProcessor")?
.extends("AudioWorkletProcessor")?
.constructor(vec![])
.method("process", &["inputs", "outputs", "params"], vec![
Stmt::ret_val(Expr::bool(true)),
])?
.build();
let module = JsModuleBuilder::new()
.class(class)
.register_processor("my-processor", "MyProcessor")?
.build();
let js = generate(&module);
let errors = validator::validate_worklet_js(&js);
assert!(errors.is_empty());
MIT OR Apache-2.0