import { STWriter } from "./STWriter.js"; import { STGroup } from "./STGroup.js"; import { STErrorListener } from "./STErrorListener.js"; import { ICompiledST, IST, ISTGroup } from "./compiler/common.js"; /** * An instance of the StringTemplate. It consists primarily of * a {@link ST#impl reference} to its implementation (shared among all * instances) and a hash table of {@link ST#locals attributes}. Because * of dynamic scoping, we also need a reference to any enclosing instance. For * example, in a deeply nested template for an HTML page body, we could still * reference the title attribute defined in the outermost page template. *

* To use templates, you create one (usually via {@link STGroup}) and then inject * attributes using {@link #add}. To render its attacks, use {@link ST#render()}.

*

* TODO: {@link ST#locals} is not actually a hash table like the documentation * says.

*/ export declare class ST implements IST { static readonly VERSION = "4.3.4ng"; static readonly UNKNOWN_NAME = "anonymous"; static readonly EMPTY_ATTR: {}; /** * When there are no formal args for template t and you map t across * some values, t implicitly gets arg "it". E.g., "$it$" */ static readonly IMPLICIT_ARG_NAME = "it"; /** The implementation for this template among all instances of same template . */ impl?: ICompiledST; /** * Created as instance of which group? We need this to initialize interpreter * via render. So, we create st and then it needs to know which * group created it for sake of polymorphism: * *
     *  st = skin1.getInstanceOf("searchBox");
     *  result = st.render(); // knows skin1 created it
     *  
* * Say we have a group {@code g1} with template {@code t} that imports * templates {@code t} and {@code u} from another group {@code g2}. * {@code g1.getInstanceOf("u")} finds {@code u} in {@code g2} but remembers * that {@code g1} created it. If {@code u} includes {@code t}, it should * create {@code g1.t} not {@code g2.t}. * *
     *   g1 = {t(), u()}
     *   |
     *   v
     *   g2 = {t()}
     *  
*/ groupThatCreatedThisInstance: ISTGroup; /** * Safe to simultaneously write via {@link #add}, which is synchronized. * Reading during exec is, however, NOT synchronized. So, not thread safe * to add attributes while it is being evaluated. Initialized to * {@link #EMPTY_ATTR} to distinguish {@code null} from empty. */ locals?: unknown[]; /** Used by group creation routine, not by users */ constructor(); /** * Used to make templates inline in code for simple things like SQL or log records. * No formal arguments are set and there is no enclosing instance. */ constructor(template: string); /** * Clone a prototype template. * Copy all fields minus {@link #debugState}; don't delegate to {@link #ST()}, * which creates {@link ConstructionEvent}. */ constructor(proto: IST); constructor(group: STGroup, template: string); /** * Create ST using non-default delimiters; each one of these will live * in it's own group since you're overriding a default; don't want to * alter {@link STGroup#defaultGroup}. */ constructor(template: string, delimiterStartChar: string, delimiterStopChar: string); /** *
     * ST.format("<%1>:<%2>", n, p);
     * 
*/ static format(template: string, ...attributes: unknown[]): string; static format(lineWidth: number, template: string, ...attributes: unknown[]): string; protected static convertToAttributeList(currentValue: unknown): unknown[]; /** * Inject an attribute (name/value pair). If there is already an attribute * with that name, this method turns the attribute into an * {@link AttributeList} with both the previous and the new attribute as * elements. This method will never alter a {@link List} that you inject. * If you send in a {@link List} and then inject a single value element, * {@code add} copies original list and adds the new value. The * attribute name cannot be null or contain '.'. *

* Return {@code this} so we can chain:

*

* {@code t.add("x", 1).add("y", "hi")}

*/ add(name: string, value: unknown): ST; /** * Split {@code aggrName.{propName1,propName2}} into list * {@code [propName1, propName2]} and the {@code aggrName}. Spaces are * allowed around {@code ','}. */ addAggr(aggregateSpec: string, ...values: unknown[]): ST; /** * Remove an attribute value entirely (can't remove attribute definitions). */ remove(name: string): void; /** * Find an attribute in this template only. */ getAttribute(name: string): unknown; getAttributes(): Map | undefined; getName(): string; isAnonSubtemplate(): boolean; write(out: STWriter): number; write(out: STWriter, locale: Intl.Locale): number; write(out: STWriter, listener: STErrorListener): number; write(out: STWriter, locale: Intl.Locale, listener: STErrorListener): number; render(lineWidth?: number): string; render(locale: Intl.Locale, lineWidth?: number): string; toString(): string; /** * Set {@code locals} attribute value when you only know the name, not the * index. This is ultimately invoked by calling {@code ST#add} from * outside so toss an exception to notify them. */ rawSetAttribute(name: string, value: unknown): void; }