Skip to content

Commit e167201

Browse files
build(html): correct what the sweep expects around template syntax (#22192)
* build(html): correct what the sweep expects around template syntax The three `{%` entries all claimed the tag was echoed from source whole. That stopped being true when the print began rebuilding such a tag's attributes, so the reference entry matched nothing and was reported stale. What the remaining two report is the respelling writing `=""` onto a bare name: a tag carrying template syntax keeps the empty value the print drops elsewhere. State that, and drop the entry nothing matches. * test(html): pin the empty value a template-bearing tag keeps * test(html): drive the kept empty value through a real build too
1 parent c01042d commit e167201

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎test/configCases/html/minimize-attributes/__snapshots__/ConfigCacheTest.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ b\\">newline in a value</p>
3737
<input type=checkbox {% if on %} checked {% endif %}>
3838
<li class=row {% for x in y %} data-x=1 {% endfor %}>a block over a list</li>
3939
<input type=text {%- if isRequired -%} required{%- endif -%}>
40+
<input type=text {% if on %} a{% endif %}=\\"\\">
4041
<p class=\\"btn{% if active %} btn-active{% endif %}\\">the same list, as text</p>
4142
<p data-slash=/end/>value ending in a slash</p>
4243
<a href=x/>unquoted value ending in a slash</a>

‎test/configCases/html/minimize-attributes/__snapshots__/ConfigTest.snap‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ b\\">newline in a value</p>
3737
<input type=checkbox {% if on %} checked {% endif %}>
3838
<li class=row {% for x in y %} data-x=1 {% endfor %}>a block over a list</li>
3939
<input type=text {%- if isRequired -%} required{%- endif -%}>
40+
<input type=text {% if on %} a{% endif %}=\\"\\">
4041
<p class=\\"btn{% if active %} btn-active{% endif %}\\">the same list, as text</p>
4142
<p data-slash=/end/>value ending in a slash</p>
4243
<a href=x/>unquoted value ending in a slash</a>

‎test/configCases/html/minimize-attributes/page.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<input type="checkbox"{% if on %} checked="checked"{% endif %}>
5454
<li class="row"{% for x in y %} data-x="1"{% endfor %}>a block over a list</li>
5555
<input type="text"{%- if isRequired -%} required{%- endif -%}>
56+
<input type="text"{% if on %} a{% endif %}="">
5657
<p class="btn{% if active %} btn-active{% endif %}">the same list, as text</p>
5758
<p data-slash="/end/">value ending in a slash</p>
5859
<a href=x/>unquoted value ending in a slash</a>

‎test/unitCases/HtmlSyntax.unittest.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5720,6 +5720,18 @@ describe("SourceProcessor — a duplicate attribute name", () => {
57205720
}
57215721
});
57225722

5723+
it("keeps an empty value written onto a name the block spells", () => {
5724+
// What the sweep's two surviving `{%` expectations report: the print drops
5725+
// `=""` elsewhere, and a tag carrying template syntax keeps what was written.
5726+
expect(minify('<p a="">t</p>')).toBe("<p a>t");
5727+
expect(minify('<input type="text"{% if x %} a{% endif %}="">')).toBe(
5728+
'<input type=text {% if x %} a{% endif %}="">'
5729+
);
5730+
expect(minify("<input type='text'{% if x %} a{% endif %}=''>")).toBe(
5731+
"<input type=text {% if x %} a{% endif %}=''>"
5732+
);
5733+
});
5734+
57235735
it("preserves case-sensitive template names", () => {
57245736
for (const condition of ["isRequired", "Foo", "options.isRequired"]) {
57255737
const printed = minify(

‎tooling/compare-html-tools.js‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,17 +1384,12 @@ const EXPECTED = [
13841384
{
13851385
relation: "respelling quote-double",
13861386
contains: "{%",
1387-
why: "a tag whose duplicate attribute names HTML parsing drops is echoed from source: rebuilding it would print the drop (#22013)"
1387+
why: 'the respelling writes `=""` onto a bare name, and a tag carrying template syntax keeps the empty value this print drops elsewhere, so the two spellings differ by the 3 bytes the respelling added'
13881388
},
13891389
{
13901390
relation: "respelling quote-single",
13911391
contains: "{%",
1392-
why: "the same echo, reached through the other delimiter"
1393-
},
1394-
{
1395-
relation: "respelling references",
1396-
contains: "{%",
1397-
why: "the same echo, which also leaves the tag's other values spelled as the source wrote them"
1392+
why: "the same kept value, reached through the other delimiter"
13981393
}
13991394
];
14001395

0 commit comments

Comments
 (0)