Skip to content

Commit

Permalink
Merge pull request #66 from c4spar/fix-trim-with-filter
Browse files Browse the repository at this point in the history
fix(trim): trim end not working with pipes
  • Loading branch information
oscarotero authored Jun 9, 2024
2 parents 43e67e9 + d59fd1c commit 7e7abe2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/trim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 17 additions & 0 deletions test/print.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e7abe2

Please sign in to comment.