diff --git a/crates/oxc/examples/compiler.rs b/crates/oxc/examples/compiler.rs index fe2596ac1c00d..b0fe763612562 100644 --- a/crates/oxc/examples/compiler.rs +++ b/crates/oxc/examples/compiler.rs @@ -1,4 +1,15 @@ #![expect(clippy::print_stdout)] +//! # Complete Compiler Example +//! +//! This example demonstrates the complete Oxc compilation pipeline including +//! parsing, semantic analysis, transformation, and code generation. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc --example compiler --features="full" [filename] +//! ``` use std::{env, io, path::Path}; @@ -10,12 +21,14 @@ use oxc::{Compiler, span::SourceType}; // * `cargo run -p oxc --example compiler --features="full"` // * `just watch 'run -p oxc --example compiler --features="full"'` +/// Run the complete Oxc compilation pipeline on a JavaScript/TypeScript file fn main() -> io::Result<()> { let name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string()); let path = Path::new(&name); let source_text = std::fs::read_to_string(path)?; let source_type = SourceType::from_path(path).unwrap(); + // Execute the full compilation pipeline match Compiler::default().execute(&source_text, source_type, path) { Ok(printed) => { println!("{printed}"); diff --git a/crates/oxc_codegen/examples/codegen.rs b/crates/oxc_codegen/examples/codegen.rs index 697ff661ad207..c942b697ac53d 100644 --- a/crates/oxc_codegen/examples/codegen.rs +++ b/crates/oxc_codegen/examples/codegen.rs @@ -1,4 +1,21 @@ #![expect(clippy::print_stdout)] +//! # Code Generation Example +//! +//! This example demonstrates how to use the Oxc code generator to convert an AST +//! back into JavaScript code. It supports minification and idempotency testing. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_codegen --example codegen [filename] [--minify] [--twice] +//! ``` +//! +//! ## Options +//! +//! - `--minify`: Generate minified output +//! - `--twice`: Test idempotency by parsing and generating twice + use std::path::Path; use oxc_allocator::Allocator; @@ -13,6 +30,7 @@ use pico_args::Arguments; // run `cargo run -p oxc_codegen --example codegen` // or `cargo watch -x "run -p oxc_codegen --example codegen"` +/// Demonstrate code generation with optional minification and idempotency testing fn main() -> std::io::Result<()> { let mut args = Arguments::from_env(); @@ -25,6 +43,7 @@ fn main() -> std::io::Result<()> { let source_type = SourceType::from_path(path).unwrap(); let mut allocator = Allocator::default(); + // First round: parse and generate let printed = { let program = parse(&allocator, &source_text, source_type); codegen(&program, minify) @@ -32,6 +51,7 @@ fn main() -> std::io::Result<()> { println!("First time:"); println!("{printed}"); + // Optional second round to test idempotency if twice { // Reset the allocator as we don't need the first AST any more allocator.reset(); @@ -48,6 +68,7 @@ fn main() -> std::io::Result<()> { Ok(()) } +/// Parse JavaScript/TypeScript source code into an AST fn parse<'a>( allocator: &'a Allocator, source_text: &'a str, @@ -65,6 +86,7 @@ fn parse<'a>( ret.program } +/// Generate JavaScript code from an AST fn codegen(program: &Program<'_>, minify: bool) -> String { Codegen::new() .with_options(if minify { CodegenOptions::minify() } else { CodegenOptions::default() }) diff --git a/crates/oxc_codegen/examples/sourcemap.rs b/crates/oxc_codegen/examples/sourcemap.rs index 51a9b208067da..37a4f3c4fc465 100644 --- a/crates/oxc_codegen/examples/sourcemap.rs +++ b/crates/oxc_codegen/examples/sourcemap.rs @@ -1,4 +1,16 @@ #![expect(clippy::print_stdout)] +//! # Source Map Generation Example +//! +//! This example demonstrates how to generate source maps alongside JavaScript code. +//! It generates a visualization URL for inspecting the source map. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_codegen --example sourcemap [filename] +//! ``` + use std::{env, path::Path}; use base64::{Engine, prelude::BASE64_STANDARD}; @@ -11,6 +23,7 @@ use oxc_span::SourceType; // 1. create a `test.js` // 2. run `cargo run -p oxc_codegen --example sourcemap` +/// Generate source maps and provide a visualization URL fn main() -> std::io::Result<()> { let name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string()); let path = Path::new(&name); @@ -19,6 +32,7 @@ fn main() -> std::io::Result<()> { let allocator = Allocator::default(); let ret = Parser::new(&allocator, &source_text, source_type).parse(); + // Handle parsing errors if !ret.errors.is_empty() { for error in ret.errors { let error = error.with_source_code(source_text.clone()); @@ -27,6 +41,7 @@ fn main() -> std::io::Result<()> { return Ok(()); } + // Generate code with source map let CodegenReturn { code, map, .. } = Codegen::new() .with_options(CodegenOptions { source_map_path: Some(path.to_path_buf()), @@ -34,6 +49,7 @@ fn main() -> std::io::Result<()> { }) .build(&ret.program); + // Create visualization URL if source map was generated if let Some(source_map) = map { let result = source_map.to_json_string(); let hash = diff --git a/crates/oxc_formatter/examples/formatter.rs b/crates/oxc_formatter/examples/formatter.rs index 7529da96f079a..073b01351b8de 100644 --- a/crates/oxc_formatter/examples/formatter.rs +++ b/crates/oxc_formatter/examples/formatter.rs @@ -1,4 +1,14 @@ #![expect(clippy::print_stdout)] +//! # Formatter Example +//! +//! This example demonstrates how to use the Oxc formatter to format JavaScript and TypeScript code. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_formatter --example formatter [filename] +//! ``` use std::{fs, path::Path}; @@ -8,14 +18,18 @@ use oxc_parser::{ParseOptions, Parser}; use oxc_span::SourceType; use pico_args::Arguments; +/// Format a JavaScript or TypeScript file fn main() -> Result<(), String> { let mut args = Arguments::from_env(); let name = args.free_from_str().unwrap_or_else(|_| "test.js".to_string()); + // Read source file let path = Path::new(&name); let source_text = fs::read_to_string(path).map_err(|_| format!("Missing '{name}'"))?; let source_type = SourceType::from_path(path).unwrap(); let allocator = Allocator::new(); + + // Parse the source code let ret = Parser::new(&allocator, &source_text, source_type) .with_options(ParseOptions { preserve_parens: false, @@ -24,12 +38,14 @@ fn main() -> Result<(), String> { }) .parse(); + // Report any parsing errors for error in ret.errors { let error = error.with_source_code(source_text.clone()); println!("{error:?}"); println!("Parsed with Errors."); } + // Format the parsed code let options = FormatOptions::default(); let code = Formatter::new(&allocator, options).build(&ret.program); diff --git a/crates/oxc_isolated_declarations/examples/isolated_declarations.rs b/crates/oxc_isolated_declarations/examples/isolated_declarations.rs index d93add9a4378e..fba9ae20e64ea 100644 --- a/crates/oxc_isolated_declarations/examples/isolated_declarations.rs +++ b/crates/oxc_isolated_declarations/examples/isolated_declarations.rs @@ -1,4 +1,16 @@ #![expect(clippy::print_stdout)] +//! # Isolated Declarations Example +//! +//! This example demonstrates how to generate TypeScript declaration files (.d.ts) +//! from TypeScript source code using isolated declarations. +//! +//! ## Usage +//! +//! Create a `test.ts` file and run: +//! ```bash +//! cargo run -p oxc_isolated_declarations --example isolated_declarations [filename] +//! ``` + use std::{env, path::Path}; use oxc_allocator::Allocator; @@ -12,6 +24,7 @@ use oxc_span::SourceType; // run `cargo run -p oxc_isolated_declarations --example isolated_declarations` // or `just example isolated_declarations` +/// Generate TypeScript declaration files from TypeScript source fn main() -> std::io::Result<()> { let name = env::args().nth(1).unwrap_or_else(|| "test.ts".to_string()); let path = Path::new(&name); diff --git a/crates/oxc_linter/examples/linter.rs b/crates/oxc_linter/examples/linter.rs index 690b8caea2f4f..e9a4e4099d7c4 100644 --- a/crates/oxc_linter/examples/linter.rs +++ b/crates/oxc_linter/examples/linter.rs @@ -1,5 +1,15 @@ #![expect(clippy::print_stdout)] -//! The simplest linter +//! # Simple Linter Example +//! +//! This example demonstrates how to create a basic linter using Oxc's parser and semantic analyzer. +//! It implements simple rules to detect debugger statements and empty destructuring patterns. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_linter --example linter [filename] +//! ``` use std::{env, path::Path}; @@ -15,6 +25,7 @@ use oxc_span::{SourceType, Span}; // run `cargo run -p oxc_linter --example linter` // or `cargo watch -x "run -p oxc_linter --example linter"` +/// Run a simple linter on a JavaScript file fn main() -> std::io::Result<()> { let name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string()); let path = Path::new(&name); @@ -29,10 +40,12 @@ fn main() -> std::io::Result<()> { return Ok(()); } + // Build semantic model for AST analysis let semantic_ret = SemanticBuilder::new().build(&ret.program); let mut errors: Vec = vec![]; + // Check for linting violations for node in semantic_ret.semantic.nodes() { match node.kind() { AstKind::DebuggerStatement(stmt) => { @@ -48,6 +61,7 @@ fn main() -> std::io::Result<()> { } } + // Report results if errors.is_empty() { println!("Success!"); } else { @@ -57,6 +71,7 @@ fn main() -> std::io::Result<()> { Ok(()) } +/// Print diagnostic errors with source context fn print_errors(source_text: &str, errors: Vec) { for error in errors { let error = error.with_source_code(source_text.to_string()); @@ -64,6 +79,7 @@ fn print_errors(source_text: &str, errors: Vec) { } } +/// Create a diagnostic for debugger statements // This prints: // // ⚠ `debugger` statement is not allowed @@ -75,6 +91,7 @@ fn no_debugger(debugger_span: Span) -> OxcDiagnostic { OxcDiagnostic::error("`debugger` statement is not allowed").with_label(debugger_span) } +/// Create a diagnostic for empty destructuring patterns // This prints: // // ⚠ empty destructuring pattern is not allowed diff --git a/crates/oxc_minifier/examples/dce.rs b/crates/oxc_minifier/examples/dce.rs index 19d051db84099..444e2eaf98668 100644 --- a/crates/oxc_minifier/examples/dce.rs +++ b/crates/oxc_minifier/examples/dce.rs @@ -1,4 +1,21 @@ #![expect(clippy::print_stdout)] +//! # Dead Code Elimination Example +//! +//! This example demonstrates dead code elimination (DCE) using the Oxc compressor. +//! It removes unreachable code and unused variables. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_minifier --example dce [filename] [--nospace] [--twice] +//! ``` +//! +//! ## Options +//! +//! - `--nospace`: Remove extra whitespace +//! - `--twice`: Test idempotency by running twice + use std::path::Path; use oxc_allocator::Allocator; diff --git a/crates/oxc_minifier/examples/mangler.rs b/crates/oxc_minifier/examples/mangler.rs index 772ce49ee6d56..d25d66fe196fc 100644 --- a/crates/oxc_minifier/examples/mangler.rs +++ b/crates/oxc_minifier/examples/mangler.rs @@ -1,4 +1,22 @@ #![expect(clippy::print_stdout)] +//! # Variable Name Mangling Example +//! +//! This example demonstrates variable name mangling using the Oxc mangler. +//! It shortens variable names to reduce file size. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_minifier --example mangler [filename] [options] +//! ``` +//! +//! ## Options +//! +//! - `--keep-names`: Preserve function and class names +//! - `--debug`: Enable debug output +//! - `--twice`: Test idempotency by running twice + use std::path::Path; use oxc_allocator::Allocator; diff --git a/crates/oxc_minifier/examples/minifier.rs b/crates/oxc_minifier/examples/minifier.rs index c487a6fd9d547..84c2779246aff 100644 --- a/crates/oxc_minifier/examples/minifier.rs +++ b/crates/oxc_minifier/examples/minifier.rs @@ -1,4 +1,23 @@ #![expect(clippy::print_stdout)] +//! # Minifier Example +//! +//! This example demonstrates the Oxc minifier with options for compression, +//! mangling, and source map generation. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_minifier --example minifier [filename] [options] +//! ``` +//! +//! ## Options +//! +//! - `--mangle`: Enable variable name mangling +//! - `--nospace`: Remove extra whitespace +//! - `--twice`: Test idempotency by running twice +//! - `--sourcemap`: Generate source maps + use std::path::{Path, PathBuf}; use base64::{Engine, prelude::BASE64_STANDARD}; diff --git a/crates/oxc_parser/examples/parser.rs b/crates/oxc_parser/examples/parser.rs index f696c612b8687..6b65f9d53be23 100644 --- a/crates/oxc_parser/examples/parser.rs +++ b/crates/oxc_parser/examples/parser.rs @@ -1,4 +1,21 @@ #![expect(clippy::print_stdout)] +//! # Parser Example +//! +//! This example demonstrates how to use the Oxc parser to parse JavaScript and TypeScript files. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_parser --example parser [filename] [--ast] [--estree] [--comments] +//! ``` +//! +//! ## Options +//! +//! - `--ast`: Display the parsed AST structure +//! - `--estree`: Display the ESTree representation +//! - `--comments`: Display extracted comments + use std::{fs, path::Path}; use oxc_allocator::Allocator; @@ -12,24 +29,29 @@ use pico_args::Arguments; // run `cargo run -p oxc_parser --example parser` // or `just watch "cargo run -p oxc_parser --example parser"` +/// Parse and display information about a JavaScript or TypeScript file fn main() -> Result<(), String> { let mut args = Arguments::from_env(); + // Parse command line arguments let show_ast = args.contains("--ast"); let show_estree = args.contains("--estree"); let show_comments = args.contains("--comments"); let name = args.free_from_str().unwrap_or_else(|_| "test.js".to_string()); + // Read source file let path = Path::new(&name); let source_text = fs::read_to_string(path).map_err(|_| format!("Missing '{name}'"))?; let source_type = SourceType::from_path(path).unwrap(); + // Parse the source code let allocator = Allocator::default(); let ret = Parser::new(&allocator, &source_text, source_type) .with_options(ParseOptions { parse_regular_expression: true, ..ParseOptions::default() }) .parse(); let mut program = ret.program; + // Display comments if requested if show_comments { println!("Comments:"); for comment in &program.comments { @@ -38,11 +60,13 @@ fn main() -> Result<(), String> { } } + // Display AST if requested if show_ast { println!("AST:"); println!("{program:#?}"); } + // Display ESTree representation if requested if show_estree { Utf8ToUtf16::new(&source_text).convert_program(&mut program); if source_type.is_javascript() { @@ -54,6 +78,7 @@ fn main() -> Result<(), String> { } } + // Report parsing results if ret.errors.is_empty() { println!("Parsed Successfully."); } else { diff --git a/crates/oxc_parser/examples/parser_tsx.rs b/crates/oxc_parser/examples/parser_tsx.rs index 27507f39422e1..38ab4ba293806 100644 --- a/crates/oxc_parser/examples/parser_tsx.rs +++ b/crates/oxc_parser/examples/parser_tsx.rs @@ -1,7 +1,19 @@ +//! # TypeScript JSX Parsing Example +//! +//! This example demonstrates parsing TypeScript files with JSX syntax. +//! It shows how to parse a simple React component and validate the parsing results. +//! +//! ## Usage +//! +//! ```bash +//! cargo run -p oxc_parser --example parser_tsx +//! ``` + use oxc_allocator::Allocator; use oxc_parser::{Parser, ParserReturn}; use oxc_span::SourceType; +/// Parse a TypeScript JSX file and validate the results fn main() { let source_text = r" import React from 'react'; diff --git a/crates/oxc_parser/examples/visitor.rs b/crates/oxc_parser/examples/visitor.rs index c2eb981a1daf0..c9a800b17f6cb 100644 --- a/crates/oxc_parser/examples/visitor.rs +++ b/crates/oxc_parser/examples/visitor.rs @@ -1,4 +1,16 @@ #![expect(clippy::print_stdout)] +//! # AST Visitor Example +//! +//! This example demonstrates how to use the visitor pattern to traverse and analyze +//! an AST. It counts different types of nodes (functions, classes, TypeScript imports). +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_parser --example visitor [filename] +//! ``` + use std::{env, path::Path}; use oxc_allocator::Allocator; @@ -13,6 +25,7 @@ use oxc_syntax::scope::ScopeFlags; // run `cargo run -p oxc_parser --example visitor` // or `cargo watch -x "run -p oxc_parser --example visitor"` +/// Demonstrate AST traversal using the visitor pattern fn main() -> std::io::Result<()> { let name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string()); let path = Path::new(&name); @@ -21,6 +34,7 @@ fn main() -> std::io::Result<()> { let source_type = SourceType::from_path(path).unwrap(); let ret = Parser::new(&allocator, &source_text, source_type).parse(); + // Report any parsing errors for error in ret.errors { let error = error.with_source_code(source_text.clone()); println!("{error:?}"); @@ -28,6 +42,7 @@ fn main() -> std::io::Result<()> { let program = ret.program; + // Use visitor to count different AST node types let mut ast_pass = CountASTNodes::default(); ast_pass.visit_program(&program); println!("{ast_pass:?}"); @@ -35,6 +50,7 @@ fn main() -> std::io::Result<()> { Ok(()) } +/// A visitor that counts different types of AST nodes #[derive(Debug, Default)] struct CountASTNodes { functions: usize, diff --git a/crates/oxc_regular_expression/examples/parse_literal.rs b/crates/oxc_regular_expression/examples/parse_literal.rs index a0ab9a1d48af6..8d8a8a7eea556 100644 --- a/crates/oxc_regular_expression/examples/parse_literal.rs +++ b/crates/oxc_regular_expression/examples/parse_literal.rs @@ -1,8 +1,19 @@ #![expect(clippy::print_stdout)] +//! # Regular Expression Literal Parsing Example +//! +//! This example demonstrates parsing regular expression literals with various +//! patterns and flags to validate and analyze regex syntax. +//! +//! ## Usage +//! +//! ```bash +//! cargo run -p oxc_regular_expression --example parse_literal +//! ``` use oxc_allocator::Allocator; use oxc_regular_expression::{LiteralParser, Options}; +/// Test various regular expression patterns and demonstrate parsing results fn main() { let allocator = Allocator::default(); diff --git a/crates/oxc_regular_expression/examples/regex_visitor.rs b/crates/oxc_regular_expression/examples/regex_visitor.rs index 0744b3a335277..43ded7a563a19 100644 --- a/crates/oxc_regular_expression/examples/regex_visitor.rs +++ b/crates/oxc_regular_expression/examples/regex_visitor.rs @@ -1,4 +1,14 @@ #![expect(clippy::print_stdout)] +//! # Regular Expression AST Visitor Example +//! +//! This example demonstrates how to use the visitor pattern to traverse +//! regular expression ASTs and inspect different node types. +//! +//! ## Usage +//! +//! ```bash +//! cargo run -p oxc_regular_expression --example regex_visitor +//! ``` use oxc_allocator::Allocator; use oxc_regular_expression::{ @@ -7,6 +17,7 @@ use oxc_regular_expression::{ }; use oxc_span::GetSpan; +/// A test visitor that logs entering and leaving AST nodes struct TestVisitor; impl Visit<'_> for TestVisitor { @@ -19,6 +30,7 @@ impl Visit<'_> for TestVisitor { } } +/// Demonstrate regex AST traversal using the visitor pattern fn main() { let source_text = r"(https?:\/\/github\.com\/(([^\s]+)\/([^\s]+))\/([^\s]+\/)?(issues|pull)\/([0-9]+))|(([^\s]+)\/([^\s]+))?#([1-9][0-9]*)($|[\s\:\;\-\(\=])"; @@ -26,6 +38,7 @@ fn main() { let parser = LiteralParser::new(&allocator, source_text, None, Options::default()); let pattern = parser.parse().unwrap(); + // Visit the regex AST and log each node let mut visitor = TestVisitor; visitor.visit_pattern(&pattern); } diff --git a/crates/oxc_semantic/examples/cfg.rs b/crates/oxc_semantic/examples/cfg.rs index 1f7c77aced46e..3c8cf9202e446 100644 --- a/crates/oxc_semantic/examples/cfg.rs +++ b/crates/oxc_semantic/examples/cfg.rs @@ -1,4 +1,20 @@ #![expect(clippy::print_stdout)] +//! # Control Flow Graph (CFG) Example +//! +//! This example demonstrates how to build and visualize control flow graphs +//! from JavaScript/TypeScript code using Oxc's semantic analyzer. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_semantic --example cfg [filename] +//! ``` +//! +//! This generates: +//! - AST dump (`test.ast.txt`) +//! - CFG blocks (`test.cfg.txt`) +//! - CFG graph in DOT format (`test.dot`) use std::{env, path::Path, sync::Arc}; @@ -26,6 +42,7 @@ use oxc_span::SourceType; // - CFG blocks (test.cfg.txt) // - CFG graph (test.dot) +/// Generate control flow graph visualizations from JavaScript/TypeScript code fn main() -> std::io::Result<()> { let test_file_name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string()); let ast_file_name = env::args().nth(1).unwrap_or_else(|| "test.ast.txt".to_string()); diff --git a/crates/oxc_semantic/examples/semantic.rs b/crates/oxc_semantic/examples/semantic.rs index e459dad152f6e..b375a8377b365 100644 --- a/crates/oxc_semantic/examples/semantic.rs +++ b/crates/oxc_semantic/examples/semantic.rs @@ -1,4 +1,19 @@ #![expect(clippy::print_stdout)] +//! # Semantic Analysis Example +//! +//! This example demonstrates how to use Oxc's semantic analyzer to perform symbol analysis +//! and scope resolution on JavaScript and TypeScript code. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_semantic --example semantic [filename] [--symbols] +//! ``` +//! +//! ## Options +//! +//! - `--symbols`: Display symbol table and reference information use std::{env, path::Path, sync::Arc}; @@ -14,6 +29,7 @@ use oxc_span::SourceType; // run `cargo run -p oxc_semantic --example semantic` // or `just watch "run -p oxc_semantic --example semantic"` +/// Perform semantic analysis on a JavaScript or TypeScript file fn main() -> std::io::Result<()> { let name = env::args().nth(1).unwrap_or_else(|| "test.js".to_string()); let show_symbols = env::args().skip(1).any(|arg| arg == "--symbols"); @@ -37,11 +53,13 @@ fn main() -> std::io::Result<()> { let program = parser_ret.program; + // Build semantic model with syntax error checking let semantic = SemanticBuilder::new() // Enable additional syntax checks not performed by the parser .with_check_syntax_error(true) .build(&program); + // Report semantic analysis errors if !semantic.errors.is_empty() { let error_message: String = semantic .errors @@ -51,6 +69,7 @@ fn main() -> std::io::Result<()> { println!("Semantic analysis failed:\n\n{error_message}",); } + // Display symbol information if requested if show_symbols { let scoping = semantic.semantic.scoping(); for symbol_id in scoping.symbol_ids() { diff --git a/crates/oxc_transformer/examples/transformer.rs b/crates/oxc_transformer/examples/transformer.rs index 06f92581c11d5..47e660c119742 100644 --- a/crates/oxc_transformer/examples/transformer.rs +++ b/crates/oxc_transformer/examples/transformer.rs @@ -1,4 +1,23 @@ #![expect(clippy::print_stdout)] +//! # Transformer Example +//! +//! This example demonstrates code transformation using the Oxc transformer. +//! It supports various transformation options including Babel compatibility +//! and environment-specific transforms. +//! +//! ## Usage +//! +//! Create a `test.js` file and run: +//! ```bash +//! cargo run -p oxc_transformer --example transformer [filename] [options] +//! ``` +//! +//! ## Options +//! +//! - `--babel-options `: Path to Babel options file +//! - `--targets `: Browser/environment targets +//! - `--target `: Single target environment + use std::path::Path; use oxc_allocator::Allocator; @@ -13,6 +32,7 @@ use pico_args::Arguments; // create a `test.js`, // run `just example transformer` or `just watch-example transformer` +/// Demonstrate code transformation with various options fn main() { let mut args = Arguments::from_env(); let babel_options_path: Option =