|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is the ReScript compiler repository - a robustly typed language that compiles to efficient and human-readable JavaScript. ReScript is built using OCaml and includes a complete toolchain with compiler, build system, syntax parser, and standard library. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +### Basic Development |
| 12 | +```bash |
| 13 | +# Build compiler and copy executables |
| 14 | +make |
| 15 | + |
| 16 | +# Build in watch mode |
| 17 | +make watch |
| 18 | + |
| 19 | +# Build everything including standard library |
| 20 | +make lib |
| 21 | + |
| 22 | +# Build artifacts and update artifact list |
| 23 | +make artifacts |
| 24 | +``` |
| 25 | + |
| 26 | +### Testing |
| 27 | +```bash |
| 28 | +# Run all tests |
| 29 | +make test |
| 30 | + |
| 31 | +# Run specific test types |
| 32 | +make test-syntax # Syntax parser tests |
| 33 | +make test-syntax-roundtrip # Roundtrip syntax tests |
| 34 | +make test-gentype # GenType tests |
| 35 | +make test-analysis # Analysis tests |
| 36 | +make test-tools # Tools tests |
| 37 | +make test-rewatch # Rewatch tests |
| 38 | + |
| 39 | +# Run single file test |
| 40 | +./cli/bsc.js myTestFile.res |
| 41 | + |
| 42 | +# View parse/typed trees for debugging |
| 43 | +./cli/bsc.js -dparsetree myTestFile.res |
| 44 | +./cli/bsc.js -dtypedtree myTestFile.res |
| 45 | +``` |
| 46 | + |
| 47 | +### Code Quality |
| 48 | +```bash |
| 49 | +# Format code |
| 50 | +make format |
| 51 | + |
| 52 | +# Check formatting |
| 53 | +make checkformat |
| 54 | + |
| 55 | +# Lint with Biome |
| 56 | +npm run check |
| 57 | +npm run check:all |
| 58 | + |
| 59 | +# TypeScript type checking |
| 60 | +npm run typecheck |
| 61 | +``` |
| 62 | + |
| 63 | +### Clean Operations |
| 64 | +```bash |
| 65 | +make clean # Clean OCaml build artifacts |
| 66 | +make clean-all # Clean everything including Rust/gentype |
| 67 | +``` |
| 68 | + |
| 69 | +## Compiler Architecture |
| 70 | + |
| 71 | +The ReScript compiler follows this high-level pipeline: |
| 72 | + |
| 73 | +``` |
| 74 | +ReScript Source (.res) |
| 75 | + ↓ (ReScript Parser - compiler/syntax/) |
| 76 | +Surface Syntax Tree |
| 77 | + ↓ (Frontend transformations - compiler/frontend/) |
| 78 | +Surface Syntax Tree |
| 79 | + ↓ (OCaml Type Checker - compiler/ml/) |
| 80 | +Typedtree |
| 81 | + ↓ (Lambda compilation - compiler/core/lam_*) |
| 82 | +Lambda IR |
| 83 | + ↓ (JS compilation - compiler/core/js_*) |
| 84 | +JS IR |
| 85 | + ↓ (JS output - compiler/core/js_dump*) |
| 86 | +JavaScript Code |
| 87 | +``` |
| 88 | + |
| 89 | +### Key Directories |
| 90 | + |
| 91 | +- **`compiler/syntax/`** - ReScript syntax parser (MIT licensed, separate from main LGPL) |
| 92 | +- **`compiler/frontend/`** - AST transformations, external FFI processing, built-in attributes |
| 93 | +- **`compiler/ml/`** - OCaml compiler infrastructure (type checker, typedtree, etc.) |
| 94 | +- **`compiler/core/`** - Core compilation: |
| 95 | + - `lam_*` files: Lambda IR compilation and optimization passes |
| 96 | + - `js_*` files: JavaScript IR and code generation |
| 97 | +- **`compiler/ext/`** - Extended utilities and data structures |
| 98 | +- **`compiler/bsb/`** - Build system implementation |
| 99 | +- **`compiler/gentype/`** - TypeScript generation |
| 100 | +- **`runtime/`** - ReScript standard library (written in ReScript) |
| 101 | +- **`lib/`** - Compiled JavaScript output of standard library |
| 102 | +- **`analysis/`** - Language server and tooling support |
| 103 | + |
| 104 | +### Build System Components |
| 105 | + |
| 106 | +- **`compiler/bsb_exe/`** - Main ReScript build tool entry point |
| 107 | +- **`compiler/bsc/`** - Compiler binary entry point |
| 108 | +- **`rewatch/`** - File watcher (written in Rust) |
| 109 | +- **`ninja/`** - Vendored Ninja build system |
| 110 | + |
| 111 | +## Development Setup Notes |
| 112 | + |
| 113 | +- Uses OCaml 5.3.0+ with opam for compiler development |
| 114 | +- Uses dune as build system with specific profiles (dev, release, browser) |
| 115 | +- Node.js 20+ required for JavaScript tooling |
| 116 | +- Rust toolchain needed for rewatch file watcher |
| 117 | +- Python ≤3.11 required for building ninja |
| 118 | + |
| 119 | +## Coding Conventions |
| 120 | + |
| 121 | +- **OCaml code**: snake_case (e.g., `to_string`) |
| 122 | +- **ReScript code**: camelCase (e.g., `toString`) |
| 123 | +- Use DCO sign-off for all commits: `Signed-Off-By: Your Name <email>` |
| 124 | + |
| 125 | +## Testing Strategy |
| 126 | + |
| 127 | +- **Mocha tests** (`tests/tests/`) - Runtime library unit tests |
| 128 | +- **Build system tests** (`tests/build_tests/`) - Integration tests |
| 129 | +- **OUnit tests** (`tests/ounit_tests/`) - Compiler unit tests |
| 130 | +- **Expectation tests** - Plain `.res` files that check compilation output |
| 131 | +- Always include appropriate tests with new features/changes |
| 132 | + |
| 133 | +## Performance Notes |
| 134 | + |
| 135 | +The compiler is designed for fast feedback loops and scales to large codebases. When making changes: |
| 136 | +- Avoid introducing meaningless symbols |
| 137 | +- Maintain readable JavaScript output |
| 138 | +- Consider compilation speed impact |
| 139 | +- Use appropriate optimization passes in the Lambda and JS IRs |
0 commit comments