Skip to content

Commit

Permalink
fix: Fix liquid conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed May 29, 2024
1 parent 8190acb commit 3f7603d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/transform/liquid/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export = function conditions(

// Consumes all between curly braces
// and all closest upon to first linebreak before and after braces.
const R_LIQUID = /((?:\n\s*)?{%-?([\s\S]*?)-?%}(?:\s*\n)?)/g;
const R_LIQUID = /((?:\n[\t ]*)?{%-?([\s\S]*?)-?%}(?:[\t ]*\n)?)/g;

let match;
while ((match = R_LIQUID.exec(input)) !== null) {
Expand Down
31 changes: 31 additions & 0 deletions test/liquid/conditions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,37 @@ describe('Conditions', () => {
Postfix
`);
});

test('Condition inside the cut block with multiple linebreaks', () => {
expect(
conditions(
trim`
{% cut "Title" %}
{% if locale == 'ru' %}
a
{% endif %}
{% endcut %}
`,
{locale: 'ru'},
'',
{
sourceMap: {},
},
),
).toEqual(trim`
{% cut "Title" %}
a
{% endcut %}
`);
});
});
});

Expand Down

0 comments on commit 3f7603d

Please sign in to comment.