fix(ivy): allow HTML comments to be present inside <ng-content> (#28849)
Prior to this change presence of HTML comments inside <ng-content> caused compiler to throw an error that <ng-content> is not empty. Now HTML comments are not considered as a meaningful content, thus no error is thrown. This behavior is now aligned in Ivy/VE. PR Close #28849
This commit is contained in:

committed by
Igor Minar

parent
df627e65df
commit
95d9aa22ef
@ -156,7 +156,9 @@ class HtmlAstToIvyAst implements html.Visitor {
|
||||
let parsedElement: t.Node|undefined;
|
||||
if (preparsedElement.type === PreparsedElementType.NG_CONTENT) {
|
||||
// `<ng-content>`
|
||||
if (element.children && !element.children.every(isEmptyTextNode)) {
|
||||
if (element.children &&
|
||||
!element.children.every(
|
||||
(node: html.Node) => isEmptyTextNode(node) || isCommentNode(node))) {
|
||||
this.reportError(`<ng-content> element cannot have content.`, element.sourceSpan);
|
||||
}
|
||||
const selector = preparsedElement.selectAttr;
|
||||
@ -413,3 +415,7 @@ function addEvents(events: ParsedEvent[], boundEvents: t.BoundEvent[]) {
|
||||
function isEmptyTextNode(node: html.Node): boolean {
|
||||
return node instanceof html.Text && node.value.trim().length == 0;
|
||||
}
|
||||
|
||||
function isCommentNode(node: html.Node): boolean {
|
||||
return node instanceof html.Comment;
|
||||
}
|
||||
|
Reference in New Issue
Block a user