createGenerator
Create a builtin generator over a fixed AST and options.
function createGenerator(ast: Ast, options: GeneratorOptions): Generator;
type Generator = {
generate: () => Promise<CodeResult>;
};Creates a builtin generator over ast and options.
The returned generator calls the builtin generator directly and never runs the plugin chain. Use generate when plugins should be able to replace the generated result.
Parameters
| Name | Type | Description |
|---|---|---|
ast | Ast | The AST to generate from. |
options | GeneratorOptions | The generator's fixed, resolved options. |
GeneratorOptions
Every field is required. In a generate hook, the stage options are available as args.options.
| Field | Type | Description |
|---|---|---|
cwd | string | Current working directory. Reserved; codegen ignores it. |
file | string | The file being generated. |
sourceMap | SourceMapOptions | The source-map inputs and outputs requested for the step. |
Generation uses ast.language when present, then the file extension. GeneratorOptions has no language field.
The builtin generator composes the AST's input map into the produced map and returns that map separately. Output delivery modes (external, inline, and both) are applied by the pipeline, not by the builtin generator.
Returns
A Generator whose generate() method returns Promise<CodeResult>:
| Field | Type | Description |
|---|---|---|
code | string | The generated code. |
map | SourceMap | null | The source map for the generated code, when one was produced. |
Generation failures reject with a CompileError.
Example
import type { AstResult, CodeResult, Generator } from "telarel";
import { createGenerator, parse } from "telarel";
const { ast }: AstResult = await parse("const x: number = 1;");
const generator: Generator = createGenerator(ast, {
cwd: process.cwd(),
file: "index.ts",
sourceMap: {},
});
const result: CodeResult = await generator.generate();Last updated on
createParser
Create a builtin parser over fixed source text and options.
ErrorSource
A source location attached to CompileError and PluginError.
Copyright © 2026, Alpheus