diff --git a/plugins/trim.ts b/plugins/trim.ts index 7eedd00..6d730fc 100644 --- a/plugins/trim.ts +++ b/plugins/trim.ts @@ -20,7 +20,7 @@ export function trim(_: Environment, tokens: Token[]) { code = code.slice(1); } - if (type === "tag" && code.endsWith("-")) { + if ((type === "tag" || type === "filter") && code.endsWith("-")) { next[1] = next[1].trimStart(); code = code.slice(0, -1); } diff --git a/test/print.test.ts b/test/print.test.ts index 6e83ef0..4d9758f 100644 --- a/test/print.test.ts +++ b/test/print.test.ts @@ -96,6 +96,23 @@ Deno.test("Print trim", async () => { }); }); +Deno.test("Print trim with filter", async () => { + await test({ + template: `Hello {{- "World" |> toUpperCase }} !`, + expected: "HelloWORLD !", + }); + + await test({ + template: `Hello {{ "World" |> toUpperCase -}} !`, + expected: "Hello WORLD!", + }); + + await test({ + template: `Hello {{- "World" |> toUpperCase -}} !`, + expected: "HelloWORLD!", + }); +}); + Deno.test({ name: "Print async filters", // @ts-ignore only used to detect node.js