private void ProcessAttributes(TagHelperIntermediateNode node) { for (var i = node.Children.Count - 1; i >= 0; i--) { if (node.Children[i] is TagHelperPropertyIntermediateNode propertyNode) { if (HasComplexChildContent(propertyNode)) { node.Diagnostics.Add(BlazorDiagnosticFactory.Create_UnsupportedComplexContent( propertyNode, propertyNode.AttributeName)); node.Children.RemoveAt(i); continue; } node.Children[i] = new ComponentAttributeExtensionNode(propertyNode); } else if (node.Children[i] is TagHelperHtmlAttributeIntermediateNode htmlNode) { if (HasComplexChildContent(htmlNode)) { node.Diagnostics.Add(BlazorDiagnosticFactory.Create_UnsupportedComplexContent( htmlNode, htmlNode.AttributeName)); node.Children.RemoveAt(i); continue; } } } }
private void ProcessAttributes(TagHelperIntermediateNode node) { for (var i = node.Children.Count - 1; i >= 0; i--) { if (node.Children[i] is TagHelperPropertyIntermediateNode propertyNode) { if (TrySimplifyContent(propertyNode) && node.TagHelpers.Any(t => t.IsComponentTagHelper())) { node.Diagnostics.Add(BlazorDiagnosticFactory.Create_UnsupportedComplexContent( propertyNode, propertyNode.AttributeName)); node.Children.RemoveAt(i); continue; } } else if (node.Children[i] is TagHelperHtmlAttributeIntermediateNode htmlNode) { if (TrySimplifyContent(htmlNode) && node.TagHelpers.Any(t => t.IsComponentTagHelper())) { node.Diagnostics.Add(BlazorDiagnosticFactory.Create_UnsupportedComplexContent( htmlNode, htmlNode.AttributeName)); node.Children.RemoveAt(i); continue; } } } }
private void RewriteUsage(TagHelperIntermediateNode node, TagHelperDescriptor tagHelper) { // Ignore Kind here. Some versions of Razor have a bug in the serializer that ignores it. // We need to surround the contents of the node with open and close nodes to ensure the component // is scoped correctly. node.Children.Insert(0, new ComponentOpenExtensionNode() { TypeName = tagHelper.GetTypeName(), }); for (var i = node.Children.Count - 1; i >= 0; i--) { if (node.Children[i] is TagHelperBodyIntermediateNode bodyNode) { // Replace with a node that we recognize so that it we can do proper scope tracking. // // Note that we force the body node to be last, this is done to push it after the // attribute nodes. This gives us the ordering we want for the render tree. node.Children.RemoveAt(i); node.Children.Add(new ComponentBodyExtensionNode(bodyNode) { TagMode = node.TagMode, TagName = node.TagName, }); } } node.Children.Add(new ComponentCloseExtensionNode()); // Now we need to rewrite any set property or HTML nodes to call the appropriate AddAttribute api. for (var i = node.Children.Count - 1; i >= 0; i--) { if (node.Children[i] is TagHelperPropertyIntermediateNode propertyNode && propertyNode.TagHelper == tagHelper) { // We don't support 'complex' content for components (mixed C# and markup) right now. // It's not clear yet if Blazor will have a good scenario to use these constructs. // // This is where a lot of the complexity in the Razor/TagHelpers model creeps in and we // might be able to avoid it if these features aren't needed. if (HasComplexChildContent(propertyNode)) { node.Diagnostics.Add(BlazorDiagnosticFactory.Create_UnsupportedComplexContent( propertyNode, propertyNode.AttributeName)); node.Children.RemoveAt(i); continue; } node.Children[i] = new ComponentAttributeExtensionNode(propertyNode); }