diff --git a/src/oxc/explore.md b/src/oxc/explore.md index 65a67d2..2d3772b 100644 --- a/src/oxc/explore.md +++ b/src/oxc/explore.md @@ -2,8 +2,31 @@ +## oxc_ast + +### Printing an AST + +For this one, you will need to read [`oxc_codegen`](#oxc_codegen) before. + ## oxc_codegen +[`oxc:oxc_codegen::Codegen`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/lib.rs) is the struct that holds everything needed to transform an [`oxc::oxc_ast::ast::Program`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_ast/src/ast/js.rs) into a `CodegenReturn` thanks to its `build` method. + +The `CodegenReturn` contains: + +- `code: String` (the code generated from the ast) +- `map: Option` (the sourcemap if activated) + +### Codegen::build + +- prepares a buffer for the code that will be generated - `self.code.reserve(program.source_text.len())` +- creates a [`HashMap`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/comment.rs) of the comments contained in the AST (if the comments are to be printed - like not in minified code) +- creates a [`oxc::oxc_codegen::SourcemapBuilder`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/sourcemap_builder.rs) (if sourcemaps are active) + +Finally, calls the `print` method on the AST, passing itself `&mut Codegen` and a default [`oxc::oxc_codegen::Context`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_codegen/src/context.rs) which will be passed to each `print` calls of each AST node. + +See the follow-up in [`oxc_ast`](#oxc_ast). + See more about sourcemaps on [`oxc::oxc_sourcemaps`](#oxc_sourcemap). 📄