mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
templateFormatter: fix empty string args not getting counted as arguments; add concat base template function
This commit is contained in:
parent
f7f08ffd3b
commit
8f898ed972
2 changed files with 14 additions and 1 deletions
|
@ -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: [""],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue