-
-
Notifications
You must be signed in to change notification settings - Fork 722
Add comprehensive example applications documentation to AGENTS.md #12967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -98,6 +98,142 @@ pnpm test | |||||
|
|
||||||
| Always run `just ready` as the last step after code has been committed to the repository. | ||||||
|
|
||||||
| ## π Running Example Applications | ||||||
|
|
||||||
| 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. | ||||||
|
|
||||||
| ### Quick Start | ||||||
|
|
||||||
| Most examples follow this pattern: | ||||||
| ```bash | ||||||
| # Create a test file (many examples default to "test.js") | ||||||
| echo "console.log('Hello, World!');" > test.js | ||||||
|
|
||||||
| # Run an example | ||||||
| cargo run -p <package_name> --example <example_name> [filename] [options] | ||||||
| ``` | ||||||
|
|
||||||
| ### Available Examples by Category | ||||||
|
|
||||||
| #### Parser Examples (`oxc_parser`) | ||||||
| ```bash | ||||||
| # Basic JavaScript/TypeScript parsing with AST display | ||||||
| cargo run -p oxc_parser --example parser [filename] [--ast] [--estree] [--comments] | ||||||
|
|
||||||
| # TypeScript JSX parsing demonstration | ||||||
| cargo run -p oxc_parser --example parser_tsx | ||||||
|
|
||||||
| # Regular expression parsing within JavaScript | ||||||
| cargo run -p oxc_parser --example regular_expression | ||||||
|
|
||||||
| # AST visitor pattern demonstration | ||||||
| cargo run -p oxc_parser --example visitor [filename] | ||||||
| ``` | ||||||
|
|
||||||
| #### Linter Examples (`oxc_linter`) | ||||||
| ```bash | ||||||
| # Simple linter with basic rules (debugger detection, empty destructuring) | ||||||
| cargo run -p oxc_linter --example linter [filename] | ||||||
| ``` | ||||||
|
|
||||||
| #### Semantic Analysis Examples (`oxc_semantic`) | ||||||
| ```bash | ||||||
| # Control flow graph generation and analysis | ||||||
| cargo run -p oxc_semantic --example cfg [filename] | ||||||
|
|
||||||
| # Semantic analysis with symbol information | ||||||
| cargo run -p oxc_semantic --example semantic [filename] [--symbols] | ||||||
| ``` | ||||||
|
|
||||||
| #### Code Generation Examples (`oxc_codegen`) | ||||||
| ```bash | ||||||
| # Code generation from AST | ||||||
| cargo run -p oxc_codegen --example codegen [filename] [--minify] [--twice] | ||||||
|
|
||||||
| # Source map generation | ||||||
| cargo run -p oxc_codegen --example sourcemap [filename] | ||||||
| ``` | ||||||
|
|
||||||
| #### Transformer Examples (`oxc_transformer`) | ||||||
| ```bash | ||||||
| # Code transformation with Babel compatibility | ||||||
| cargo run -p oxc_transformer --example transformer [filename] [options] | ||||||
| # Options: --babel-options <path>, --targets <targets>, --target <target> | ||||||
| ``` | ||||||
|
|
||||||
| #### Minifier Examples (`oxc_minifier`) | ||||||
| ```bash | ||||||
| # Dead code elimination | ||||||
| cargo run -p oxc_minifier --example dce [filename] [--nospace] [--twice] | ||||||
|
|
||||||
| # Variable name mangling | ||||||
| cargo run -p oxc_minifier --example mangler [filename] [options] | ||||||
|
|
||||||
| # Complete minification pipeline | ||||||
| cargo run -p oxc_minifier --example minifier [filename] [options] | ||||||
| ``` | ||||||
|
|
||||||
| #### Formatter Examples (`oxc_formatter`) | ||||||
| ```bash | ||||||
| # Code formatting | ||||||
| cargo run -p oxc_formatter --example formatter [filename] | ||||||
| ``` | ||||||
|
|
||||||
| #### Isolated Declarations Examples (`oxc_isolated_declarations`) | ||||||
| ```bash | ||||||
| # TypeScript isolated declarations generation | ||||||
| cargo run -p oxc_isolated_declarations --example isolated_declarations [filename] | ||||||
| ``` | ||||||
|
|
||||||
| #### Regular Expression Examples (`oxc_regular_expression`) | ||||||
| ```bash | ||||||
| # Regular expression literal parsing | ||||||
| cargo run -p oxc_regular_expression --example parse_literal | ||||||
|
|
||||||
| # Regular expression AST visitor | ||||||
| cargo run -p oxc_regular_expression --example regex_visitor | ||||||
| ``` | ||||||
|
|
||||||
| #### Complete Compiler Examples (`oxc`) | ||||||
| ```bash | ||||||
| # Full compilation pipeline (parsing, semantic analysis, transformation, codegen) | ||||||
| cargo run -p oxc --example compiler --features="full" [filename] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Cargo features flag syntax is incorrect. It should be either # Correct options:
cargo run -p oxc --example compiler --features "full" [filename]
# or
cargo run -p oxc --example compiler --features=full [filename]
Suggested change
Spotted by Diamond |
||||||
| ``` | ||||||
|
|
||||||
| ### Example Usage Patterns | ||||||
|
|
||||||
| 1. **File Input**: Most examples accept an optional filename parameter. If not provided, they default to `test.js`. | ||||||
|
|
||||||
| 2. **Creating Test Files**: Create appropriate test files for different examples: | ||||||
| ```bash | ||||||
| # For JavaScript examples | ||||||
| echo "const x = 1; console.log(x);" > test.js | ||||||
|
|
||||||
| # For TypeScript examples | ||||||
|
||||||
| # For TypeScript examples | |
| # For TypeScript examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra trailing whitespace after 'demonstration'. Remove the trailing space.