compile_from_ast
Compile an existing AST through rewrite and generation.
pub async fn compile_from_ast(
ast: Ast,
options: CompileFromAstOptions,
plugins: Vec<SharedPluginable>,
) -> Result<CodeResult, CompileError>Compiles an existing ast through rewrite and generation.
Because the stages run inline, options, start, and end fire exactly once.
Parameters
| Name | Type | Description |
|---|---|---|
ast | Ast | The AST to compile. |
options | CompileFromAstOptions | The compile options. |
plugins | Vec<SharedPluginable> | The plugins to run. |
CompileFromAstOptions
Every field is optional and resolved against defaults before use.
| Field | Type | Default | Description |
|---|---|---|---|
cwd | Option<PathBuf> | process working dir | Filesystem root used to resolve relative paths. |
file | Option<String> | index.ts | The file being compiled; used for option resolution and source-map defaults. Does not change the AST grammar. |
language | Option<Language> | AST language, then file | The grammar recorded in the resolved step options and visible to plugins. Does not change the input AST grammar. |
source_type | Option<SourceType> | inferred | The module kind recorded in the resolved step options and visible to plugins. Does not change the input AST module kind. |
output | Option<OutputOptions> | file | Output code settings. output.file derives the default source-map URL. |
source_map | Option<SourceMapOptions> | off | The source-map inputs and outputs requested for the run. |
The explicit values are visible to the options hook; after resolution the values (explicit or inferred) are visible to start and later hooks through the resolved options and PluginContext.module. When language is omitted, the resolved language falls back to the input AST grammar, then the file extension. compile_from_ast does not reparse the AST; the rewrite stages return the input AST or a plugin replacement, and builtin generation emits from that AST's own Program.source_type.
Returns
Result<CodeResult, CompileError>, where CodeResult is { code: String, map: Option<SourceMap> }.
Example
use telarel::{
parse,
compile_from_ast,
ParseOptions,
CompileFromAstOptions,
AstResult,
CodeResult,
};
let parsed: AstResult = parse(
String::from("const x: number = 1;"),
ParseOptions::default(),
vec![],
).await?;
let result: CodeResult = compile_from_ast(
parsed.ast,
CompileFromAstOptions::default(),
vec![],
).await?;
println!("{}", result.code); // const x = 1;Last updated on
Copyright © 2026, Alpheus