Rust API

compile

Compile source text from parse to generate.

pub async fn compile(
    code: String,
    options: CompileOptions,
    plugins: Vec<SharedPluginable>,
) -> Result<CodeResult, CompileError>

Compiles code from source to generated output.

Because the stages run inline, options, start, and end fire exactly once. The builtin parser resolves any requested input source map.

Parameters

NameTypeDescription
codeStringThe source text to compile.
optionsCompileOptionsThe compile options.
pluginsVec<SharedPluginable>The plugins to run.

CompileOptions

Every field is optional and resolved against defaults before use.

FieldTypeDefaultDescription
cwdOption<PathBuf>process working dirFilesystem root used to resolve relative paths.
fileOption<String>index.tsThe file being compiled. The language is inferred from its extension.
languageOption<Language>inferredThe grammar of the code. Overrides the extension inference.
source_typeOption<SourceType>inferredThe module system of the code. Overrides the grammar's module kind.
outputOption<OutputOptions>fileOutput code settings. output.file derives the default source-map URL.
source_mapOption<SourceMapOptions>offThe source-map inputs and outputs requested for the run.

Returns

Result<CodeResult, CompileError>, where CodeResult is { code: String, map: Option<SourceMap> }.

Example

use telarel::{compile, CompileOptions, CodeResult};

let result: CodeResult = compile(
    String::from("const x: number = 1;"),
    CompileOptions::default(),
    vec![],
).await?;

println!("{}", result.code); // const x = 1;

Last updated on

Copyright © 2026, Alpheus

On this page