jsx-generator
JSX code generator with formatting, optimization, and minification capabilities.
Features
- Code Emission: Convert AST tokens to readable JSX code
- Multiple Formatters: KandR and Allman styles
- Minification: Remove unnecessary whitespace and comments
- Optimization: Constant folding and dead code elimination
- Configurable: Control indentation, semicolons, and more
- No
unsafe: 100% safe Rust
Quick Start
use ;
use Token;
// Create emitter
let mut emitter = default;
// Emit token to code
let token = StringLiteral;
let code = emitter.emit_token?;
println!; // "hello"
// Format code
let formatter = default;
let formatted = formatter.format?;
Configuration
use ;
let config = EmitterConfig ;
let emitter = new;
Formatting Styles
KandR Style (Default)
Allman Style
Optimization
use CodeOptimizer;
let optimizer = default;
// Constant folding: 2 + 3 → 5
let result = optimizer.fold_numeric_operation?;
// Dead code elimination after return
let optimized = optimizer.optimize_tokens?;
Examples
See examples/emit_code.rs for complete working example.
Performance
- 1,000 tokens: ~8ms emission + ~3ms formatting
- Single pass: Linear O(n) complexity
Contributing
Contributions welcome! See CONTRIBUTING.md.
License
Licensed under the MIT License. See LICENSE file.
Related
- jsxbin-parser - Binary parsing
- analyzer - Code analysis