fix: ensure only child optimization ignores comments (#3012)

* fix: ensure only child optimization ignores comments

* chore: add changeset
This commit is contained in:
Luke LaValva 2025-12-17 12:53:31 -08:00 committed by GitHub
parent 9b26913239
commit 7ec9683b16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"@marko/runtime-tags": patch
---
Ignore comments for only child conditional optimization

View File

@ -9,7 +9,7 @@ export default _._template("__tests__/template.marko", input => {
_._html(`<span>${_._escape(value)}${_._el_resume($scope1_id, "#text/0")}</span>`);
_._scope($scope1_id, {
_: _._scope_with_id($scope0_id)
}, "__tests__/template.marko", "3:4");
}, "__tests__/template.marko", "4:4");
return 0;
}
}, $scope0_id, "#div/0", 1, /* value */1, /* value */1, "</div>", 1);

View File

@ -1,5 +1,6 @@
<let/value=input.value>
<div>
// This comment shouldn't count as a child!
<if=value>
<span>${value}</span>
</if>

View File

@ -29,7 +29,9 @@ export function getOnlyChildParentTagName(
parentTag &&
getTagDef(parentTag)?.html &&
parentTag.node.name.type === "StringLiteral" &&
(tag.parent as t.MarkoTagBody).body.length === branchSize
(tag.parent as t.MarkoTagBody).body.filter(
(node) => node.type !== "MarkoComment",
).length === branchSize
? parentTag.node.name.value
: false);
}