From 39d6be1aff7eca4688efeff345dd3885978ba331 Mon Sep 17 00:00:00 2001 From: 3y3 <3y3@ya.ru> Date: Tue, 4 Jun 2024 17:32:24 +0300 Subject: [PATCH] fix: Fix liquid conditions --- src/transform/liquid/conditions.ts | 2 +- test/liquid/conditions.test.ts | 36 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/transform/liquid/conditions.ts b/src/transform/liquid/conditions.ts index 5fa44f4a..ad3e8b39 100644 --- a/src/transform/liquid/conditions.ts +++ b/src/transform/liquid/conditions.ts @@ -205,7 +205,7 @@ function inlineConditions( return { result: start + result + end, - lastIndex: start.length + result.length, + lastIndex: start.length + result.length - tailLinebreak(ifTag.rawEnd).length, ifCon, }; } diff --git a/test/liquid/conditions.test.ts b/test/liquid/conditions.test.ts index eb405b1c..548a28f9 100644 --- a/test/liquid/conditions.test.ts +++ b/test/liquid/conditions.test.ts @@ -217,6 +217,42 @@ describe('Conditions', () => { {% endnote %} `); }); + + test('Falsy block condition after truthly block condition', () => { + expect( + conditions( + trim` + Start + + Before + {% if product == "A" %} + Truthly + {% endif %} + {% if product == "B" %} + Falsy + {% endif %} + After + + End + `, + { + product: 'A', + }, + '', + { + sourceMap: {}, + }, + ), + ).toEqual(trim` + Start + + Before + Truthly + After + + End + `); + }); }); describe('Conditions', () => {