Skip to content

Commit 39d6be1

Browse files
committed
fix: Fix liquid conditions
1 parent 5a0e8aa commit 39d6be1

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/transform/liquid/conditions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function inlineConditions(
205205

206206
return {
207207
result: start + result + end,
208-
lastIndex: start.length + result.length,
208+
lastIndex: start.length + result.length - tailLinebreak(ifTag.rawEnd).length,
209209
ifCon,
210210
};
211211
}

test/liquid/conditions.test.ts

+36
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,42 @@ describe('Conditions', () => {
217217
{% endnote %}
218218
`);
219219
});
220+
221+
test('Falsy block condition after truthly block condition', () => {
222+
expect(
223+
conditions(
224+
trim`
225+
Start
226+
227+
Before
228+
{% if product == "A" %}
229+
Truthly
230+
{% endif %}
231+
{% if product == "B" %}
232+
Falsy
233+
{% endif %}
234+
After
235+
236+
End
237+
`,
238+
{
239+
product: 'A',
240+
},
241+
'',
242+
{
243+
sourceMap: {},
244+
},
245+
),
246+
).toEqual(trim`
247+
Start
248+
249+
Before
250+
Truthly
251+
After
252+
253+
End
254+
`);
255+
});
220256
});
221257

222258
describe('Conditions', () => {

0 commit comments

Comments
 (0)