mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-18 15:00:00 +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()}");
|
const result = await renderTemplate("{foo} {bar()}");
|
||||||
// No "Unclosed function" exception = success
|
// 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 = () => {
|
const dumpArg = () => {
|
||||||
if (!currentVar) return;
|
if (!currentVar) return;
|
||||||
|
|
||||||
if (currentVar._state.currentArg !== null && currentVar._state.currentArg !== "") {
|
if (currentVar._state.currentArgType) {
|
||||||
if (currentVar._state.currentArgType === "number") {
|
if (currentVar._state.currentArgType === "number") {
|
||||||
if (isNaN(currentVar._state.currentArg as any)) {
|
if (isNaN(currentVar._state.currentArg as any)) {
|
||||||
throw new TemplateParseError(`Invalid numeric argument: ${currentVar._state.currentArg}`);
|
throw new TemplateParseError(`Invalid numeric argument: ${currentVar._state.currentArg}`);
|
||||||
|
@ -272,6 +272,9 @@ const baseValues = {
|
||||||
not(arg) {
|
not(arg) {
|
||||||
return !arg;
|
return !arg;
|
||||||
},
|
},
|
||||||
|
concat(...args) {
|
||||||
|
return [...args].join("");
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function renderTemplate(template: string, values = {}, includeBaseValues = true) {
|
export async function renderTemplate(template: string, values = {}, includeBaseValues = true) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue