From d59fd1cd94bc441595b0b6fc950c5bba6515931d Mon Sep 17 00:00:00 2001 From: Benjamin Fischer Date: Sun, 9 Jun 2024 13:17:34 +0200 Subject: [PATCH] fix(trim): trim end not working with pipes --- plugins/trim.ts | 2 +- test/print.test.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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