Templates 2.0 (#636)
Templates 2.0 and a whole bunch of other refactoring
This commit is contained in:
@@ -11,6 +11,12 @@ export const builtinFunctions: FunctionMap = {
|
||||
min(...args: number[]) {
|
||||
return Math.min(...args);
|
||||
},
|
||||
replace(str: string, match: [string, string] | string, replace: string) {
|
||||
const matcher = Array.isArray(match)
|
||||
? new RegExp(match[0], match[1] + "g")
|
||||
: match;
|
||||
return str.replaceAll(matcher, replace);
|
||||
},
|
||||
toJSON(obj: any) {
|
||||
return JSON.stringify(obj);
|
||||
},
|
||||
|
||||
@@ -191,7 +191,10 @@ export function nodeAtPos(tree: ParseTree, pos: number): ParseTree | null {
|
||||
}
|
||||
|
||||
// Turn ParseTree back into text
|
||||
export function renderToText(tree: ParseTree): string {
|
||||
export function renderToText(tree?: ParseTree): string {
|
||||
if (!tree) {
|
||||
return "";
|
||||
}
|
||||
const pieces: string[] = [];
|
||||
if (tree.text !== undefined) {
|
||||
return tree.text;
|
||||
|
||||
Reference in New Issue
Block a user