Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Make sure that empty block will have empty line in between #85

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ __Example__

{{ 'Hello %s %s!'|format(...['Fabien', 'Potencier']) }}
```

### Bugfixes
- Make sure that empty block statement will have empty line in between for consistency

---
## 0.11.1 (2024-11-13)

Expand Down
11 changes: 7 additions & 4 deletions src/print/BlockStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const p = (node, path, print, options) => {
node.trimRightBlock ? " -%}" : " %}"
];
const parts = [opener];

if (node.body.length === 0) {
parts.push(hardline);
}

if (node.body.length > 0) {
const indentedBody = printChildBlock(node, path, print, "body");
parts.push(indentedBody);
Expand All @@ -30,18 +35,16 @@ const p = (node, path, print, options) => {
node.trimRight ? " -%}" : " %}"
);

const result = group(parts);
return result;
return group(parts);
} else if (Node.isPrintExpressionStatement(node.body)) {
const parts = [
return [
node.trimLeft ? "{%-" : "{%",
" block ",
path.call(print, "name"),
" ",
path.call(print, "body", "value"),
node.trimRight ? " -%}" : " %}"
];
return parts;
}
};

Expand Down
15 changes: 14 additions & 1 deletion tests/IncludeEmbed/__snapshots__/block.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,20 @@

{{ block('hello') }}

{% block content %}
{% block content_empty %}

{% endblock %}

{% block content_noline %}

{% endblock %}

{% block content_multiline %}

{% endblock %}

{% block content_empty_indented %}

{% endblock %}

{%- block hello -%}
Expand Down
16 changes: 15 additions & 1 deletion tests/IncludeEmbed/block.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@

{{ block('hello') }}

{% block content %}{% endblock %}
{% block content_empty %}{% endblock %}

{% block content_noline %}
{% endblock %}

{% block content_multiline %}





{% endblock %}

{% block content_empty_indented %}
{% endblock %}

{%- block hello -%}
Hello
Expand Down