Skip to content

Commit 363c269

Browse files
authored
docs(AGENTS.md): Add comprehensive example applications documentation to AGENTS.md (#12967)
1 parent 166f5cc commit 363c269

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

AGENTS.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,142 @@ pnpm test
9898

9999
Always run `just ready` as the last step after code has been committed to the repository.
100100

101+
## 🚀 Running Example Applications
102+
103+
The repository includes numerous example applications in the `examples/` directories of various crates. These examples demonstrate how to use different parts of the Oxc toolchain and serve as practical learning resources.
104+
105+
### Quick Start
106+
107+
Most examples follow this pattern:
108+
```bash
109+
# Create a test file (many examples default to "test.js")
110+
echo "console.log('Hello, World!');" > test.js
111+
112+
# Run an example
113+
cargo run -p <package_name> --example <example_name> [filename] [options]
114+
```
115+
116+
### Available Examples by Category
117+
118+
#### Parser Examples (`oxc_parser`)
119+
```bash
120+
# Basic JavaScript/TypeScript parsing with AST display
121+
cargo run -p oxc_parser --example parser [filename] [--ast] [--estree] [--comments]
122+
123+
# TypeScript JSX parsing demonstration
124+
cargo run -p oxc_parser --example parser_tsx
125+
126+
# Regular expression parsing within JavaScript
127+
cargo run -p oxc_parser --example regular_expression
128+
129+
# AST visitor pattern demonstration
130+
cargo run -p oxc_parser --example visitor [filename]
131+
```
132+
133+
#### Linter Examples (`oxc_linter`)
134+
```bash
135+
# Simple linter with basic rules (debugger detection, empty destructuring)
136+
cargo run -p oxc_linter --example linter [filename]
137+
```
138+
139+
#### Semantic Analysis Examples (`oxc_semantic`)
140+
```bash
141+
# Control flow graph generation and analysis
142+
cargo run -p oxc_semantic --example cfg [filename]
143+
144+
# Semantic analysis with symbol information
145+
cargo run -p oxc_semantic --example semantic [filename] [--symbols]
146+
```
147+
148+
#### Code Generation Examples (`oxc_codegen`)
149+
```bash
150+
# Code generation from AST
151+
cargo run -p oxc_codegen --example codegen [filename] [--minify] [--twice]
152+
153+
# Source map generation
154+
cargo run -p oxc_codegen --example sourcemap [filename]
155+
```
156+
157+
#### Transformer Examples (`oxc_transformer`)
158+
```bash
159+
# Code transformation with Babel compatibility
160+
cargo run -p oxc_transformer --example transformer [filename] [options]
161+
# Options: --babel-options <path>, --targets <targets>, --target <target>
162+
```
163+
164+
#### Minifier Examples (`oxc_minifier`)
165+
```bash
166+
# Dead code elimination
167+
cargo run -p oxc_minifier --example dce [filename] [--nospace] [--twice]
168+
169+
# Variable name mangling
170+
cargo run -p oxc_minifier --example mangler [filename] [options]
171+
172+
# Complete minification pipeline
173+
cargo run -p oxc_minifier --example minifier [filename] [options]
174+
```
175+
176+
#### Formatter Examples (`oxc_formatter`)
177+
```bash
178+
# Code formatting
179+
cargo run -p oxc_formatter --example formatter [filename]
180+
```
181+
182+
#### Isolated Declarations Examples (`oxc_isolated_declarations`)
183+
```bash
184+
# TypeScript isolated declarations generation
185+
cargo run -p oxc_isolated_declarations --example isolated_declarations [filename]
186+
```
187+
188+
#### Regular Expression Examples (`oxc_regular_expression`)
189+
```bash
190+
# Regular expression literal parsing
191+
cargo run -p oxc_regular_expression --example parse_literal
192+
193+
# Regular expression AST visitor
194+
cargo run -p oxc_regular_expression --example regex_visitor
195+
```
196+
197+
#### Complete Compiler Examples (`oxc`)
198+
```bash
199+
# Full compilation pipeline (parsing, semantic analysis, transformation, codegen)
200+
cargo run -p oxc --example compiler --features="full" [filename]
201+
```
202+
203+
### Example Usage Patterns
204+
205+
1. **File Input**: Most examples accept an optional filename parameter. If not provided, they default to `test.js`.
206+
207+
2. **Creating Test Files**: Create appropriate test files for different examples:
208+
```bash
209+
# For JavaScript examples
210+
echo "const x = 1; console.log(x);" > test.js
211+
212+
# For TypeScript examples
213+
echo "const x: number = 1; console.log(x);" > test.ts
214+
215+
# For JSX examples
216+
echo "const App = () => <div>Hello</div>;" > test.jsx
217+
```
218+
219+
3. **Development Workflow**: Use `just watch` for continuous development:
220+
```bash
221+
just watch "cargo run -p oxc_parser --example parser"
222+
```
223+
224+
4. **Special Requirements**:
225+
- The `oxc` compiler example requires `--features="full"`
226+
- Some examples have additional command-line options for different modes
227+
- Examples automatically detect file type from extension (`.js`, `.ts`, `.jsx`, `.tsx`)
228+
229+
### Tips for AI Development
230+
231+
- Use examples to understand how different Oxc components work together
232+
- Examples serve as integration tests for the APIs
233+
- Modify examples temporarily to experiment with different inputs
234+
- Examples demonstrate best practices for using the allocator pattern
235+
- Check example source code for detailed usage patterns and error handling
236+
101237
## 🧭 Code Navigation Tips
102238

103239
### Understanding the AST

0 commit comments

Comments
 (0)