cleanup statements if they only contain whitespace

This commit is contained in:
davidodenwald 2023-05-07 14:33:06 +02:00
parent 60a2cc487e
commit d72173d3fe
3 changed files with 15 additions and 0 deletions

View file

@ -228,6 +228,14 @@ const buildBlock = (
block: Block, block: Block,
mapped: (string | builders.Doc[] | builders.DocCommand)[] mapped: (string | builders.Doc[] | builders.DocCommand)[]
): builders.Doc => { ): builders.Doc => {
// if the content is empty or whitespace only.
if (block.content.match(/^\s*$/)) {
return builders.fill([
path.call(print, "nodes", block.start.id),
builders.softline,
path.call(print, "nodes", block.end.id),
]);
}
if (block.containsNewLines) { if (block.containsNewLines) {
return builders.group([ return builders.group([
path.call(print, "nodes", block.start.id), path.call(print, "nodes", block.start.id),

View file

@ -0,0 +1,2 @@
{% block title %}
{% endblock %}

View file

@ -0,0 +1,5 @@
{% block title %}
{% endblock %}