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: Support "only" modifier in embed statements #119

Merged
merged 1 commit into from
Feb 1, 2025
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
### Features
- [GH-61](https://github.com/zackad/prettier-plugin-twig/issues/61#issuecomment-2596726423) Add support for twig comment as html element attribute

### Internal
### Bugfixes
- Fix broken embed statement with `only` modifier

### Internals
- Stringify ast object to make it easier to inspect when debugging on test setup

---
Expand Down
3 changes: 3 additions & 0 deletions src/print/EmbedStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const printOpener = (node, path, print) => {
if (node.argument) {
parts.push(indent([line, "with ", path.call(print, "argument")]));
}
if (node.contextFree) {
parts.push(" only");
}
parts.push([line, node.trimRightEmbed ? "-%}" : "%}"]);
return group(parts);
};
Expand Down
4 changes: 2 additions & 2 deletions tests/Failing/__snapshots__/failing.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
}
%}

{# "only" dropped, comment dropped #}
{# comment dropped #}
{% embed '@hotelsearch/common/tooltip/tooltip.twig'
with {
position: 'bottomTrailing',
id: 'most-popular-badge',
classList: tooltipOpen ? 'show-tooltip',
isAriaHidden: not (tooltipOpen ?? false)
}
} only
%}
{% block text %}
<p>
Expand Down
2 changes: 1 addition & 1 deletion tests/Failing/failing.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
%}

{# "only" dropped, comment dropped #}
{# comment dropped #}
{% embed '@hotelsearch/common/tooltip/tooltip.twig' with {
position: 'bottomTrailing',
id: 'most-popular-badge',
Expand Down
2 changes: 1 addition & 1 deletion tests/IncludeEmbed/__snapshots__/embed.snap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- embed 'foo.twig'
with {
foo: 'bar'
}
} only
%}
{% block hello %}
{{ fun }}
Expand Down
2 changes: 1 addition & 1 deletion tests/IncludeEmbed/embed.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block hello %}
<div class="test-{{ foo }} bar">
{%- embed "foo.twig" with { foo: 'bar' } %}
{%- embed "foo.twig" with { foo: 'bar' } only %}
{% block hello %}
{{ fun }}
{% embed "bar.twig" -%}
Expand Down