import { ChildNode, Node } from "./ast"; import { ObjectChain } from "./chain_object"; import { DefaultMap } from "./collections"; import { Template } from "./template"; import { RenderContext } from "./context"; /** * Options passed to `Template.analyze` and `Template.analyzeSync`. */ export type TemplateAnalysisOptions = { /** * If `true`, we will try to load partial templates and analyze those * templates too. * @defaultValue `true`. */ followPartials?: boolean; /** * If `true`, we will throw an error if an `ast.Node` or `expression.Expression` * does not define a `children()` method, or if a partial template can not be loaded. * When `false`, no error is thrown and an mapping of failed nodes and expressions * is available as the `failedVisits` property of the resulting `TemplateAnalysis` * object. */ raiseForFailures?: boolean; }; /** * The location of a template variable, as found during static template * analysis. * * A column number might be added later. */ export type VariableLocation = { templateName: string; lineNumber: number; }; /** * An array of template variable locations. */ export type VariableLocations = VariableLocation[]; /** * A mapping of template variable names to their locations. */ export type VariableRefs = { [index: string]: VariableLocations; }; /** * A mapping of template, tag or filter names to their locations. */ export type RefMap = DefaultMap; /** * The result of statically analyzing a template's variables. * * Each of the following properties is an object mapping template variable names * to an array of objects. Each object includes the template name and line number * of the associated variable. If a name is referenced multiple times, it will * appear multiple times in the array. If a name is referenced before it is * "assigned", it will appear in `localVariables` and `globalVariables`. */ export type TemplateAnalysis = { /** * All referenced variables, whether they are in scope or not. Including * references to names such as `forloop` from the `for` tag. */ variables: VariableRefs; /** * Template variables that are added to the template local scope, whether * they are subsequently used or not. */ localVariables: VariableRefs; /** * Template variables that, on the given line number and "file", are out of * scope or are assumed to be "global". That is, expected to be included by * the application developer rather than a template author. */ globalVariables: VariableRefs; /** * Names and locations of AST `Node` and `Expression` objects that could not * be visited, probably because they do not implement a `children` method. */ failedVisits: VariableRefs; /** * Names/identifiers and locations of partial templates that could not be * loaded. This will be empty if `followPartials` is `false`. */ unloadablePartials: VariableRefs; /** * Filters found during static analysis. */ filters: VariableRefs; /** * Tags found during static analysis. */ tags: VariableRefs; }; type TemplateVariableCounterOptions = { followPartials?: boolean; raiseForFailures?: boolean; scope?: ObjectChain; templateLocals?: RefMap; partials?: Set; }; export declare class TemplateVariableCounter { protected template: Template; readonly templateName: string; readonly followPartials: boolean; readonly raiseForFailures: boolean; readonly scope: ObjectChain; readonly partials: Set; readonly templateLocals: RefMap; readonly templateGlobals: RefMap; readonly variables: RefMap; readonly failedVisits: RefMap; readonly unloadablePartials: RefMap; readonly emptyContext: RenderContext; readonly filters: RefMap; readonly tags: RefMap; protected static RE_SPLIT_IDENT: RegExp; constructor(template: Template, { followPartials, raiseForFailures, scope, templateLocals, partials, }: TemplateVariableCounterOptions); analyze(): Promise; analyzeSync(): TemplateVariableCounter; protected _analyze(root: Node): Promise; protected _analyzeSync(root: Node): void; private analyzeExpression; private updateTemplateScope; private updateExpressionRefs; private analyzeInclude; private analyzeIncludeSync; private includeContext; private analyzeRender; private analyzeRenderSync; private analyzeTemplateInheritanceChain; private analyzeTemplateInheritanceChainSync; private extend; private stackBlocks; private getTemplate; private getTemplateSync; private renderContext; protected countTag(node: Node): void; protected updateReferenceCounters(refs: TemplateVariableCounter): void; private _raiseForFailures; protected expressionHook(child: ChildNode): Promise; protected expressionHookSync(child: ChildNode): void; } export {};