diff --git a/src/templateFormatter.test.ts b/src/templateFormatter.test.ts index 62af828b..366be4ac 100644 --- a/src/templateFormatter.test.ts +++ b/src/templateFormatter.test.ts @@ -99,3 +99,13 @@ test("Edge case #1", async () => { const result = await renderTemplate("{foo} {bar()}"); // No "Unclosed function" exception = success }); + +test("Parses empty string args as empty strings", async () => { + const result = parseTemplate('{foo("")}'); + expect(result).toEqual([ + { + identifier: "foo", + args: [""], + }, + ]); +}); diff --git a/src/templateFormatter.ts b/src/templateFormatter.ts index d5351584..376c85ba 100644 --- a/src/templateFormatter.ts +++ b/src/templateFormatter.ts @@ -59,7 +59,7 @@ export function parseTemplate(str: string): ParsedTemplate { const dumpArg = () => { if (!currentVar) return; - if (currentVar._state.currentArg !== null && currentVar._state.currentArg !== "") { + if (currentVar._state.currentArgType) { if (currentVar._state.currentArgType === "number") { if (isNaN(currentVar._state.currentArg as any)) { throw new TemplateParseError(`Invalid numeric argument: ${currentVar._state.currentArg}`); @@ -272,6 +272,9 @@ const baseValues = { not(arg) { return !arg; }, + concat(...args) { + return [...args].join(""); + }, }; export async function renderTemplate(template: string, values = {}, includeBaseValues = true) {