Skip to content

@sqlrooms/mosaic / astToESM

Function: astToESM()

astToESM(ast, options?): string

Generate ESM code for a Mosaic spec AST.

Parameters

ParameterTypeDescription
astSpecNodeMosaic AST root node.
options?{ baseURL?: string; connector?: string; namespace?: string; depth?: number; imports?: Map<string, string | string[]>; preamble?: string | string[]; }Code generation options.
options.baseURL?stringThe base URL for loading data files.
options.connector?stringA database connector to initialize. Valid values are 'wasm', 'socket', and 'rest'. If undefined, no connector code is generated.
options.namespace?stringThe vgplot API namespace object.
options.depth?numberThe starting indentation depth.
options.imports?Map<string, string | string[]>A Map of ESM imports to include in generated code. Keys are packages (e.g., '@uwdata/vgplot') and values indicate what to import (e.g., '* as vg').
options.preamble?string | string[]Code to include after imports.

Returns

string

Generated ESM code using the vgplot API.