Comptime.ts: compile-time expressions for TypeScript
21 days ago
- #compile-time
- #TypeScript
- #optimization
- comptime.ts is a TypeScript compiler for compile-time evaluation of expressions marked with `comptime`.
- Inspired by Bun macros and Zig comptime, it optimizes code by moving computations from runtime to compile time.
- Supports various expressions, including function calls, tagged template literals, and imported constants, provided they are JSON-serializable.
- Installation is straightforward with npm, pnpm, or Bun, and it integrates with Vite and Bun bundler.
- Features include forcing comptime evaluation, resolving promises at compile time, and deferring code execution post-evaluation.
- Best practices recommend using comptime for constants and static content, avoiding complex runtime logic.
- Troubleshooting tips address common issues like unexpected compilation results and slow build times.
- The project encourages support through starring, sharing, or sponsoring, and is licensed under MIT.