Skip to content
Shapemetry

Model - Expression

API reference for src/schema/expression, src/expression on @huukhanhnguyen/model, reachable from ..

See the Guide for the ModelJSON / evaluate pipeline.

API reference

Signatures are generated from the live package .d.ts - not hand-written.

Arr

type

type Arr
// = Expression & { type: "ArrayExpression"; elements: Expression[]; }

Arrow

type

type Arrow
// = Expression & { type: "ArrowFunctionExpression"; params?: Ident[]; body: Expression; }

Bin

type

type Bin
// = Expression & { type: "BinaryExpression"; operator: string; left: Expression; right: Expression; }

Call

type

type Call
// = Expression & { type: "CallExpression"; callee: Expression; arguments: Expression[]; }

collectIdentifiers

function

Every free identifier an expression references (shadow-aware). An unparseable expression yields an empty set — syntax reporting is validateExpressions' job, not this collector's.

collectIdentifiers(expr: string): Set<string>

Comp

type

type Comp
// = Expression & { type: "Compound"; body: Expression[]; }

Cond

type

type Cond
// = Expression & { type: "ConditionalExpression"; test: Expression; consequent: Expression; alternate: Expression; }

EvalContext

type

Public expression types, plus the nested jsep AST node shapes shared by the evaluator (src/expression.ts), the unit rewriter (utils/convertExpression.ts) and schema/nodesRegistry.ts — three consumers across two boundaries, so they live here, not in _locals.

type EvalContext
// = Record<string, unknown>

evaluate

function

Evaluate an expression AST. namespaces = the registry's PascalCase computation namespaces (Point, Vector, NurbsCurve, …) for the owning model — per-registry, NOT module-global, so two models on different registries can coexist in one process. They sit on the prototype chain below the JS builtins; node keys (own props of context) shadow both.

evaluate(node: Expression, context?: EvalContext, namespaces?: Record<string, unknown>): unknown

ExpressionBudgetError

class

Thrown when an expression exceeds an evaluation resource budget (step fuel, or a user-controlled array length at a builtin).

class ExpressionBudgetError

freezeNamespace

function

Freeze a RUNTIME-injected namespace (Table, Scene, Material) before an expression can see it. Same threat as the builtins above: [].push.call(Table, 'X') rebinds this to whatever object the DSL holds. The methods are frozen too — a bare function object is just as pollutable as the namespace that carries it.

freezeNamespace(namespace: T): T

Fuel

type

type Fuel
// = {
    remaining: number;
}

Ident

type

type Ident
// = Expression & { type: "Identifier"; name: string; start?: number; }

Lit

type

type Lit
// = Expression & { type: "Literal"; value: unknown; raw?: string; }

Mem

type

type Mem
// = Expression & { type: "MemberExpression"; object: Expression; property: Expression; computed: boolean; }

Obj

type

type Obj
// = Expression & { type: "ObjectExpression"; properties: ObjProp[]; }

ObjProp

type

type ObjProp
// = {
    key: Ident | Lit;
    value: Expression;
}

quoteLiteral

function

quoteLiteral(text: string): string

renameIdentifier

function

Rewrite every reference to oldName as newName in an expression string (used to propagate a node key rename into every formula that referenced it). Returns expr unchanged if it doesn't parse (mid-edit/invalid text) or contains no matching reference.

renameIdentifier(expr: string, oldName: string, newName: string): string

stringify

function

stringify(node: Expression, parentPrec?: number): string

Un

type

type Un
// = Expression & { type: "UnaryExpression"; operator: string; argument: Expression; }
Last updated: 📖 2 min readEdit on GitHub