muban-convert-hbs
Version:
Convert muban hbs templates to htl, django, twig and others.
72 lines (71 loc) • 2.21 kB
TypeScript
export declare type ReplacementMap = {
[key: string]: string;
};
/**
* Holds information about the current Handlebars Context.
* A new context is created when traversing inside a block that introduces new variables, e.g. 'each'
*
* Creating a child context is done by calling context.createChildContext([variables in scope]).
* This will clone the current context, append the new scope, and increase the depth
*/
export default class Context {
/**
* A list of scopes, length should correspond with `depth-1`
*/
private scopes;
/**
* Context depth, will be increased when creating a child context
*/
private depth;
/**
* object will be shared between parent and child contexts
*/
shared: {
ifCounter: number;
};
constructor();
/**
* Add new values to the context and return the new context. The current context remains untouched.
* @param {string[]} variables
* @param replacements
* @return {Context} A new context.
*/
createChildContext(variables: Array<string>, replacements?: ReplacementMap): Context;
/**
* Gets the scope for a given depth
*
* @param {number} depth
* @return {Scope}
*/
private getScope(depth);
getCurrentScope(): Scope;
/**
* Gets all the available variables available in the scopes up to the given depth.
* Can be used to see if a variable is explicitly referencing a scope variable
* @param {number} depth
* @return {Array<string>}
*/
getScopesToDepth(depth: number): {
variables: Array<string>;
replacements: Array<ReplacementMap>;
};
getScopedVariable(path: hbs.AST.PathExpression): any;
clone(): Context;
}
/**
* Internal scope class, created when increasing the context depth.
* Contains all the variables in the new scope.
*/
export declare class Scope {
iterationType: string;
variables: Array<string>;
replacements: ReplacementMap;
value: string;
key: string;
constructor(variables: Array<string>, replacements?: ReplacementMap);
iterateAsObject(): void;
}
export declare enum IterationType {
ARRAY = "array",
OBJECT = "object",
}