Skip to content

OptimizerContext

OptimizerContext embeds an environment and expression factory for type-safe AST rewrites.

Generated subexpressions use ids consistent with parsed expressions, and copied macro metadata is coordinated with the ids assigned to copied expression trees.

new OptimizerContext(options): OptimizerContext

constructor initializes a context for a single static optimization run.

Env

number

SourceInfo

OptimizerContext

ast(expr): AST

ast creates an AST from an expression using source info managed by this context.

Expr

AST


bindMacro(options): MacroExpressionPair

bindMacro creates an expanded cel.bind expression and its unexpanded macro signature.

BindMacroOptions

MacroExpressionPair


call(options): Expr

call creates a global function call invocation expression.

CallOptions

Expr


clearMacroCall(id): void

clearMacroCall clears the macro at the given expression id.

number

void


copyAst(input): object

copyAst creates a renumbered copy of an input AST’s expression and source info.

Use this method before merging an expression from one AST into another.

AST

object

expr: Expr

sourceInfo: SourceInfo


copyAstAndMetadata(input): Expr

copyAstAndMetadata copies an AST and propagates its macro and offset metadata.

AST

Expr


env(): Env

env returns the environment currently associated with the optimizer context.

Env


extendEnv(options?): void

extendEnv augments the context environment with additional option-object configuration.

EnvOptions = {}

void


hasMacro(options): MacroExpressionPair

hasMacro creates a test-only select and an unexpanded has macro signature.

HasMacroOptions

MacroExpressionPair


ident(name): Expr

ident creates an identifier expression.

string

Expr


list(options): Expr

list creates a list expression with optional element indices.

ListOptions

Expr


literal(value): Expr

literal creates a CEL literal expression.

ConstantValue

Expr


macroCalls(): Map<number, Expr>

macroCalls returns the macro calls currently tracked by the context.

Map<number, Expr>


map(entries): Expr

map creates a map from entry expressions.

EntryExpr[]

Expr


mapEntry(options): EntryExpr

mapEntry creates a map entry expression.

MapEntryOptions

EntryExpr


memberCall(options): Expr

memberCall creates a receiver-style function call invocation expression.

MemberCallOptions

Expr


select(options): Expr

select creates a field selection expression.

SelectOptions

Expr


setMacroCall(options): void

setMacroCall sets macro call metadata for the given expression id.

SetMacroCallOptions

void


struct(options): Expr

struct creates a typed struct expression.

StructOptions

Expr


structField(options): EntryExpr

structField creates a struct field initializer.

StructFieldOptions

EntryExpr


updateExpr(options): void

updateExpr updates a target expression while preserving macro metadata.

The update handles every combination of macro and non-macro target and replacement nodes.

UpdateExprOptions

void