import { ForLoopDrop } from "./builtin/drops/forloop"; import { ObjectChain } from "./chain_object"; import { LiquidPrimitive } from "./drop"; import { Environment } from "./environment"; import { Template } from "./template"; import { ContextScope } from "./types"; export declare const EXTENDS_REGISTER: unique symbol; export type ContextPath = Array; export type RenderContextOptions = { templateName?: string; disabledTags?: Set; copyDepth?: number; loaderContext?: ContextScope; localsScoreCarry?: number; loopIterationCarry?: number; template?: Template; }; /** * A RenderContext manages template scopes, internal registers and * access to the bound environment during the rendering of a template. * * A new RenderContext is created automatically every time `render()` * is called on a `Template`, so you probably don't want to instantiate * it directly. */ export declare class RenderContext { readonly environment: Environment; private globals; /** * A distinct scope for counters set using the `increment` and * `decrement` tags. */ readonly counters: { [index: string]: number; }; /** * A stack of `ForLoopDrop` objects. Used to populate the `parentloop` * property of a `ForLoopDrop`. */ readonly forLoops: ForLoopDrop[]; /** * A register is a Map used by tags and/or filters to store arbitrary * values that are not available to template authors. Use `getRegister()` * to obtain a named register. */ readonly registers: Map>; /** * A namespace for variables set using the `assign` or `capture` tags. */ private locals; /** * A non-specific indication of how much the local namespace has been used. */ localsScore: number; /** * A loop iteration count carried over from a parent context, if this one has * been copied. This helps us adhere to loop iteration limits in templates * rendered with the `render` tag. */ readonly loopIterationCarry: number; /** * A chain of scopes. When resolving names, each scope in the chain is * searched in order. If a new scope if pushed on to a RenderContext, * it is pushed to the front if this chain. */ readonly scope: ObjectChain; /** * A set of tag names that are disallowed in this render context. For * example, the `include` tag is not allowed in templates rendered * with the `render` tag. */ readonly disabledTags: Set; /** The name of the template being rendered. Will be `` for * templates parsed using `Environment.fromString()` without being * given a name. */ readonly templateName: string; /** * The `Template` being rendered by this render context. */ template?: Template; /** * The number of times this render context has been copied or * extended. This helps us guard against recursive use of `include` * or `render` tags. */ private copyDepth; /** * An object containing arbitrary properties passed down from a * template loader. The properties of this object are not intended * to be accessible by template authors. */ readonly loaderContext: ContextScope; /** * * @param environment - The environment from which this context was created. * @param globals - Global template variables, passed down from the * Environment, Template, Loader and arguments to `.render()`. * @param options - Extra render context options. */ constructor(environment: Environment, globals?: ContextScope, { disabledTags, templateName, copyDepth, loaderContext, localsScoreCarry, loopIterationCarry, template, }?: RenderContextOptions); /** * Assign or re-assign a template local variable, probably from either the * `assign` or `capture` tags. * @param key - The name of the template local variable. * @param value - The value of the template local variable. */ assign(key: string, value: unknown): void; /** * Return a size or score for the key and/or value to contribute to the local * namespace score. Override this to control how the local namespace score is * calculated. */ assignScore(key: string, value: unknown): number; /** * Resolve a template variable by searching the scope chain. Unlike `get`, * `resolve` performs a single, top level search of the scope chain. It * does not expect a dotted or bracketed identifier. * @param name - The name of the template variable to resolve. * @returns The value stored against the given name, or an instance of * the `Undefined` class defined on the attached environment. */ resolve(name: string): Promise; resolveSync(name: string): unknown; /** * Search the current scope for a template variable and, if found, follow * the given path. This is a bit like resolving a JSONPath expression. * @param name - The name of the template variable to resolve. * @param path - An optional array of path elements to follow. * @param missing - A default value used if the name and path fail to find * a value. * @returns The value at `path`, starting from the given name, or `missing` * otherwise. If `missing` is not given, an instance of the `Undefined` * class defined on the attached environment will be used. */ get(name: string, path?: ContextPath, missing?: unknown): Promise; /** * A synchronous version of `RenderContext.get()`. * @see {@link get} */ getSync(name: string, path?: ContextPath, missing?: unknown): unknown; /** * A convenience method for loading a template from the attached environment. * @param name - The name or identifier of the template to load. * @param loaderContext - Additional, arbitrary data that a loader can use * to scope or otherwise narrow its search space. * @returns A `Template`, ready to be rendered. * @throws `NoSuchTemplateError` if a template with the given name can not * be found. */ getTemplate(name: string, loaderContext: { [index: string]: unknown; }): Promise