aprender-test-js-gen-0.31.1 has been yanked.
probar-js-gen
NASA/DO-178B-grade Rust DSL for type-safe JavaScript generation.
Zero raw JavaScript. Zero manual editing. Zero defects.
Why This Exists
Raw JavaScript strings in Rust codebases are a liability:
- No Compiler Checks: Typos, syntax errors, reserved words pass silently
- No Immutability: Generated files can be manually edited, breaking invariants
- No Traceability: Changes to generated code are undetectable
This crate solves all three with a typed DSL, hash manifests, and property-based testing.
Features
| 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 |
Quick Start
use *;
// Build a JavaScript module
let module = new
.comment
.let_decl?
.const_decl?
.build;
// Generate JavaScript code
let js = generate;
// Write with manifest for immutability verification
write_with_manifest?;
// Later, verify the file wasn't tampered with
verify?;
Toyota Way Principles
This crate implements the Toyota Production System principles for software:
Jidoka (Automation with Human Touch)
- Stop the Line: Any validation failure halts generation immediately
- Andon: Error messages include regeneration instructions
- Poka-Yoke: Type system prevents invalid constructs
Genchi Genbutsu (Go and See)
- No Blind Trust: All generated code is verified
- Observable State: Manifest tracks generation metadata
Kaizen (Continuous Improvement)
- Property Tests: 1000+ random cases per property
- Mutation Testing: 85%+ mutation score required
Yokoten (Horizontal Deployment)
- Reusable DSL: Same patterns for Workers, Worklets, any JS context
Quality Guarantees
| 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% |
Run Quality Gates
# Unit + property tests
# Coverage
# Mutation testing
# Clippy (pedantic)
100-Point Falsification Checklist
See FALSIFICATION.md for the complete Popperian falsification checklist. Each of the 100 claims is:
- Testable: Has a concrete test
- Refutable: Can be proven false
- Independent: Orthogonal to other claims
Peer-Reviewed References
Formal Methods
- McKeeman, W.M. (1998) "Differential Testing for Software", Digital Technical Journal
- Claessen & Hughes (2000) "QuickCheck: A Lightweight Tool for Random Testing", ICFP
- DeMillo et al. (1978) "Hints on Test Data Selection", IEEE Computer
JavaScript Semantics
- Maffeis et al. (2008) "An Operational Semantics for JavaScript", APLAS
- Guha et al. (2010) "The Essence of JavaScript", ECOOP
- ECMA-262 (ES2022) Specification
Software Safety
- Leveson, N.G. (2012) "Engineering a Safer World", MIT Press
- RTCA DO-178C (2011) "Software Considerations in Airborne Systems"
- Holzmann, G.J. (2006) "The Power of 10", IEEE Computer
Hash Functions
- O'Connor et al. (2020) "BLAKE3: One Function, Fast Everywhere", RWC
Architecture
┌─────────────────────────────────────────────────────────────┐
│ 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 │
└─────────────────────────────────────────────────────────────┘
Forbidden Patterns
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 |
Use Cases
Web Workers
let module = new
.comment
.let_decl?
.stmt
.build;
let js = generate;
let errors = validate_worker_js;
assert!;
AudioWorklets
let class = new?
.extends?
.constructor
.method?
.build;
let module = new
.class
.register_processor?
.build;
let js = generate;
let errors = validate_worklet_js;
assert!;
License
MIT OR Apache-2.0
Part of the Aprender monorepo — 70 workspace crates.