Skip to content

Commit 1d75746

Browse files
test(html): cover the tag shapes a {% template writes (#22183)
* test(html): cover the tag shapes a `{%` template writes The suite drove one spelling of one block. It drives the tight and the whitespace-control ones too now, a `{% for %}` over a list, two blocks in one tag, and what the block wraps being minified rather than echoed. A block written against the element name is covered as the pitfall it is: a tag name runs to the first whitespace, so `<span{%` names an element nothing closes. * test(html): leave the config fixture to the fix it exposed The `{% if %}` lines around a `checked="checked"` print a tag whose bare name fuses with the template, which is a defect in the printer rather than a case this branch can state. They move to the change that fixes it.
1 parent a302da0 commit 1d75746

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

‎test/unitCases/HtmlSyntax.unittest.js‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5746,6 +5746,50 @@ describe("SourceProcessor — a duplicate attribute name", () => {
57465746
minify('<p onclick="a &amp;&amp; b()"{% if x %} a{% endif %}>t</p>')
57475747
).toBe('<p onclick="a && b()"{% if x %} a{% endif %}>t');
57485748
});
5749+
5750+
it("keeps the block however the engine spells its delimiters", () => {
5751+
// Jinja, Nunjucks, Liquid and Twig close with a word rather than a `/`, and
5752+
// admit the tight and the whitespace-control spelling beside the spaced one.
5753+
expect(minify('<input type="text"{%if required%} required{%endif%}>')).toBe(
5754+
"<input type=text {%if required%} required{%endif%}>"
5755+
);
5756+
expect(
5757+
minify('<input type="text"{%- if required -%} required{%- endif -%}>')
5758+
).toBe("<input type=text {%- if required -%} required{%- endif -%}>");
5759+
expect(
5760+
minify('<li class="row"{% for x in y %} data-x="1"{% endfor %}>t</li>')
5761+
).toBe("<li class=row {% for x in y %} data-x=1 {% endfor %}>t");
5762+
// Two blocks in one tag, the second opening where the first closed.
5763+
expect(
5764+
minify(
5765+
'<input type="text"{% if a %} required{% endif %}{% if b %} disabled{% endif %}>'
5766+
)
5767+
).toBe(
5768+
"<input type=text {% if a %} required{% endif %}{% if b %} disabled{% endif %}>"
5769+
);
5770+
});
5771+
5772+
it("minifies the attributes the block is written around", () => {
5773+
// What rebuilding the tag buys over echoing it: an attribute inside the
5774+
// block is minified like any other, the boolean and the list alike.
5775+
expect(
5776+
minify('<input type="checkbox"{% if on %} checked="checked"{% endif %}>')
5777+
).toBe("<input type=checkbox {% if on %} checked{% endif %}>");
5778+
expect(
5779+
minify('<p class=" a b "{% if wide %} data-c="2"{% endif %}>t</p>')
5780+
).toBe('<p class="a b"{% if wide %} data-c=2 {% endif %}>t');
5781+
});
5782+
5783+
it("reads a block written against the element name as part of it", () => {
5784+
// A tag name runs to the first ASCII whitespace, `/` or `>`, so `<span{%`
5785+
// names an element nothing closes: the space is the template's to write.
5786+
expect(minify('<span{% if x %} title="a"{% endif %}>t</span>')).toBe(
5787+
"<span{% if x %} title=a {% endif %}>t</span{%>"
5788+
);
5789+
expect(minify('<span {% if x %} title="a"{% endif %}>t</span>')).toBe(
5790+
"<span {% if x %} title=a {% endif %}>t</span>"
5791+
);
5792+
});
57495793
});
57505794

57515795
describe("SourceProcessor — token list values", () => {

0 commit comments

Comments
 (0)