diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BindLoweringPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BindLoweringPass.cs index 59c20de758..02889979a7 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BindLoweringPass.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BindLoweringPass.cs @@ -479,7 +479,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor if (template != null) { // See comments in TemplateDiagnosticPass - node.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(template.Source)); + node.Diagnostics.Add(BlazorDiagnosticFactory.Create_TemplateInvalidLocation(template.Source)); return new IntermediateToken() { Kind = TokenKind.CSharp, Content = string.Empty, }; } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs index 0e52a2aa2f..a12a7505eb 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs @@ -348,18 +348,23 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.RenderNode(attribute); } - // We need to be aware of the blazor scope-tracking concept in design-time code generation - // because each component creates a lambda scope for its child content. - // - // We're hacking it a bit here by just forcing every component to have an empty lambda - _scopeStack.OpenComponentScope(node.TagName); - _scopeStack.IncrementCurrentScopeChildCount(context); - - foreach (var child in node.Body) + if (node.ChildContents.Any()) { - context.RenderNode(child); + foreach (var childContent in node.ChildContents) + { + context.RenderNode(childContent); + } + } + else + { + // We eliminate 'empty' child content when building the tree so that usage like + // '\r\n' doesn't create a child content. + // + // Consider what would happen if the user's cursor was inside the element. At + // design -time we want to render an empty lambda to provide proper scoping + // for any code that the user types. + context.RenderNode(new ComponentChildContentIntermediateNode()); } - _scopeStack.CloseScope(context); foreach (var capture in node.Captures) { @@ -398,34 +403,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor { // Do nothing } - else if (node.Children.Count == 1 && node.Children[0] is TemplateIntermediateNode template) - { - // Templates are represented as lambdas assignable for RenderFragment (for some T). - // We don't have a type to write down unless its bound to a stronly typed attribute. - // That's OK because the compiler gives an error if we can't type check it. - context.CodeWriter.Write(DesignTimeVariable); - context.CodeWriter.Write(" = "); - - // If we have a parameter type, then add a type check. - if (NeedsTypeCheck(node)) - { - context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck); - context.CodeWriter.Write("<"); - context.CodeWriter.Write(node.BoundAttribute.TypeName); - context.CodeWriter.Write(">"); - context.CodeWriter.Write("("); - } - - context.RenderNode(template); - - if (NeedsTypeCheck(node)) - { - context.CodeWriter.Write(")"); - } - - context.CodeWriter.Write(";"); - context.CodeWriter.WriteLine(); - } else { // There are a few different forms that could be used to contain all of the tokens, but we don't really care @@ -440,7 +417,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor // Of a list of tokens directly in the attribute. var tokens = GetCSharpTokens(node); - if (node.BoundAttribute?.IsDelegateProperty() ?? false) + if ((node.BoundAttribute?.IsDelegateProperty() ?? false) || + (node.BoundAttribute?.IsChildContentProperty() ?? false)) { // We always surround the expression with the delegate constructor. This makes type // inference inside lambdas, and method group conversion do the right thing. @@ -502,6 +480,30 @@ namespace Microsoft.AspNetCore.Blazor.Razor } } + public override void WriteComponentChildContent(CodeRenderingContext context, ComponentChildContentIntermediateNode node) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (node == null) + { + throw new ArgumentNullException(nameof(node)); + } + + _scopeStack.OpenComponentScope( + context, + node.AttributeName, + node.TypeName, + node.IsParameterized ? node.ParameterName : null); + for (var i = 0; i < node.Children.Count; i++) + { + context.RenderNode(node.Children[i]); + } + _scopeStack.CloseScope(context); + } + public override void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node) { if (context == null) @@ -514,11 +516,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - // Since the user doesn't write this name themselves, we have to use something hardcoded - // and predicatable. - const string VariableName = "context"; - - _scopeStack.OpenTemplateScope(context, VariableName); + _scopeStack.OpenTemplateScope(context); context.RenderChildren(node); _scopeStack.CloseScope(context); } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs index b12218c607..9b326e24e9 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.AspNetCore.Razor.Language; @@ -178,15 +179,89 @@ namespace Microsoft.AspNetCore.Blazor.Razor return diagnostic; } - public static readonly RazorDiagnosticDescriptor Template_InvalidLocation = + public static readonly RazorDiagnosticDescriptor TemplateInvalidLocation = new RazorDiagnosticDescriptor( "BL9994", () => "Razor templates cannot be used in attributes.", RazorDiagnosticSeverity.Error); - public static RazorDiagnostic CreateTemplate_InvalidLocation(SourceSpan? source) + public static RazorDiagnostic Create_TemplateInvalidLocation(SourceSpan? source) { - return RazorDiagnostic.Create(Template_InvalidLocation, source ?? SourceSpan.Undefined); + return RazorDiagnostic.Create(TemplateInvalidLocation, source ?? SourceSpan.Undefined); + } + + public static readonly RazorDiagnosticDescriptor ChildContentSetByAttributeAndBody = + new RazorDiagnosticDescriptor( + "BL9995", + () => "The child content property '{0}' is set by both the attribute and the element contents.", + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic Create_ChildContentSetByAttributeAndBody(SourceSpan? source, string attribute) + { + return RazorDiagnostic.Create(ChildContentSetByAttributeAndBody, source ?? SourceSpan.Undefined, attribute); + } + + public static readonly RazorDiagnosticDescriptor ChildContentMixedWithExplicitChildContent = + new RazorDiagnosticDescriptor( + "BL9996", + () => "Unrecognized child content inside component '{0}'. The component '{0}' accepts child content through the " + + "following top-level items: {1}.", + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic Create_ChildContentMixedWithExplicitChildContent(SourceSpan? source, ComponentExtensionNode component) + { + var supportedElements = string.Join(", ", component.Component.GetChildContentProperties().Select(p => $"'{p.Name}'")); + return RazorDiagnostic.Create(ChildContentMixedWithExplicitChildContent, source ?? SourceSpan.Undefined, component.TagName, supportedElements); + } + + public static readonly RazorDiagnosticDescriptor ChildContentHasInvalidAttribute = + new RazorDiagnosticDescriptor( + "BL9997", + () => "Unrecognized attribute '{0}' on child content element '{1}'.", + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic Create_ChildContentHasInvalidAttribute(SourceSpan? source, string attribute, string element) + { + return RazorDiagnostic.Create(ChildContentHasInvalidAttribute, source ?? SourceSpan.Undefined, attribute, element); + } + + public static readonly RazorDiagnosticDescriptor ChildContentHasInvalidParameter = + new RazorDiagnosticDescriptor( + "BL9998", + () => "Invalid parameter name. The parameter name attribute '{0}' on child content element '{1}' can only include literal text.", + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic Create_ChildContentHasInvalidParameter(SourceSpan? source, string attribute, string element) + { + return RazorDiagnostic.Create(ChildContentHasInvalidParameter, source ?? SourceSpan.Undefined, attribute, element); + } + + public static readonly RazorDiagnosticDescriptor ChildContentRepeatedParameterName = + new RazorDiagnosticDescriptor( + "BL9999", + () => "The child content element '{0}' of component '{1}' uses the same parameter name ('{2}') as enclosing child content " + + "element '{3}' of component '{4}'. Specify the parameter name like: '<{0} Context=\"another_name\"> to resolve the ambiguity", + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic Create_ChildContentRepeatedParameterName( + SourceSpan? source, + ComponentChildContentIntermediateNode childContent1, + ComponentExtensionNode component1, + ComponentChildContentIntermediateNode childContent2, + ComponentExtensionNode component2) + { + Debug.Assert(childContent1.ParameterName == childContent2.ParameterName); + Debug.Assert(childContent1.IsParameterized); + Debug.Assert(childContent2.IsParameterized); + + return RazorDiagnostic.Create( + ChildContentRepeatedParameterName, + source ?? SourceSpan.Undefined, + childContent1.AttributeName, + component1.TagName, + childContent1.ParameterName, + childContent2.AttributeName, + component2.TagName); } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorExtensionInitializer.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorExtensionInitializer.cs index 73f3fc985d..9e856fd883 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorExtensionInitializer.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorExtensionInitializer.cs @@ -82,6 +82,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor builder.Features.Add(new RefLoweringPass()); builder.Features.Add(new BindLoweringPass()); builder.Features.Add(new TemplateDiagnosticPass()); + builder.Features.Add(new ChildContentDiagnosticPass()); builder.Features.Add(new HtmlBlockPass()); builder.Features.Add(new ComponentTagHelperDescriptorProvider()); diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorMetadata.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorMetadata.cs index 673ae9f504..648f94c42b 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorMetadata.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorMetadata.cs @@ -26,8 +26,19 @@ namespace Microsoft.AspNetCore.Blazor.Razor public readonly static string ChangeAttribute = "Blazor.Bind.ChangeAttribute"; } + public static class ChildContent + { + public static readonly string RuntimeName = "Blazor.None"; + + public static readonly string TagHelperKind = "Blazor.ChildContent"; + + public static readonly string ParameterNameBoundAttributeKind = "Blazor.ChildContentParameterName"; + } + public static class Component { + public static readonly string ChildContentKey = "Blazor.ChildContent"; + public static readonly string DelegateSignatureKey = "Blazor.DelegateSignature"; public static readonly string WeaklyTypedKey = "Blazor.IsWeaklyTyped"; diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs index 712e78861f..7642c9ed78 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs @@ -17,6 +17,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor public abstract void WriteComponentAttribute(CodeRenderingContext context, ComponentAttributeExtensionNode node); + public abstract void WriteComponentChildContent(CodeRenderingContext context, ComponentChildContentIntermediateNode node); + public abstract void WriteHtmlElement(CodeRenderingContext context, HtmlElementIntermediateNode node); public abstract void WriteHtmlBlock(CodeRenderingContext context, HtmlBlockIntermediateNode node); diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs index a2752b0b62..b5b4b96dc8 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs @@ -65,7 +65,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor { if (node.Children[i] is IntermediateToken token && token.IsCSharp) { - _scopeStack.IncrementCurrentScopeChildCount(context); context.AddSourceMappingFor(token); context.CodeWriter.Write(token.Content); } @@ -100,7 +99,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor // Since we're not in the middle of writing an element, this must evaluate as some // text to display - _scopeStack.IncrementCurrentScopeChildCount(context); context.CodeWriter .WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{nameof(BlazorApi.RenderTreeBuilder.AddContent)}") .Write((_sourceSequence++).ToString()) @@ -161,8 +159,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - _scopeStack.IncrementCurrentScopeChildCount(context); - context.CodeWriter .WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{nameof(BlazorApi.RenderTreeBuilder.AddMarkupContent)}") .Write((_sourceSequence++).ToString()) @@ -183,8 +179,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - _scopeStack.IncrementCurrentScopeChildCount(context); - context.CodeWriter .WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{nameof(BlazorApi.RenderTreeBuilder.OpenElement)}") .Write((_sourceSequence++).ToString()) @@ -267,7 +261,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor // Text node var content = GetHtmlContent(node); - _scopeStack.IncrementCurrentScopeChildCount(context); context.CodeWriter .WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{nameof(BlazorApi.RenderTreeBuilder.AddContent)}") .Write((_sourceSequence++).ToString()) @@ -303,9 +296,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - // The start tag counts as a child from a markup point of view. - _scopeStack.IncrementCurrentScopeChildCount(context); - // builder.OpenComponent(42); context.CodeWriter.Write(_scopeStack.BuilderVarName); context.CodeWriter.Write("."); @@ -321,22 +311,17 @@ namespace Microsoft.AspNetCore.Blazor.Razor { context.RenderNode(attribute); } - - _scopeStack.OpenComponentScope(node.TagName); - foreach (var child in node.Body) + + foreach (var childContent in node.ChildContents) { - context.RenderNode(child); + context.RenderNode(childContent); } - _scopeStack.CloseScope(context); foreach (var capture in node.Captures) { context.RenderNode(capture); } - // The close tag counts as a child from a markup point of view. - _scopeStack.IncrementCurrentScopeChildCount(context); - // builder.OpenComponent(42); context.CodeWriter.Write(_scopeStack.BuilderVarName); context.CodeWriter.Write("."); @@ -383,34 +368,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor var content = string.Join(string.Empty, GetHtmlTokens(htmlNode).Select(t => t.Content)); context.CodeWriter.WriteStringLiteral(content); } - else if (node.Children.Count == 1 && node.Children[0] is TemplateIntermediateNode template) - { - // Templates are represented as lambdas assignable for RenderFragment (for some T). - // We don't have a type to write down unless its bound to a stronly typed attribute. - // That's OK because the compiler gives an error if we can't type check it. - - // If we have a parameter type, then add a type check. - if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped()) - { - context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck); - context.CodeWriter.Write("<"); - context.CodeWriter.Write(node.BoundAttribute.TypeName); - context.CodeWriter.Write(">"); - context.CodeWriter.Write("("); - } - - context.RenderNode(template); - - if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped()) - { - context.CodeWriter.Write(")"); - } - } else { // See comments in BlazorDesignTimeNodeWriter for a description of the cases that are possible. var tokens = GetCSharpTokens(node); - if (node.BoundAttribute?.IsDelegateProperty() ?? false) + if ((node.BoundAttribute?.IsDelegateProperty() ?? false) || + (node.BoundAttribute?.IsChildContentProperty() ?? false)) { context.CodeWriter.Write("new "); context.CodeWriter.Write(node.BoundAttribute.TypeName); @@ -425,7 +388,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor } else { - if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped()) + if (NeedsTypeCheck(node)) { context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck); context.CodeWriter.Write("<"); @@ -439,7 +402,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.CodeWriter.Write(tokens[i].Content); } - if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped()) + if (NeedsTypeCheck(node)) { context.CodeWriter.Write(")"); } @@ -460,6 +423,35 @@ namespace Microsoft.AspNetCore.Blazor.Razor // We generally expect all children to be HTML, this is here just in case. return html.FindDescendantNodes().Where(t => t.IsHtml).ToArray(); } + + bool NeedsTypeCheck(ComponentAttributeExtensionNode n) + { + return node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped(); + } + } + + public override void WriteComponentChildContent(CodeRenderingContext context, ComponentChildContentIntermediateNode node) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (node == null) + { + throw new ArgumentNullException(nameof(node)); + } + + _scopeStack.OpenComponentScope( + context, + node.AttributeName, + node.TypeName, + node.IsParameterized ? node.ParameterName : null); + for (var i = 0; i < node.Children.Count; i++) + { + context.RenderNode(node.Children[i]); + } + _scopeStack.CloseScope(context); } public override void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node) @@ -474,11 +466,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - // Since the user doesn't write this name themselves, we have to use something hardcoded - // and predicatable. - const string VariableName = "context"; - - _scopeStack.OpenTemplateScope(context, VariableName); + _scopeStack.OpenTemplateScope(context); context.RenderChildren(node); _scopeStack.CloseScope(context); } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ChildContentDiagnosticPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ChildContentDiagnosticPass.cs new file mode 100644 index 0000000000..d2f099c0c9 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ChildContentDiagnosticPass.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Blazor.Razor +{ + internal class ChildContentDiagnosticPass : IntermediateNodePassBase, IRazorOptimizationPass + { + // Runs after components/eventhandlers/ref/bind/templates. We want to validate every component + // and it's usage of ChildContent. + public override int Order => 160; + + protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) + { + var visitor = new Visitor(); + visitor.Visit(documentNode); + } + + private class Visitor : IntermediateNodeWalker, IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor + { + public void VisitExtension(ComponentExtensionNode node) + { + // Check for properties that are set by both element contents (body) and the attribute itself. + foreach (var childContent in node.ChildContents) + { + foreach (var attribute in node.Attributes) + { + if (attribute.AttributeName == childContent.AttributeName) + { + node.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentSetByAttributeAndBody( + attribute.Source, + attribute.AttributeName)); + } + } + } + + base.VisitDefault(node); + } + + public void VisitExtension(ComponentChildContentIntermediateNode node) + { + // Check that each child content has a unique parameter name within its scope. This is important + // because the parameter name can be implict, and it doesn't work well when nested. + if (node.IsParameterized) + { + for (var i = 0; i < Ancestors.Count - 1; i++) + { + var ancestor = Ancestors[i] as ComponentChildContentIntermediateNode; + if (ancestor != null && + ancestor.IsParameterized && + string.Equals(node.ParameterName, ancestor.ParameterName, StringComparison.Ordinal)) + { + // Duplicate name. We report an error because this will almost certainly also lead to an error + // from the C# compiler that's way less clear. + node.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentRepeatedParameterName( + node.Source, + node, + (ComponentExtensionNode)Ancestors[0], // Encosing component + ancestor, // conflicting child content node + (ComponentExtensionNode)Ancestors[i + 1])); // Encosing component of conflicting child content node + } + } + } + + base.VisitDefault(node); + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentChildContentIntermediateNode.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentChildContentIntermediateNode.cs new file mode 100644 index 0000000000..9b4551cebc --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentChildContentIntermediateNode.cs @@ -0,0 +1,52 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Blazor.Shared; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Blazor.Razor +{ + internal class ComponentChildContentIntermediateNode : ExtensionIntermediateNode + { + public string AttributeName => BoundAttribute?.Name ?? BlazorApi.RenderTreeBuilder.ChildContent; + + public BoundAttributeDescriptor BoundAttribute { get; set; } + + public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); + + public bool IsParameterized => BoundAttribute?.IsParameterizedChildContentProperty() ?? false; + + public string ParameterName { get; set; } = "context"; + + public string TypeName => BoundAttribute?.TypeName == null ? BlazorApi.RenderFragment.FullTypeName : BoundAttribute.TypeName; + + public override void Accept(IntermediateNodeVisitor visitor) + { + if (visitor == null) + { + throw new ArgumentNullException(nameof(visitor)); + } + + AcceptExtensionNode(this, visitor); + } + + public override void WriteNode(CodeTarget target, CodeRenderingContext context) + { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var writer = (BlazorNodeWriter)context.NodeWriter; + writer.WriteComponentChildContent(context, this); + } + } +} diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentExtensionNode.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentExtensionNode.cs index 7d0317ab39..bfb222d405 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentExtensionNode.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentExtensionNode.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -17,12 +17,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor public IEnumerable Captures => Children.OfType(); - public IEnumerable Body => Children.Where(c => - { - return - c as ComponentAttributeExtensionNode == null && - c as RefExtensionNode == null; - }); + public IEnumerable ChildContents => Children.OfType(); public override IntermediateNodeCollection Children { get; } = new IntermediateNodeCollection(); @@ -82,7 +77,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor } builder.Append(">"); - builder.Append(Body.Any() ? "..." : string.Empty); + builder.Append(ChildContents.Any() ? "..." : string.Empty); builder.Append(""); diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentLoweringPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentLoweringPass.cs index 0bc4d27534..13c73bceb9 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentLoweringPass.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentLoweringPass.cs @@ -1,7 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Diagnostics; using System.Linq; +using Microsoft.AspNetCore.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Intermediate; @@ -49,6 +52,10 @@ namespace Microsoft.AspNetCore.Blazor.Razor { reference.Replace(RewriteAsComponent(node, node.TagHelpers.First(t => t.IsComponentTagHelper()))); } + else if (node.TagHelpers.Any(t => t.IsChildContentTagHelper())) + { + // Ignore, this will be handled when we rewrite the parent. + } else { reference.Replace(RewriteAsElement(node)); @@ -58,7 +65,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor private ComponentExtensionNode RewriteAsComponent(TagHelperIntermediateNode node, TagHelperDescriptor tagHelper) { - var result = new ComponentExtensionNode() + var component = new ComponentExtensionNode() { Component = tagHelper, Source = node.Source, @@ -67,13 +74,13 @@ namespace Microsoft.AspNetCore.Blazor.Razor for (var i = 0; i < node.Diagnostics.Count; i++) { - result.Diagnostics.Add(node.Diagnostics[i]); + component.Diagnostics.Add(node.Diagnostics[i]); } - var visitor = new ComponentRewriteVisitor(result.Children); + var visitor = new ComponentRewriteVisitor(component); visitor.Visit(node); - return result; + return component; } private HtmlElementIntermediateNode RewriteAsElement(TagHelperIntermediateNode node) @@ -97,28 +104,182 @@ namespace Microsoft.AspNetCore.Blazor.Razor private class ComponentRewriteVisitor : IntermediateNodeWalker { + private readonly ComponentExtensionNode _component; private readonly IntermediateNodeCollection _children; - public ComponentRewriteVisitor(IntermediateNodeCollection children) + public ComponentRewriteVisitor(ComponentExtensionNode component) { - _children = children; + _component = component; + _children = component.Children; } public override void VisitTagHelper(TagHelperIntermediateNode node) { // Visit children, we're replacing this node. - for (var i = 0; i < node.Children.Count; i++) - { - Visit(node.Children[i]); - } + base.VisitDefault(node); } public override void VisitTagHelperBody(TagHelperBodyIntermediateNode node) { + // Wrap the component's children in a ChildContent node if we have some significant + // content. + if (node.Children.Count == 0) + { + return; + } + + // If we get a single HTML content node containing only whitespace, + // then this is probably a tag that looks like ' + // + // We don't want to create a child content for this case, because it can conflict + // with a child content that's set via an attribute. We don't want the formatting + // of insigificant whitespace to be annoying when setting attributes directly. + if (node.Children.Count == 1 && IsIgnorableWhitespace(node.Children[0])) + { + return; + } + + // From here we fork and behave differently based on whether the component's child content is + // implicit or explicit. + // + // Explict child content will look like:
...
+ // compared with implicit:
+ // + // Using implicit child content: + // 1. All content is grouped into a single child content lambda, and assiged to the property 'ChildContent' + // + // Using explicit child content: + // 1. All content must be contained within 'child content' elements that are direct children + // 2. Whitespace outside of 'child content' elements will be ignored (not an error) + // 3. Non-whitespace outside of 'child content' elements will cause an error + // 4. All 'child content' elements must match parameters on the component (exception for ChildContent, + // which is always allowed. + // 5. Each 'child content' element will generate its own lambda, and be assigned to the property + // that matches the element name. + if (!node.Children.OfType().Any(t => t.TagHelpers.Any(th => th.IsChildContentTagHelper()))) + { + // This node has implicit child content. It may or may not have an attribute that matches. + var attribute = _component.Component.BoundAttributes + .Where(a => string.Equals(a.Name, BlazorApi.RenderTreeBuilder.ChildContent, StringComparison.Ordinal)) + .FirstOrDefault(); + _children.Add(RewriteChildContent(attribute, node.Source, node.Children)); + return; + } + + // OK this node has explicit child content, we can rewrite it by visiting each node + // in sequence, since we: + // a) need to rewrite each child content element + // b) any significant content outside of a child content is an error for (var i = 0; i < node.Children.Count; i++) { - _children.Add(node.Children[i]); + var child = node.Children[i]; + if (IsIgnorableWhitespace(child)) + { + continue; + } + + if (child is TagHelperIntermediateNode tagHelperNode && + tagHelperNode.TagHelpers.Any(th => th.IsChildContentTagHelper())) + { + // This is a child content element + var attribute = _component.Component.BoundAttributes + .Where(a => string.Equals(a.Name, tagHelperNode.TagName, StringComparison.Ordinal)) + .FirstOrDefault(); + _children.Add(RewriteChildContent(attribute, child.Source, child.Children)); + continue; + } + + // If we get here then this is significant content inside a component with explicit child content. + child.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentMixedWithExplicitChildContent(child.Source, _component)); + _children.Add(child); } + + bool IsIgnorableWhitespace(IntermediateNode n) + { + if (n is HtmlContentIntermediateNode html && + html.Children.Count == 1 && + html.Children[0] is IntermediateToken token && + string.IsNullOrWhiteSpace(token.Content)) + { + return true; + } + + return false; + } + } + + private ComponentChildContentIntermediateNode RewriteChildContent(BoundAttributeDescriptor attribute, SourceSpan? source, IntermediateNodeCollection children) + { + var childContent = new ComponentChildContentIntermediateNode() + { + BoundAttribute = attribute, + Source = source, + }; + + // There are two cases here: + // 1. Implicit child content - the children will be non-taghelper nodes, just accept them + // 2. Explicit child content - the children will be various tag helper nodes, that need special processing. + for (var i = 0; i < children.Count; i++) + { + var child = children[i]; + if (child is TagHelperBodyIntermediateNode body) + { + // The body is all of the content we want to render, the rest of the childen will + // be the attributes. + for (var j = 0; j < body.Children.Count; j++) + { + childContent.Children.Add(body.Children[j]); + } + } + else if (child is TagHelperPropertyIntermediateNode property) + { + if (property.BoundAttribute.Kind == BlazorMetadata.ChildContent.TagHelperKind) + { + // Check for each child content with a parameter name, that the parameter name is specified + // with literal text. For instance, the following is not allowed and should generate a diagnostic. + // + // ... + if (TryGetAttributeStringContent(property, out var parameterName)) + { + childContent.ParameterName = parameterName; + continue; + } + + // The parameter name is invalid. + childContent.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentHasInvalidParameter(property.Source, property.AttributeName, attribute.Name)); + continue; + } + + // This is an unrecognized attribute, this is possible if you try to do something like put 'ref' on a child content. + childContent.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentHasInvalidAttribute(property.Source, property.AttributeName, attribute.Name)); + } + else if (child is TagHelperHtmlAttributeIntermediateNode a) + { + // This is an HTML attribute on a child content. + childContent.Diagnostics.Add(BlazorDiagnosticFactory.Create_ChildContentHasInvalidAttribute(a.Source, a.AttributeName, attribute.Name)); + } + else + { + // This is some other kind of node (likely an implicit child content) + childContent.Children.Add(child); + } + } + + return childContent; + } + + private bool TryGetAttributeStringContent(TagHelperPropertyIntermediateNode property, out string content) + { + // The success path looks like - a single HTML Attribute Value node with tokens + if (property.Children.Count == 1 && + property.Children[0] is HtmlContentIntermediateNode html) + { + content = string.Join(string.Empty, html.Children.OfType().Select(n => n.Content)); + return true; + } + + content = null; + return false; } public override void VisitTagHelperHtmlAttribute(TagHelperHtmlAttributeIntermediateNode node) diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentTagHelperDescriptorProvider.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentTagHelperDescriptorProvider.cs index 2f82f4aca9..d74d9211ab 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentTagHelperDescriptorProvider.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentTagHelperDescriptorProvider.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -45,29 +45,10 @@ namespace Microsoft.AspNetCore.Blazor.Razor // We need to see private members too compilation = WithMetadataImportOptionsAll(compilation); - var componentSymbol = compilation.GetTypeByMetadataName(BlazorApi.IComponent.MetadataName); - if (componentSymbol == null) - { - // No definition for IComponent, nothing to do. - return; - } - - var parameterSymbol = compilation.GetTypeByMetadataName(BlazorApi.ParameterAttribute.FullTypeName); - if (parameterSymbol == null) - { - // No definition for [Parameter], nothing to do. - return; - } - - var blazorComponentSymbol = compilation.GetTypeByMetadataName(BlazorApi.BlazorComponent.FullTypeName); - if (blazorComponentSymbol == null) - { - // No definition for BlazorComponent, nothing to do. - return; - } + var symbols = BlazorSymbols.Create(compilation); var types = new List(); - var visitor = new ComponentTypeVisitor(componentSymbol, types); + var visitor = new ComponentTypeVisitor(symbols, types); // Visit the primary output of this compilation, as well as all references. visitor.Visit(compilation.Assembly); @@ -84,7 +65,14 @@ namespace Microsoft.AspNetCore.Blazor.Razor for (var i = 0; i < types.Count; i++) { var type = types[i]; - context.Results.Add(CreateDescriptor(type, parameterSymbol, blazorComponentSymbol)); + var descriptor = CreateDescriptor(symbols, type); + context.Results.Add(descriptor); + + foreach (var childContent in descriptor.GetChildContentProperties()) + { + // Synthesize a separate tag helper for each child content property that's declared. + context.Results.Add(CreateChildContentDescriptor(symbols, descriptor, childContent)); + } } } @@ -95,18 +83,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor return compilation.WithOptions(newCompilationOptions); } - private TagHelperDescriptor CreateDescriptor(INamedTypeSymbol type, INamedTypeSymbol parameterSymbol, INamedTypeSymbol blazorComponentSymbol) + private TagHelperDescriptor CreateDescriptor(BlazorSymbols symbols, INamedTypeSymbol type) { - if (type == null) - { - throw new ArgumentNullException(nameof(type)); - } - - if (parameterSymbol == null) - { - throw new ArgumentNullException(nameof(parameterSymbol)); - } - var typeName = type.ToDisplayString(FullNameTypeDisplayFormat); var assemblyName = type.ContainingAssembly.Identity.Name; @@ -126,7 +104,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor // Components have very simple matching rules. The type name (short) matches the tag name. builder.TagMatchingRule(r => r.TagName = type.Name); - foreach (var property in GetProperties(type, parameterSymbol, blazorComponentSymbol)) + foreach (var property in GetProperties(symbols, type)) { if (property.kind == PropertyKind.Ignored) { @@ -144,6 +122,11 @@ namespace Microsoft.AspNetCore.Blazor.Razor pb.IsEnum = true; } + if (property.kind == PropertyKind.ChildContent) + { + pb.Metadata.Add(BlazorMetadata.Component.ChildContentKey, bool.TrueString); + } + if (property.kind == PropertyKind.Delegate) { pb.Metadata.Add(BlazorMetadata.Component.DelegateSignatureKey, bool.TrueString); @@ -162,6 +145,51 @@ namespace Microsoft.AspNetCore.Blazor.Razor return descriptor; } + private TagHelperDescriptor CreateChildContentDescriptor(BlazorSymbols symbols, TagHelperDescriptor component, BoundAttributeDescriptor attribute) + { + var typeName = component.GetTypeName() + "." + attribute.Name; + var assemblyName = component.AssemblyName; + + var builder = TagHelperDescriptorBuilder.Create(BlazorMetadata.ChildContent.TagHelperKind, typeName, assemblyName); + builder.SetTypeName(typeName); + + // This opts out this 'component' tag helper for any processing that's specific to the default + // Razor ITagHelper runtime. + builder.Metadata[TagHelperMetadata.Runtime.Name] = BlazorMetadata.ChildContent.RuntimeName; + + // Opt out of processing as a component. We'll process this specially as part of the component's body. + builder.Metadata[BlazorMetadata.SpecialKindKey] = BlazorMetadata.ChildContent.TagHelperKind; + + var xml = attribute.Documentation; + if (!string.IsNullOrEmpty(xml)) + { + builder.Documentation = xml; + } + + // Child content matches the property name, but only as a direct child of the component. + builder.TagMatchingRule(r => + { + r.TagName = attribute.Name; + r.ParentTag = component.TagMatchingRules.First().TagName; + }); + + if (attribute.IsParameterizedChildContentProperty()) + { + // For child content attributes with a parameter, synthesize an attribute that allows you to name + // the parameter. + builder.BindAttribute(b => + { + b.Name = "Context"; + b.TypeName = typeof(string).FullName; + b.Documentation = string.Format(Resources.ChildContentParameterName_Documentation, attribute.Name); + }); + } + + var descriptor = builder.Build(); + + return descriptor; + } + // Does a walk up the inheritance chain to determine the set of parameters by using // a dictionary keyed on property name. // @@ -170,12 +198,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor // - have the [Parameter] attribute // - have a setter, even if private // - are not indexers - private IEnumerable<(IPropertySymbol property, PropertyKind kind)> GetProperties(INamedTypeSymbol type, INamedTypeSymbol parameterSymbol, INamedTypeSymbol blazorComponentSymbol) + private IEnumerable<(IPropertySymbol property, PropertyKind kind)> GetProperties(BlazorSymbols symbols, INamedTypeSymbol type) { var properties = new Dictionary(StringComparer.Ordinal); do { - if (type == blazorComponentSymbol) + if (type == symbols.BlazorComponent) { // The BlazorComponent base class doesn't have any [Parameter]. // Bail out now to avoid walking through its many members, plus the members @@ -217,7 +245,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor kind = PropertyKind.Ignored; } - if (!property.GetAttributes().Any(a => a.AttributeClass == parameterSymbol)) + if (!property.GetAttributes().Any(a => a.AttributeClass == symbols.ParameterAttribute)) { // Does not have [Parameter] kind = PropertyKind.Ignored; @@ -228,6 +256,19 @@ namespace Microsoft.AspNetCore.Blazor.Razor kind = PropertyKind.Enum; } + if (kind == PropertyKind.Default && property.Type == symbols.RenderFragment) + { + kind = PropertyKind.ChildContent; + } + + if (kind == PropertyKind.Default && + property.Type is INamedTypeSymbol namedType && + namedType.IsGenericType && + namedType.ConstructedFrom == symbols.RenderFragmentOfT) + { + kind = PropertyKind.ChildContent; + } + if (kind == PropertyKind.Default && property.Type.TypeKind == TypeKind.Delegate) { kind = PropertyKind.Delegate; @@ -248,17 +289,74 @@ namespace Microsoft.AspNetCore.Blazor.Razor Ignored, Default, Enum, + ChildContent, Delegate, } + private class BlazorSymbols + { + public static BlazorSymbols Create(Compilation compilation) + { + var symbols = new BlazorSymbols(); + symbols.BlazorComponent = compilation.GetTypeByMetadataName(BlazorApi.BlazorComponent.MetadataName); + if (symbols.BlazorComponent == null) + { + // No definition for BlazorComponent, nothing to do. + return null; + } + + symbols.IComponent = compilation.GetTypeByMetadataName(BlazorApi.IComponent.MetadataName); + if (symbols.IComponent == null) + { + // No definition for IComponent, nothing to do. + return null; + } + + symbols.ParameterAttribute = compilation.GetTypeByMetadataName(BlazorApi.ParameterAttribute.MetadataName); + if (symbols.ParameterAttribute == null) + { + // No definition for [Parameter], nothing to do. + return null; + } + + symbols.RenderFragment = compilation.GetTypeByMetadataName(BlazorApi.RenderFragment.MetadataName); + if (symbols.RenderFragment == null) + { + // No definition for RenderFragment, nothing to do. + } + + symbols.RenderFragmentOfT = compilation.GetTypeByMetadataName(BlazorApi.RenderFragmentOfT.MetadataName); + if (symbols.RenderFragmentOfT == null) + { + // No definition for RenderFragment, nothing to do. + } + + return symbols; + } + + private BlazorSymbols() + { + } + + public INamedTypeSymbol BlazorComponent { get; private set; } + + public INamedTypeSymbol IComponent { get; private set; } + + public INamedTypeSymbol ParameterAttribute { get; private set; } + + public INamedTypeSymbol RenderFragment { get; private set; } + + public INamedTypeSymbol RenderFragmentOfT { get; private set; } + } + private class ComponentTypeVisitor : SymbolVisitor { - private INamedTypeSymbol _interface; - private List _results; + private readonly BlazorSymbols _symbols; + private readonly List _results; - public ComponentTypeVisitor(INamedTypeSymbol @interface, List results) + public ComponentTypeVisitor(BlazorSymbols symbols, List results) { - _interface = @interface; + _symbols = symbols; _results = results; } @@ -290,7 +388,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor internal bool IsComponent(INamedTypeSymbol symbol) { - if (_interface == null) + if (_symbols == null) { return false; } @@ -299,7 +397,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor symbol.DeclaredAccessibility == Accessibility.Public && !symbol.IsAbstract && !symbol.IsGenericType && - symbol.AllInterfaces.Contains(_interface); + symbol.AllInterfaces.Contains(_symbols.IComponent); } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/EventHandlerLoweringPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/EventHandlerLoweringPass.cs index 2512fde137..7f4ded2676 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/EventHandlerLoweringPass.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/EventHandlerLoweringPass.cs @@ -189,7 +189,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor if (template != null) { // See comments in TemplateDiagnosticPass - node.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(template.Source)); + node.Diagnostics.Add(BlazorDiagnosticFactory.Create_TemplateInvalidLocation(template.Source)); return new[] { new IntermediateToken() { Kind = TokenKind.CSharp, Content = string.Empty, }, }; } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/Resources.Designer.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/Resources.Designer.cs index 5a9efcccb2..e6b792f3ac 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/Resources.Designer.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/Resources.Designer.cs @@ -105,6 +105,15 @@ namespace Microsoft.AspNetCore.Blazor.Razor { } } + /// + /// Looks up a localized string similar to Specifies the parameter name for the '{0}' lambda expression.. + /// + internal static string ChildContentParameterName_Documentation { + get { + return ResourceManager.GetString("ChildContentParameterName_Documentation", resourceCulture); + } + } + /// /// Looks up a localized string similar to Sets the '{0}' attribute to the provided string or delegate value. A delegate value should be of type '{1}'.. /// diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/Resources.resx b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/Resources.resx index a80941096e..9ec29c40ea 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/Resources.resx +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/Resources.resx @@ -132,6 +132,9 @@ Specifies a format to convert the value specified by the corresponding bind attribute. For example: <code>format-value="..."</code> will apply a format string to the value specified in <code>bind-value-...</code>. The format string can currently only be used with expressions of type <code>DateTime</code>. + + Specifies the parameter name for the '{0}' lambda expression. + Sets the '{0}' attribute to the provided string or delegate value. A delegate value should be of type '{1}'. diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs index 509ed26f83..df758a606a 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs @@ -26,19 +26,39 @@ namespace Microsoft.AspNetCore.Blazor.Razor _stack.Push(new ScopeEntry(tagName, ScopeKind.Element)); } - public void OpenComponentScope(string tagName) + public void OpenComponentScope(CodeRenderingContext context, string name, string type, string parameterName) { - _stack.Push(new ScopeEntry(tagName, ScopeKind.Component)); + var scope = new ScopeEntry(name, ScopeKind.Component); + _stack.Push(scope); + + var blazorNodeWriter = (BlazorNodeWriter)context.NodeWriter; + blazorNodeWriter.BeginWriteAttribute(context.CodeWriter, name); + OffsetBuilderVarNumber(1); + + // Writes code that looks like: + // + // builder.AddAttribute(0, "{name}", ({type})((__builder) => { ... })); + // OR + // builder.AddAttribute(0, "{name}", ({type})((context) => (__builder) => { ... })); + + context.CodeWriter.Write($"({type})("); + + if (parameterName != null) + { + context.CodeWriter.Write($"({parameterName}) => "); + } + + scope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName); } - public void OpenTemplateScope(CodeRenderingContext context, string variableName) + public void OpenTemplateScope(CodeRenderingContext context) { var currentScope = new ScopeEntry("__template", ScopeKind.Template); _stack.Push(currentScope); // Templates always get a lambda scope, because they are defined as a lambda. OffsetBuilderVarNumber(1); - currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName, variableName); + currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName); } @@ -61,27 +81,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor } } - public void IncrementCurrentScopeChildCount(CodeRenderingContext context) - { - if (_stack.Count > 0) - { - var currentScope = _stack.Peek(); - - if (currentScope.Kind == ScopeKind.Component && currentScope.ChildCount == 0) - { - // When we're about to insert the first child into a component, - // it's time to open a new lambda - var blazorNodeWriter = (BlazorNodeWriter)context.NodeWriter; - blazorNodeWriter.BeginWriteAttribute(context.CodeWriter, BlazorApi.RenderTreeBuilder.ChildContent); - OffsetBuilderVarNumber(1); - context.CodeWriter.Write($"({BlazorApi.RenderFragment.FullTypeName})("); - currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName); - } - - currentScope.ChildCount++; - } - } - private void OffsetBuilderVarNumber(int delta) { _builderVarNumber += delta; @@ -92,19 +91,19 @@ namespace Microsoft.AspNetCore.Blazor.Razor private class ScopeEntry { - public readonly string TagName; + public readonly string Name; public ScopeKind Kind; public int ChildCount; public IDisposable LambdaScope; - public ScopeEntry(string tagName, ScopeKind kind) + public ScopeEntry(string name, ScopeKind kind) { - TagName = tagName; + Name = name; Kind = kind; ChildCount = 0; } - public override string ToString() => $"<{TagName}> ({Kind})"; + public override string ToString() => $"<{Name}> ({Kind})"; } private enum ScopeKind diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TagHelperBoundAttributeDescriptorExtensions.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TagHelperBoundAttributeDescriptorExtensions.cs index 59cf7e1880..4971b40c23 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TagHelperBoundAttributeDescriptorExtensions.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TagHelperBoundAttributeDescriptorExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using Microsoft.AspNetCore.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language; namespace Microsoft.AspNetCore.Blazor.Razor @@ -33,5 +34,41 @@ namespace Microsoft.AspNetCore.Blazor.Razor attribute.Metadata.TryGetValue(key, out var value) && string.Equals(value, bool.TrueString); } + + /// + /// Gets a value that indicates whether the property is a child content property. Properties are + /// considered child content if they have the type RenderFragment or RenderFragment{T}. + /// + /// The . + /// Returns true if the property is child content, otherwise false. + public static bool IsChildContentProperty(this BoundAttributeDescriptor attribute) + { + if (attribute == null) + { + throw new ArgumentNullException(nameof(attribute)); + } + + var key = BlazorMetadata.Component.ChildContentKey; + return + attribute.Metadata.TryGetValue(key, out var value) && + string.Equals(value, bool.TrueString); + } + + /// + /// Gets a value that indicates whether the property is a parameterized child content property. Properties are + /// considered parameterized child content if they have the type RenderFragment{T} (for some T). + /// + /// The . + /// Returns true if the property is parameterized child content, otherwise false. + public static bool IsParameterizedChildContentProperty(this BoundAttributeDescriptor attribute) + { + if (attribute == null) + { + throw new ArgumentNullException(nameof(attribute)); + } + + return attribute.IsChildContentProperty() && + !string.Equals(attribute.TypeName, BlazorApi.RenderFragment.FullTypeName, StringComparison.Ordinal); + } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TagHelperDescriptorExtensions.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TagHelperDescriptorExtensions.cs index a714eba955..ebb66117f4 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TagHelperDescriptorExtensions.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TagHelperDescriptorExtensions.cs @@ -1,8 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using Microsoft.AspNetCore.Razor.Language; namespace Microsoft.AspNetCore.Blazor.Razor @@ -81,6 +82,18 @@ namespace Microsoft.AspNetCore.Blazor.Razor return result; } + public static bool IsChildContentTagHelper(this TagHelperDescriptor tagHelper) + { + if (tagHelper == null) + { + throw new ArgumentNullException(nameof(tagHelper)); + } + + return + tagHelper.Metadata.TryGetValue(BlazorMetadata.SpecialKindKey, out var value) && + string.Equals(value, BlazorMetadata.ChildContent.TagHelperKind, StringComparison.Ordinal); + } + public static bool IsComponentTagHelper(this TagHelperDescriptor tagHelper) { if (tagHelper == null) @@ -125,5 +138,27 @@ namespace Microsoft.AspNetCore.Blazor.Razor tagHelper.Metadata.TryGetValue(BlazorMetadata.EventHandler.EventArgsType, out var result); return result; } + + /// + /// Gets the set of component attributes that can accept child content (RenderFragment or RenderFragment{T}). + /// + /// The . + /// The child content attributes + public static IEnumerable GetChildContentProperties(this TagHelperDescriptor tagHelper) + { + if (tagHelper == null) + { + throw new ArgumentNullException(nameof(tagHelper)); + } + + for (var i = 0; i < tagHelper.BoundAttributes.Count; i++) + { + var attribute = tagHelper.BoundAttributes[i]; + if (attribute.IsChildContentProperty()) + { + yield return attribute; + } + } + } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TemplateDiagnosticPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TemplateDiagnosticPass.cs index b5c2f0da19..1b5d4d74ce 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TemplateDiagnosticPass.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TemplateDiagnosticPass.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor for (var i = 0; i < visitor.Candidates.Count; i++) { var candidate = visitor.Candidates[i]; - candidate.Parent.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(candidate.Node.Source)); + candidate.Parent.Diagnostics.Add(BlazorDiagnosticFactory.Create_TemplateInvalidLocation(candidate.Node.Source)); // Remove the offending node since we don't know how to render it. This means that the user won't get C# // completion at this location, which is fine because it's inside an HTML attribute. diff --git a/src/Microsoft.AspNetCore.Blazor/RenderFragment.cs b/src/Microsoft.AspNetCore.Blazor/RenderFragment.cs index a8526956b6..56a1e6c245 100644 --- a/src/Microsoft.AspNetCore.Blazor/RenderFragment.cs +++ b/src/Microsoft.AspNetCore.Blazor/RenderFragment.cs @@ -13,11 +13,10 @@ namespace Microsoft.AspNetCore.Blazor public delegate void RenderFragment(RenderTreeBuilder builder); /// - /// Represents a segment of UI content for an object of type , implemented - /// as a delegate that writes the content to a . + /// Represents a segment of UI content for an object of type , implemented as + /// a function that returns a . /// /// The type of object. - /// The to which the content should be written. /// The value used to build the content. - public delegate void RenderFragment(RenderTreeBuilder builder, T value); + public delegate RenderFragment RenderFragment(T value); } diff --git a/src/Microsoft.AspNetCore.Blazor/RenderFragmentExtensions.cs b/src/Microsoft.AspNetCore.Blazor/RenderFragmentExtensions.cs deleted file mode 100644 index 44471c02a1..0000000000 --- a/src/Microsoft.AspNetCore.Blazor/RenderFragmentExtensions.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -namespace Microsoft.AspNetCore.Blazor -{ - /// - /// Contains extension methods for and . - /// - public static class RenderFragmentExtensions - { - /// - /// Binds a and a value of type to a - /// so that it can be used by the rendering system from Razor code. - /// - /// The type of the value used by the . - /// A , usually produced by a Razor template. - /// The value of type . - /// A . - public static RenderFragment WithValue(this RenderFragment fragment, T value) - { - return (b) => fragment(b, value); - } - } -} diff --git a/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeBuilder.cs b/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeBuilder.cs index 0b152cfe8e..5ffe4164ed 100644 --- a/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeBuilder.cs +++ b/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeBuilder.cs @@ -112,13 +112,7 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree { if (fragment != null) { - // We surround the fragment with a region delimiter to indicate that the - // sequence numbers inside the fragment are unrelated to the sequence numbers - // outside it. If we didn't do this, the diffing logic might produce inefficient - // diffs depending on how the sequence numbers compared. - OpenRegion(sequence); - fragment(this, value); - CloseRegion(); + AddContent(sequence, fragment(value)); } } diff --git a/src/shared/BlazorApi.cs b/src/shared/BlazorApi.cs index 22b13616e1..a70bb9f4bd 100644 --- a/src/shared/BlazorApi.cs +++ b/src/shared/BlazorApi.cs @@ -13,6 +13,7 @@ namespace Microsoft.AspNetCore.Blazor.Shared { public static readonly string Namespace = "Microsoft.AspNetCore.Blazor.Components"; public static readonly string FullTypeName = Namespace + ".BlazorComponent"; + public static readonly string MetadataName = FullTypeName; public static readonly string BuildRenderTree = nameof(BuildRenderTree); } @@ -20,6 +21,7 @@ namespace Microsoft.AspNetCore.Blazor.Shared public static class ParameterAttribute { public static readonly string FullTypeName = "Microsoft.AspNetCore.Blazor.Components.ParameterAttribute"; + public static readonly string MetadataName = FullTypeName; } public static class LayoutAttribute @@ -43,8 +45,16 @@ namespace Microsoft.AspNetCore.Blazor.Shared { public static readonly string Namespace = "Microsoft.AspNetCore.Blazor"; public static readonly string FullTypeName = Namespace + ".RenderFragment"; + public static readonly string MetadataName = FullTypeName; } - + + public static class RenderFragmentOfT + { + public static readonly string Namespace = "Microsoft.AspNetCore.Blazor"; + public static readonly string FullTypeName = Namespace + ".RenderFragment<>"; + public static readonly string MetadataName = Namespace + ".RenderFragment`1"; + } + public static class RenderTreeBuilder { public static readonly string FullTypeName = "Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder"; diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/ChildContentRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/ChildContentRazorIntegrationTest.cs new file mode 100644 index 0000000000..fc2a4e1627 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/ChildContentRazorIntegrationTest.cs @@ -0,0 +1,496 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using Microsoft.AspNetCore.Blazor.Razor; +using Microsoft.AspNetCore.Blazor.RenderTree; +using Microsoft.AspNetCore.Blazor.Test.Helpers; +using Microsoft.CodeAnalysis.CSharp; +using Xunit; + +namespace Microsoft.AspNetCore.Blazor.Build.Test +{ + public class ChildContentRazorIntegrationTest : RazorIntegrationTestBase + { + private readonly CSharpSyntaxTree RenderChildContentComponent = Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; +using Microsoft.AspNetCore.Blazor.RenderTree; +namespace Test +{ + public class RenderChildContent : BlazorComponent + { + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.AddContent(0, ChildContent); + } + + [Parameter] + RenderFragment ChildContent { get; set; } + } +} +"); + + private readonly CSharpSyntaxTree RenderChildContentStringComponent = Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; +using Microsoft.AspNetCore.Blazor.RenderTree; +namespace Test +{ + public class RenderChildContentString : BlazorComponent + { + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.AddContent(0, ChildContent, Value); + } + + [Parameter] + RenderFragment ChildContent { get; set; } + + [Parameter] + string Value { get; set; } + } +} +"); + + private readonly CSharpSyntaxTree RenderMultipleChildContent = Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; +using Microsoft.AspNetCore.Blazor.RenderTree; +namespace Test +{ + public class RenderMultipleChildContent : BlazorComponent + { + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + builder.AddContent(0, Header, Name); + builder.AddContent(1, ChildContent, Value); + builder.AddContent(2, Footer); + } + + [Parameter] + string Name { get; set; } + + [Parameter] + RenderFragment Header { get; set; } + + [Parameter] + RenderFragment ChildContent { get; set; } + + [Parameter] + RenderFragment Footer { get; set; } + + [Parameter] + string Value { get; set; } + } +} +"); + + internal override bool UseTwoPhaseCompilation => true; + + [Fact] + public void Render_BodyChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly + +
+
"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 0), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 1), + frame => AssertFrame.Markup(frame, "\n
\n", 2)); + } + + [Fact] + public void Render_BodyChildContent_Generic() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentStringComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly + +
@context.ToLowerInvariant()
+
"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContentString", 3, 0), + frame => AssertFrame.Attribute(frame, "Value", "HI", 1), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 2), + frame => AssertFrame.Whitespace(frame, 3), + frame => AssertFrame.Element(frame, "div", 2, 4), + frame => AssertFrame.Text(frame, "hi", 5), + frame => AssertFrame.Whitespace(frame, 6)); + } + + [Fact] + public void Render_ExplicitChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly + + +
+
+
"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 0), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 1), + frame => AssertFrame.Markup(frame, "\n
\n ", 2)); + } + + [Fact] + public void Render_BodyChildContent_Recursive() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly + + +
+
+
"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 0), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 1), + frame => AssertFrame.Whitespace(frame, 2), + frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 3), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 4), + frame => AssertFrame.Whitespace(frame, 6), + frame => AssertFrame.Markup(frame, "\n
\n ", 5)); + } + + [Fact] + public void Render_AttributeChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +@{ RenderFragment template = (context) => @
@context.ToLowerInvariant()
; } +"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 2), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hi", 1)); + } + + [Fact] + public void Render_AttributeChildContent_RenderFragmentOfString() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentStringComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +@{ RenderFragment template = (context) => @
@context.ToLowerInvariant()
; } +"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContentString", 3, 2), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3), + frame => AssertFrame.Attribute(frame, "Value", "HI", 4), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hi", 1)); + } + + [Fact] + public void Render_AttributeChildContent_NoArgTemplate() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +@{ RenderFragment template = @
@(""HI"".ToLowerInvariant())
; } +"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 2), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hi", 1)); + } + + [Fact] + public void Render_AttributeChildContent_IgnoresEmptyBody() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +@{ RenderFragment template = (context) => @
@context.ToLowerInvariant()
; } +"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 2), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hi", 1)); + } + + [Fact] + public void Render_AttributeChildContent_IgnoresWhitespaceBody() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +@{ RenderFragment template = (context) => @
@context.ToLowerInvariant()
; } + + +"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderChildContent", 2, 2), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, 3), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hi", 1)); + } + + [Fact] + public void Render_MultipleChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderMultipleChildContent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +@{ RenderFragment header = context => @
@context.ToLowerInvariant()
; } + + Some @context.ToLowerInvariant() Content +
Bye!
+
"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.RenderMultipleChildContent", 6, 2), + frame => AssertFrame.Attribute(frame, "Name", "billg", 3), + frame => AssertFrame.Attribute(frame, "Header", typeof(RenderFragment), 4), + frame => AssertFrame.Attribute(frame, "Value", "HI", 5), + frame => AssertFrame.Attribute(frame, RenderTreeBuilder.ChildContent, typeof(RenderFragment), 6), + frame => AssertFrame.Attribute(frame, "Footer", typeof(RenderFragment), 10), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "billg", 1), + frame => AssertFrame.Text(frame, "Some ", 7), + frame => AssertFrame.Text(frame, "hi", 8), + frame => AssertFrame.Text(frame, " Content", 9), + frame => AssertFrame.Text(frame, "Bye!", 11)); + } + + [Fact] + public void Render_ChildContent_AttributeAndBody_ProducesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +@{ RenderFragment template = @
@context.ToLowerInvariant()
; } + +Some Content +"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Same(BlazorDiagnosticFactory.ChildContentSetByAttributeAndBody.Id, diagnostic.Id); + } + + [Fact] + public void Render_ChildContent_AttributeAndExplicitChildContent_ProducesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +@{ RenderFragment template = @
@context.ToLowerInvariant()
; } + + +Some Content + +"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Same(BlazorDiagnosticFactory.ChildContentSetByAttributeAndBody.Id, diagnostic.Id); + } + + [Fact] + public void Render_ChildContent_ExplicitChildContent_UnrecogizedContent_ProducesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + + +@somethingElse +"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Same(BlazorDiagnosticFactory.ChildContentMixedWithExplicitChildContent.Id, diagnostic.Id); + Assert.Equal( + "Unrecognized child content inside component 'RenderChildContent'. The component 'RenderChildContent' accepts " + + "child content through the following top-level items: 'ChildContent'.", + diagnostic.GetMessage()); + } + + [Fact] + public void Render_ChildContent_ExplicitChildContent_UnrecogizedElement_ProducesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + + + +"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Same(BlazorDiagnosticFactory.ChildContentMixedWithExplicitChildContent.Id, diagnostic.Id); + } + + [Fact] + public void Render_ChildContent_ExplicitChildContent_UnrecogizedAttribute_ProducesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentComponent); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + + +"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Same(BlazorDiagnosticFactory.ChildContentHasInvalidAttribute.Id, diagnostic.Id); + } + + [Fact] + public void Render_ChildContent_ExplicitChildContent_InvalidParameterName_ProducesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentStringComponent); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + + +"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Same(BlazorDiagnosticFactory.ChildContentHasInvalidParameter.Id, diagnostic.Id); + } + + [Fact] + public void Render_ChildContent_ExplicitChildContent_RepeatedParameterName_GeneratesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(RenderChildContentStringComponent); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + + + + + + +"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Same(BlazorDiagnosticFactory.ChildContentRepeatedParameterName.Id, diagnostic.Id); + Assert.Equal( + "The child content element 'ChildContent' of component 'RenderChildContentString' uses the same parameter name ('context') as enclosing child content " + + "element 'ChildContent' of component 'RenderChildContentString'. Specify the parameter name like: ' to resolve the ambiguity", + diagnostic.GetMessage()); + } + } +} diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/CodeGenerationTestBase.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/CodeGenerationTestBase.cs new file mode 100644 index 0000000000..88684c7e40 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/CodeGenerationTestBase.cs @@ -0,0 +1,1891 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Linq; +using Xunit; + +namespace Microsoft.AspNetCore.Blazor.Build.Test +{ + public abstract class CodeGenerationTestBase : RazorBaselineIntegrationTestBase + { + internal override bool UseTwoPhaseCompilation => true; + + public CodeGenerationTestBase() + { + GenerateBaselines = true; + } + + #region Basics + + [Fact] + public void ChildComponent_Simple() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_WithParameters() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class SomeType + { + } + + public class MyComponent : BlazorComponent + { + [Parameter] int IntProperty { get; set; } + [Parameter] bool BoolProperty { get; set; } + [Parameter] string StringProperty { get; set; } + [Parameter] SomeType ObjectProperty { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_WithExplicitStringParameter() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + string StringProperty { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_WithNonPropertyAttributes() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ComponentParameter_TypeMismatch_ReportsDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class CoolnessMeter : BlazorComponent + { + [Parameter] private int Coolness { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + + var assembly = CompileToAssembly(generated, throwOnFailure: false); + // This has some errors + Assert.Collection( + assembly.Diagnostics.OrderBy(d => d.Id), + d => Assert.Equal("CS1503", d.Id)); + } + + #endregion + + #region Bind + + [Fact] + public void BindToComponent_SpecifiesValue_WithMatchingProperties() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + int Value { get; set; } + + [Parameter] + Action ValueChanged { get; set; } + } +}")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public int ParentValue { get; set; } = 42; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BindToComponent_TypeChecked_WithMatchingProperties() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + int Value { get; set; } + + [Parameter] + Action ValueChanged { get; set; } + } +}")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public string ParentValue { get; set; } = ""42""; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + + var assembly = CompileToAssembly(generated, throwOnFailure: false); + // This has some errors + Assert.Collection( + assembly.Diagnostics.OrderBy(d => d.Id), + d => Assert.Equal("CS0029", d.Id), + d => Assert.Equal("CS1503", d.Id)); + } + + [Fact] + public void BindToComponent_SpecifiesValue_WithoutMatchingProperties() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent, IComponent + { + void IComponent.SetParameters(ParameterCollection parameters) + { + } + } +}")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public int ParentValue { get; set; } = 42; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + int Value { get; set; } + + [Parameter] + Action OnChanged { get; set; } + } +}")); + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public int ParentValue { get; set; } = 42; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BindToComponent_SpecifiesValueAndChangeEvent_WithoutMatchingProperties() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent, IComponent + { + void IComponent.SetParameters(ParameterCollection parameters) + { + } + } +}")); + + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public int ParentValue { get; set; } = 42; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BindToElement_WritesAttributes() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + [BindElement(""div"", null, ""myvalue"", ""myevent"")] + public static class BindAttributes + { + } +}")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +
+@functions { + public string ParentValue { get; set; } = ""hi""; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BindToElementWithSuffix_WritesAttributes() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + [BindElement(""div"", ""value"", ""myvalue"", ""myevent"")] + public static class BindAttributes + { + } +}")); + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +
+@functions { + public string ParentValue { get; set; } = ""hi""; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BuiltIn_BindToInputWithoutType_WritesAttributes() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public int ParentValue { get; set; } = 42; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BuiltIn_BindToInputText_WithFormat_WritesAttributes() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BuiltIn_BindToInputText_WithFormatFromProperty_WritesAttributes() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); + + public string Format { get; set; } = ""MM/dd/yyyy""; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BuiltIn_BindToInputText_WritesAttributes() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public int ParentValue { get; set; } = 42; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BuiltIn_BindToInputCheckbox_WritesAttributes() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public bool Enabled { get; set; } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BindToElementFallback_WritesAttributes() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public int ParentValue { get; set; } = 42; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BindToElementFallback_WithFormat_WritesAttributes() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + #endregion + + #region Child Content + + [Fact] + public void ChildComponent_WithChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + string MyAttr { get; set; } + + [Parameter] + RenderFragment ChildContent { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +Some textNested text"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_WithGenericChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + string MyAttr { get; set; } + + [Parameter] + RenderFragment ChildContent { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +Some text@context.ToLowerInvariant()"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + + [Fact] + public void ChildComponent_WithGenericChildContent_SetsParameterName() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + string MyAttr { get; set; } + + [Parameter] + RenderFragment ChildContent { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + + Some text@item.ToLowerInvariant() + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_WithElementOnlyChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment ChildContent { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +hello"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_WithExplicitChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment ChildContent { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +hello"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_WithExplicitGenericChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment ChildContent { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +@context"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void MultipleExplictChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment Header { get; set; } + + [Parameter] + RenderFragment Footer { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +
Hi!
+
@(""bye!"")
+
"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BodyAndAttributeChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment Header { get; set; } + + RenderFragment ChildContent { get; set; } + + [Parameter] + RenderFragment Footer { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +@{ RenderFragment header = (context) => @
@context.ToLowerInvariant()
; } + + Some Content +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void BodyAndExplicitChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment Header { get; set; } + + [Parameter] + RenderFragment ChildContent { get; set; } + + [Parameter] + RenderFragment Footer { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +@{ RenderFragment header = (context) => @
@context.ToLowerInvariant()
; } + + Some Content +
Bye!
+
"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + #endregion + + #region Directives + + [Fact] + public void ChildComponent_WithPageDirective() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +@page ""/MyPage"" +@page ""/AnotherRoute/{id}"" +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + #endregion + + #region Event Handlers + + [Fact] + public void ChildComponent_WithLambdaEventHandler() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + Action OnClick { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + { Increment(); })""/> + +@functions { + private int counter; + private void Increment() { + counter++; + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + // Regression test for #954 - we need to allow arbitrary event handler + // attributes with weak typing. + [Fact] + public void ChildComponent_WithWeaklyTypeEventHandler() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class DynamicElement : BlazorComponent + { + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +@functions { + private Action OnClick { get; set; } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_WithExplicitEventHandler() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + Action OnClick { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +@functions { + private int counter; + private void Increment(UIEventArgs e) { + counter++; + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void EventHandler_OnElement_WithString() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void EventHandler_OnElement_WithNoArgsLambdaDelegate() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" + { })"" />"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void EventHandler_OnElement_WithEventArgsLambdaDelegate() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" + { })"" />"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void EventHandler_OnElement_WithNoArgMethodGroup() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" + +@functions { + void OnClick() { + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void EventHandler_OnElement_WithEventArgsMethodGroup() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" + +@functions { + void OnClick(UIMouseEventArgs e) { + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" + +@functions { + void OnClick(UIEventArgs e) { + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void AsyncEventHandler_OnElement_Action_MethodGroup() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@using System.Threading.Tasks + +@functions { + Task OnClick() + { + return Task.CompletedTask; + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void AsyncEventHandler_OnElement_ActionEventArgs_MethodGroup() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@using System.Threading.Tasks + +@functions { + Task OnClick(UIMouseEventArgs e) + { + return Task.CompletedTask; + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void AsyncEventHandler_OnElement_Action_Lambda() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@using System.Threading.Tasks + await Task.Delay(10)"" /> +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void AsyncEventHandler_OnElement_ActionEventArgs_Lambda() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@using System.Threading.Tasks + await Task.Delay(10)"" /> +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void EventHandler_OnElement_WithLambdaDelegate() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" + { })"" />"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void EventHandler_OnElement_WithDelegate() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" + +@functions { + void OnClick(UIMouseEventArgs e) { + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + #endregion + + #region Ref + + [Fact] + public void Element_WithRef() + { + // Arrange/Act + var generated = CompileToCSharp(@" +Hello + +@functions { + private Microsoft.AspNetCore.Blazor.ElementRef myElem; + public void Foo() { System.GC.KeepAlive(myElem); } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void Component_WithRef() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + } +} +")); + + // Arrange/Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +@functions { + private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void Component_WithRef_WithChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + } +} +")); + + // Arrange/Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + Some further content + + +@functions { + private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + #endregion + + #region Templates + + [Fact] + public void RazorTemplate_InCodeBlock() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@{ + RenderFragment p = (person) => @
@person.Name
; +} +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_InExplicitExpression() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@(RenderPerson((person) => @
@person.Name
)) +@functions { + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_NonGeneric_InImplicitExpression() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@RenderPerson(@
HI
) +@functions { + object RenderPerson(RenderFragment p) => null; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_Generic_InImplicitExpression() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@RenderPerson((person) => @
@person.Name
) +@functions { + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_ContainsComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ + RenderFragment p = (person) => @
; +} +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + // Targeted at the logic that assigns 'builder' names + [Fact] + public void RazorTemplate_FollowedByComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ + RenderFragment p = (person) => @
; +} + +@(""hello, world!"") + + +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_NonGeneric_AsComponentParameter() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] RenderFragment Template { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ RenderFragment template = @
Joey
; } + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_Generic_AsComponentParameter() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] RenderFragment PersonTemplate { get; set; } + } + + public class Person + { + public string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ RenderFragment template = (person) => @
@person.Name
; } + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_AsComponentParameter_MixedContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] RenderFragment Template { get; set; } + } + + public class Context + { + public int Index { get; set; } + public string Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ RenderFragment template = (context) => @
  • #@context.Index - @context.Item.ToLower()
  • ; } + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + #endregion + + #region Whitespace + + [Fact] + public void LeadingWhiteSpace_WithDirective() + { + // Arrange/Act + var generated = CompileToCSharp(@" + +@using System + +

    Hello

    "); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void LeadingWhiteSpace_WithCSharpExpression() + { + // Arrange/Act + var generated = CompileToCSharp(@" + +@(""My value"") + +

    Hello

    "); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void LeadingWhiteSpace_WithComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class SomeOtherComponent : BlazorComponent + { + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + + +

    Hello

    "); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void TrailingWhiteSpace_WithDirective() + { + // Arrange/Act + var generated = CompileToCSharp(@" +

    Hello

    + +@page ""/my/url"" + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void TrailingWhiteSpace_WithCSharpExpression() + { + // Arrange/Act + var generated = CompileToCSharp(@" +

    Hello

    + +@(""My value"") + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void TrailingWhiteSpace_WithComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class SomeOtherComponent : BlazorComponent + { + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +

    Hello

    + + + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + #endregion + + #region Misc + + [Fact] // We don't process - we just skip them + public void Component_WithDocType() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" + +
    +
    "); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ScriptTag_WithErrorSuppressed() + { + // Arrange/Act + var generated = CompileToCSharp(@" +
    + +
    +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] // https://github.com/aspnet/Blazor/issues/597 + public void Regression_597() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class Counter : BlazorComponent + { + public int Count { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + string y = null; +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void Regression_609() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class User : BlazorComponent + { + public string Name { get; set; } + public Action NameChanged { get; set; } + public bool IsActive { get; set; } + public Action IsActiveChanged { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +@functions { + public string UserName { get; set; } + public bool UserIsActive { get; set; } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] // https://github.com/aspnet/Blazor/issues/772 + public void Regression_772() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class SurveyPrompt : BlazorComponent + { + [Parameter] private string Title { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +@page ""/"" + +

    Hello, world!

    + +Welcome to your new app. + + d.Id), + d => Assert.Equal("RZ1034", d.Id), + d => Assert.Equal("RZ1035", d.Id)); + } + + [Fact] // https://github.com/aspnet/Blazor/issues/773 + public void Regression_773() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class SurveyPrompt : BlazorComponent + { + [Parameter] private string Title { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +@page ""/"" + +

    Hello, world!

    + +Welcome to your new app. + +Test!
    "" /> +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void Regression_784() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +

    +@functions { + public string ParentBgColor { get; set; } = ""#FFFFFF""; + + public void OnComponentHover(UIMouseEventArgs e) + { + } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + #endregion + } +} diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/ComponentRenderingRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/ComponentRenderingRazorIntegrationTest.cs index aa318bd98e..8451014691 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/ComponentRenderingRazorIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/ComponentRenderingRazorIntegrationTest.cs @@ -586,7 +586,7 @@ namespace Test var component = CompileToComponent(@" @addTagHelper ""*, TestAssembly"" -@{ RenderFragment template = @

    @context.ToLower()
    ; } +@{ RenderFragment template = (context) => @
    @context.ToLower()
    ; } "); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs index 82249842ca..858f6de540 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs @@ -1,1250 +1,10 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Linq; -using Xunit; - namespace Microsoft.AspNetCore.Blazor.Build.Test { - public class DesignTimeCodeGenerationTest : RazorBaselineIntegrationTestBase + public class DesignTimeCodeGenerationTest : CodeGenerationTestBase { internal override bool DesignTime => true; - - internal override bool UseTwoPhaseCompilation => true; - - [Fact] - public void ChildComponent_WithParameters() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class SomeType - { - } - - public class MyComponent : BlazorComponent - { - [Parameter] int IntProperty { get; set; } - [Parameter] bool BoolProperty { get; set; } - [Parameter] string StringProperty { get; set; } - [Parameter] SomeType ObjectProperty { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ComponentParameter_TypeMismatch_ReportsDiagnostic() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class CoolnessMeter : BlazorComponent - { - [Parameter] private int Coolness { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - - var assembly = CompileToAssembly(generated, throwOnFailure: false); - // This has some errors - Assert.Collection( - assembly.Diagnostics.OrderBy(d => d.Id), - d => Assert.Equal("CS1503", d.Id)); - } - - [Fact] - public void ChildComponent_WithExplicitStringParameter() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - string StringProperty { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithNonPropertyAttributes() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithLambdaEventHandler() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - Action OnClick { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - { Increment(); })""/> - -@functions { - private int counter; - private void Increment() { - counter++; - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - // Regression test for #954 - we need to allow arbitrary event handler - // attributes with weak typing. - [Fact] - public void ChildComponent_WithWeaklyTypeEventHandler() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class DynamicElement : BlazorComponent - { - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - -@functions { - private Action OnClick { get; set; } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithExplicitEventHandler() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - Action OnClick { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - -@functions { - private int counter; - private void Increment(UIEventArgs e) { - counter++; - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithChildContent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - string MyAttr { get; set; } - - [Parameter] - RenderFragment ChildContent { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -Some textNested text"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithElementOnlyChildContent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - RenderFragment ChildContent { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -hello"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void EventHandler_OnElement_WithString() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void EventHandler_OnElement_WithLambdaDelegate() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - { })"" />"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void EventHandler_OnElement_WithDelegate() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - -@functions { - void OnClick(UIMouseEventArgs e) { - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void AsyncEventHandler_OnElement_Action_MethodGroup() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@using System.Threading.Tasks - -@functions { - Task OnClick() - { - return Task.CompletedTask; - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void AsyncEventHandler_OnElement_ActionEventArgs_MethodGroup() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@using System.Threading.Tasks - -@functions { - Task OnClick(UIMouseEventArgs e) - { - return Task.CompletedTask; - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void AsyncEventHandler_OnElement_Action_Lambda() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@using System.Threading.Tasks - await Task.Delay(10)"" /> -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void AsyncEventHandler_OnElement_ActionEventArgs_Lambda() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@using System.Threading.Tasks - await Task.Delay(10)"" /> -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] // https://github.com/aspnet/Blazor/issues/597 - public void Regression_597() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class Counter : BlazorComponent - { - public int Count { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - string y = null; -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Regression_609() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class User : BlazorComponent - { - public string Name { get; set; } - public Action NameChanged { get; set; } - public bool IsActive { get; set; } - public Action IsActiveChanged { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - -@functions { - public string UserName { get; set; } - public bool UserIsActive { get; set; } -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] // https://github.com/aspnet/Blazor/issues/772 - public void Regression_772() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class SurveyPrompt : BlazorComponent - { - [Parameter] private string Title { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -@page ""/"" - -

    Hello, world!

    - -Welcome to your new app. - - d.Id), - d => Assert.Equal("RZ1034", d.Id), - d => Assert.Equal("RZ1035", d.Id)); - } - - [Fact] // https://github.com/aspnet/Blazor/issues/773 - public void Regression_773() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class SurveyPrompt : BlazorComponent - { - [Parameter] private string Title { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -@page ""/"" - -

    Hello, world!

    - -Welcome to your new app. - -Test!
    "" /> -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Regression_784() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -

    -@functions { - public string ParentBgColor { get; set; } = ""#FFFFFF""; - - public void OnComponentHover(UIMouseEventArgs e) - { - } -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToComponent_SpecifiesValue_WithMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - int Value { get; set; } - - [Parameter] - Action ValueChanged { get; set; } - } -}")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToComponent_TypeChecked_WithMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - int Value { get; set; } - - [Parameter] - Action ValueChanged { get; set; } - } -}")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public string ParentValue { get; set; } = ""42""; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - - var assembly = CompileToAssembly(generated, throwOnFailure: false); - // This has some errors - Assert.Collection( - assembly.Diagnostics.OrderBy(d => d.Id), - d => Assert.Equal("CS0029", d.Id), - d => Assert.Equal("CS1503", d.Id)); - } - - [Fact] - public void BindToComponent_SpecifiesValue_WithoutMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent, IComponent - { - void IComponent.SetParameters(ParameterCollection parameters) - { - } - } -}")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - int Value { get; set; } - - [Parameter] - Action OnChanged { get; set; } - } -}")); - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToComponent_SpecifiesValueAndChangeEvent_WithoutMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent, IComponent - { - void IComponent.SetParameters(ParameterCollection parameters) - { - } - } -}")); - - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToElement_WritesAttributes() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - [BindElement(""div"", null, ""myvalue"", ""myevent"")] - public static class BindAttributes - { - } -}")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -

    -@functions { - public string ParentValue { get; set; } = ""hi""; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToElementWithSuffix_WritesAttributes() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - [BindElement(""div"", ""value"", ""myvalue"", ""myevent"")] - public static class BindAttributes - { - } -}")); - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -
    -@functions { - public string ParentValue { get; set; } = ""hi""; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputWithoutType_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputText_WithFormat_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputText_WithFormatFromProperty_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); - - public string Format { get; set; } = ""MM/dd/yyyy""; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputText_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputCheckbox_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public bool Enabled { get; set; } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToElementFallback_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToElementFallback_WithFormat_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Element_WithRef() - { - // Arrange/Act - var generated = CompileToCSharp(@" -Hello - -@functions { - Microsoft.AspNetCore.Blazor.ElementRef myElem; - - void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Component_WithRef() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - -@functions { - Test.MyComponent myInstance; - - void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] // We don't process - we just skip them - public void Component_WithDocType() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - -
    -
    "); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_InCodeBlock() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@{ - RenderFragment p = @
    @context.Name
    ; -} -@functions { - class Person - { - public string Name { get; set; } - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - - [Fact] - public void RazorTemplate_InExplicitExpression() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@(RenderPerson(@
    @context.Name
    )) -@functions { - class Person - { - public string Name { get; set; } - } - - object RenderPerson(RenderFragment p) => null; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_InImplicitExpression() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@RenderPerson(@
    @context.Name
    ) -@functions { - class Person - { - public string Name { get; set; } - } - - object RenderPerson(RenderFragment p) => null; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_ContainsComponent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] string Name { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper ""*, TestAssembly"" -@{ - RenderFragment p = @
    ; -} -@functions { - class Person - { - public string Name { get; set; } - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - // Targeted at the logic that assigns 'builder' names - [Fact] - public void RazorTemplate_FollowedByComponent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] string Name { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper ""*, TestAssembly"" -@{ - RenderFragment p = @
    ; -} - -@(""hello, world!"") - - -@functions { - class Person - { - public string Name { get; set; } - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_AsComponentParameter() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] RenderFragment PersonTemplate { get; set; } - } - - public class Person - { - public string Name { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper ""*, TestAssembly"" -@{ RenderFragment template = @
    @context.Name
    ; } - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_AsComponentParameter_MixedContent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] RenderFragment Template { get; set; } - } - - public class Context - { - public int Index { get; set; } - public string Item { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper ""*, TestAssembly"" -@{ RenderFragment template = @
  • #@context.Index - @context.Item.ToLower()
  • ; } - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } } } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/InitializeTestFileAttribute.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/InitializeTestFileAttribute.cs index 2add553f5b..c4bb636f35 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/InitializeTestFileAttribute.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/InitializeTestFileAttribute.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; @@ -11,16 +11,16 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests { public override void Before(MethodInfo methodUnderTest) { - if (typeof(RazorBaselineIntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo())) + if (typeof(RazorBaselineIntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.ReflectedType.GetTypeInfo())) { - var typeName = methodUnderTest.DeclaringType.Name; + var typeName = methodUnderTest.ReflectedType.Name; RazorBaselineIntegrationTestBase.DirectoryPath = $"TestFiles/{typeName}/{methodUnderTest.Name}"; } } public override void After(MethodInfo methodUnderTest) { - if (typeof(RazorBaselineIntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.DeclaringType.GetTypeInfo())) + if (typeof(RazorBaselineIntegrationTestBase).GetTypeInfo().IsAssignableFrom(methodUnderTest.ReflectedType.GetTypeInfo())) { RazorBaselineIntegrationTestBase.DirectoryPath = null; } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/IntermediateNodeWriter.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/IntermediateNodeWriter.cs index daf38c1251..4e39b09cec 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/IntermediateNodeWriter.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/IntermediateNodeWriter.cs @@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor, + IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor { @@ -285,6 +286,11 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests WriteContentNode(node, node.AttributeName, node.PropertyName); } + void IExtensionIntermediateNodeVisitor.VisitExtension(ComponentChildContentIntermediateNode node) + { + WriteContentNode(node, node.AttributeName); + } + void IExtensionIntermediateNodeVisitor.VisitExtension(RouteAttributeExtensionNode node) { WriteContentNode(node, node.Template); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs index a51499c39c..2457c44efb 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs @@ -600,14 +600,14 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test public enum MyEnum { FirstValue, SecondValue } [Fact] - public void RazorTemplate_CanBeUsedFromRazorCode() + public void RazorTemplate_NonGeneric_CanBeUsedFromRazorCode() { // Arrange var component = CompileToComponent(@" -@{ RenderFragment template = @
    @context.ToLower()
    ; } +@{ RenderFragment template = @
    @(""Hello, World!"".ToLower())
    ; } @for (var i = 0; i < 3; i++) { - @template.WithValue(""Hello, World!""); + @template; } "); @@ -626,11 +626,75 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test } [Fact] - public void RazorTemplate_CanBeUsedFromMethod() + public void RazorTemplate_Generic_CanBeUsedFromRazorCode() { // Arrange var component = CompileToComponent(@" -@(Repeat(@
    @context.ToLower()
    , ""Hello, World!"", 3)) +@{ RenderFragment template = (context) => @
    @context.ToLower()
    ; } +@for (var i = 0; i < 3; i++) +{ + @template(""Hello, World!""); +} +"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1)); + } + + [Fact] + public void RazorTemplate_NonGeneric_CanBeUsedFromMethod() + { + // Arrange + var component = CompileToComponent(@" +@(Repeat(@
    @(""Hello, World!"".ToLower())
    , 3)) + +@functions { + RenderFragment Repeat(RenderFragment template, int count) + { + return (b) => + { + for (var i = 0; i < count; i++) + { + b.AddContent(i, template); + } + }; + } +}"); + + // Act + var frames = GetRenderTree(component); + + // Assert + // + // The sequence numbers start at 1 here because there is an AddContent(0, Repeat(....) call + // that precedes the definition of the lambda. Sequence numbers for the lambda are allocated + // from the same logical sequence as the surrounding code. + Assert.Collection( + frames, + frame => AssertFrame.Element(frame, "div", 2, 1), + frame => AssertFrame.Text(frame, "hello, world!", 2), + frame => AssertFrame.Element(frame, "div", 2, 1), + frame => AssertFrame.Text(frame, "hello, world!", 2), + frame => AssertFrame.Element(frame, "div", 2, 1), + frame => AssertFrame.Text(frame, "hello, world!", 2)); + } + + [Fact] + public void RazorTemplate_Generic_CanBeUsedFromMethod() + { + // Arrange + var component = CompileToComponent(@" +@(Repeat((context) => @
    @context.ToLower()
    , ""Hello, World!"", 3)) @functions { RenderFragment Repeat(RenderFragment template, T value, int count) @@ -639,7 +703,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test { for (var i = 0; i < count; i++) { - template(b, value); + b.AddContent(i, template, value); } }; } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs index 5e48e4bf6b..271daee854 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs @@ -1,1489 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Linq; -using Xunit; - namespace Microsoft.AspNetCore.Blazor.Build.Test { - public class RuntimeCodeGenerationTest : RazorBaselineIntegrationTestBase - { - internal override bool UseTwoPhaseCompilation => true; - - [Fact] - public void ChildComponent_Simple() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent + public class RuntimeCodeGenerationTest : CodeGenerationTestBase { } } -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithParameters() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class SomeType - { - } - - public class MyComponent : BlazorComponent - { - [Parameter] int IntProperty { get; set; } - [Parameter] bool BoolProperty { get; set; } - [Parameter] string StringProperty { get; set; } - [Parameter] SomeType ObjectProperty { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithExplicitStringParameter() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - string StringProperty { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithNonPropertyAttributes() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - - [Fact] - public void ChildComponent_WithLambdaEventHandler() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - Action OnClick { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - { Increment(); })""/> - -@functions { - private int counter; - private void Increment() { - counter++; - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - // Regression test for #954 - we need to allow arbitrary event handler - // attributes with weak typing. - [Fact] - public void ChildComponent_WithWeaklyTypeEventHandler() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class DynamicElement : BlazorComponent - { - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - -@functions { - private Action OnClick { get; set; } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithExplicitEventHandler() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - Action OnClick { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - -@functions { - private int counter; - private void Increment(UIEventArgs e) { - counter++; - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithChildContent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - string MyAttr { get; set; } - - [Parameter] - RenderFragment ChildContent { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -Some textNested text"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithElementOnlyChildContent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - RenderFragment ChildContent { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -hello"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ChildComponent_WithPageDirective() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -@page ""/MyPage"" -@page ""/AnotherRoute/{id}"" -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ComponentParameter_TypeMismatch_ReportsDiagnostic() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class CoolnessMeter : BlazorComponent - { - [Parameter] private int Coolness { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - - var assembly = CompileToAssembly(generated, throwOnFailure: false); - // This has some errors - Assert.Collection( - assembly.Diagnostics.OrderBy(d => d.Id), - d => Assert.Equal("CS1503", d.Id)); - } - - [Fact] - public void EventHandler_OnElement_WithString() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void EventHandler_OnElement_WithNoArgsLambdaDelegate() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - { })"" />"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void EventHandler_OnElement_WithEventArgsLambdaDelegate() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - { })"" />"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void EventHandler_OnElement_WithNoArgMethodGroup() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - -@functions { - void OnClick() { - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void EventHandler_OnElement_WithEventArgsMethodGroup() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - -@functions { - void OnClick(UIMouseEventArgs e) { - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - -@functions { - void OnClick(UIEventArgs e) { - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void AsyncEventHandler_OnElement_Action_MethodGroup() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@using System.Threading.Tasks - -@functions { - Task OnClick() - { - return Task.CompletedTask; - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void AsyncEventHandler_OnElement_ActionEventArgs_MethodGroup() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@using System.Threading.Tasks - -@functions { - Task OnClick(UIMouseEventArgs e) - { - return Task.CompletedTask; - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void AsyncEventHandler_OnElement_Action_Lambda() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@using System.Threading.Tasks - await Task.Delay(10)"" /> -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void AsyncEventHandler_OnElement_ActionEventArgs_Lambda() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@using System.Threading.Tasks - await Task.Delay(10)"" /> -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void ScriptTag_WithErrorSuppressed() - { - // Arrange/Act - var generated = CompileToCSharp(@" -
    - -
    -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void LeadingWhiteSpace_WithDirective() - { - // Arrange/Act - var generated = CompileToCSharp(@" - -@using System - -

    Hello

    "); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void LeadingWhiteSpace_WithCSharpExpression() - { - // Arrange/Act - var generated = CompileToCSharp(@" - -@(""My value"") - -

    Hello

    "); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void LeadingWhiteSpace_WithComponent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class SomeOtherComponent : BlazorComponent - { - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - - -

    Hello

    "); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void TrailingWhiteSpace_WithDirective() - { - // Arrange/Act - var generated = CompileToCSharp(@" -

    Hello

    - -@page ""/my/url"" - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void TrailingWhiteSpace_WithCSharpExpression() - { - // Arrange/Act - var generated = CompileToCSharp(@" -

    Hello

    - -@(""My value"") - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void TrailingWhiteSpace_WithComponent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class SomeOtherComponent : BlazorComponent - { - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -

    Hello

    - - - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] // https://github.com/aspnet/Blazor/issues/597 - public void Regression_597() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class Counter : BlazorComponent - { - public int Count { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - string y = null; -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Regression_609() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class User : BlazorComponent - { - public string Name { get; set; } - public Action NameChanged { get; set; } - public bool IsActive { get; set; } - public Action IsActiveChanged { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - -@functions { - public string UserName { get; set; } - public bool UserIsActive { get; set; } -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] // https://github.com/aspnet/Blazor/issues/772 - public void Regression_772() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class SurveyPrompt : BlazorComponent - { - [Parameter] private string Title { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -@page ""/"" - -

    Hello, world!

    - -Welcome to your new app. - - d.Id), - d => Assert.Equal("RZ1034", d.Id), - d => Assert.Equal("RZ1035", d.Id)); - } - - [Fact] // https://github.com/aspnet/Blazor/issues/773 - public void Regression_773() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class SurveyPrompt : BlazorComponent - { - [Parameter] private string Title { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -@page ""/"" - -

    Hello, world!

    - -Welcome to your new app. - -Test!
    "" /> -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Regression_784() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -

    -@functions { - public string ParentBgColor { get; set; } = ""#FFFFFF""; - - public void OnComponentHover(UIMouseEventArgs e) - { - } -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToComponent_SpecifiesValue_WithMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - int Value { get; set; } - - [Parameter] - Action ValueChanged { get; set; } - } -}")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToComponent_SpecifiesValue_WithoutMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent, IComponent - { - void IComponent.SetParameters(ParameterCollection parameters) - { - } - } -}")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToComponent_SpecifiesValueAndChangeEvent_WithMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] - int Value { get; set; } - - [Parameter] - Action OnChanged { get; set; } - } -}")); - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToComponent_SpecifiesValueAndChangeEvent_WithoutMatchingProperties() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent, IComponent - { - void IComponent.SetParameters(ParameterCollection parameters) - { - } - } -}")); - - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToElement_WritesAttributes() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - [BindElement(""div"", null, ""myvalue"", ""myevent"")] - public static class BindAttributes - { - } -}")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -

    -@functions { - public string ParentValue { get; set; } = ""hi""; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToElementWithSuffix_WritesAttributes() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using System; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - [BindElement(""div"", ""value"", ""myvalue"", ""myevent"")] - public static class BindAttributes - { - } -}")); - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly -
    -@functions { - public string ParentValue { get; set; } = ""hi""; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputWithoutType_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputText_WithFormat_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputText_WithFormatFromProperty_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); - - public string Format { get; set; } = ""MM/dd/yyyy""; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputText_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BuiltIn_BindToInputCheckbox_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public bool Enabled { get; set; } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToElementFallback_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public int ParentValue { get; set; } = 42; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void BindToElementFallback_WithFormat_WritesAttributes() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - -@functions { - public DateTime CurrentDate { get; set; } = new DateTime(2018, 1, 1); -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Element_WithRef() - { - // Arrange/Act - var generated = CompileToCSharp(@" -Hello - -@functions { - private Microsoft.AspNetCore.Blazor.ElementRef myElem; -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Component_WithRef() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - } -} -")); - - // Arrange/Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - -@functions { - private Test.MyComponent myInstance; -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void Component_WithRef_WithChildContent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - } -} -")); - - // Arrange/Act - var generated = CompileToCSharp(@" -@addTagHelper *, TestAssembly - - Some further content - - -@functions { - private Test.MyComponent myInstance; -} -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] // We don't process - we just skip them - public void Component_WithDocType() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" - -
    -
    "); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_InCodeBlock() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@{ - RenderFragment p = @
    @context.Name
    ; -} -@functions { - class Person - { - public string Name { get; set; } - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - - [Fact] - public void RazorTemplate_InExplicitExpression() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@(RenderPerson(@
    @context.Name
    )) -@functions { - class Person - { - public string Name { get; set; } - } - - object RenderPerson(RenderFragment p) => null; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_InImplicitExpression() - { - // Arrange - - // Act - var generated = CompileToCSharp(@" -@RenderPerson(@
    @context.Name
    ) -@functions { - class Person - { - public string Name { get; set; } - } - - object RenderPerson(RenderFragment p) => null; -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_ContainsComponent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] string Name { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper ""*, TestAssembly"" -@{ - RenderFragment p = @
    ; -} -@functions { - class Person - { - public string Name { get; set; } - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - // Targeted at the logic that assigns 'builder' names - [Fact] - public void RazorTemplate_FollowedByComponent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] string Name { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper ""*, TestAssembly"" -@{ - RenderFragment p = @
    ; -} - -@(""hello, world!"") - - -@functions { - class Person - { - public string Name { get; set; } - } -}"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_AsComponentParameter() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] RenderFragment PersonTemplate { get; set; } - } - - public class Person - { - public string Name { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper ""*, TestAssembly"" -@{ RenderFragment template = @
    @context.Name
    ; } - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - - [Fact] - public void RazorTemplate_AsComponentParameter_MixedContent() - { - // Arrange - AdditionalSyntaxTrees.Add(Parse(@" -using Microsoft.AspNetCore.Blazor; -using Microsoft.AspNetCore.Blazor.Components; - -namespace Test -{ - public class MyComponent : BlazorComponent - { - [Parameter] RenderFragment Template { get; set; } - } - - public class Context - { - public int Index { get; set; } - public string Item { get; set; } - } -} -")); - - // Act - var generated = CompileToCSharp(@" -@addTagHelper ""*, TestAssembly"" -@{ RenderFragment template = @
  • #@context.Index - @context.Item.ToLower()
  • ; } - -"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); - CompileToAssembly(generated); - } - } -} diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TemplateRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TemplateRazorIntegrationTest.cs index fdc02afd37..a94bbc7233 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TemplateRazorIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TemplateRazorIntegrationTest.cs @@ -5,7 +5,7 @@ using Xunit; namespace Microsoft.AspNetCore.Blazor.Build.Test { - public class TemplateRazorIntegrationTest : RazorBaselineIntegrationTestBase + public class TemplateRazorIntegrationTest : RazorIntegrationTestBase { // Razor doesn't parse this as a template, we don't need much special handling for // it because it will just be invalid in general. diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..874370cd3d --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.codegen.cs @@ -0,0 +1,60 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment header = (context) => + +#line default +#line hidden + (builder2) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.ToLowerInvariant(); + +#line default +#line hidden + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + __o = new Microsoft.AspNetCore.Blazor.RenderFragment( +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + header + +#line default +#line hidden + ); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..81cff48b37 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.ir.txt @@ -0,0 +1,39 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment header = (context) => + Template - (80:1,49 [37] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (80:1,49 [38] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant() + CSharpCode - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (123:2,0 [62] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (151:2,28 [20] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (151:2,28 [20] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some Content\n + ComponentAttributeExtensionNode - (143:2,20 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Header - Header + CSharpExpression - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - header diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..23e2dfcacf --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.mappings.txt @@ -0,0 +1,25 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment header = (context) => | +Generated Location: (1039:29,2 [46] ) +| RenderFragment header = (context) => | + +Source Location: (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) +|context.ToLowerInvariant()| +Generated Location: (1253:35,55 [26] ) +|context.ToLowerInvariant()| + +Source Location: (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1466:41,87 [2] ) +|; | + +Source Location: (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) +|header| +Generated Location: (1655:47,21 [6] ) +|header| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..7704b55c64 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.codegen.cs @@ -0,0 +1,63 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment header = (context) => + +#line default +#line hidden + (builder2) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.ToLowerInvariant(); + +#line default +#line hidden + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + __o = new Microsoft.AspNetCore.Blazor.RenderFragment( +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + header + +#line default +#line hidden + ); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + builder.AddAttribute(-1, "Footer", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..e47457aeee --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.ir.txt @@ -0,0 +1,42 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment header = (context) => + Template - (80:1,49 [37] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (80:1,49 [38] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant() + CSharpCode - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (123:2,0 [114] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (155:3,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + HtmlContent - (169:3,16 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (169:3,16 [12] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some Content + ComponentChildContent - (200:4,2 [21] x:\dir\subdir\Test\TestComponent.cshtml) - Footer + HtmlContent - (208:4,10 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (208:4,10 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Bye! + ComponentAttributeExtensionNode - (143:2,20 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Header - Header + CSharpExpression - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - header diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..23e2dfcacf --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.mappings.txt @@ -0,0 +1,25 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment header = (context) => | +Generated Location: (1039:29,2 [46] ) +| RenderFragment header = (context) => | + +Source Location: (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) +|context.ToLowerInvariant()| +Generated Location: (1253:35,55 [26] ) +|context.ToLowerInvariant()| + +Source Location: (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1466:41,87 [2] ) +|; | + +Source Location: (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) +|header| +Generated Location: (1655:47,21 [6] ) +|header| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.codegen.cs new file mode 100644 index 0000000000..37a3009656 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.codegen.cs @@ -0,0 +1,36 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.ir.txt new file mode 100644 index 0000000000..c716464868 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.ir.txt @@ -0,0 +1,25 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (31:1,0 [15] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.mappings.txt new file mode 100644 index 0000000000..75b2c90a92 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Simple/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.ir.txt index ac6736fae4..c921265f1a 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.ir.txt @@ -23,14 +23,15 @@ Document - HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n ComponentExtensionNode - (31:1,0 [91] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text - HtmlElement - (66:1,35 [42] x:\dir\subdir\Test\TestComponent.cshtml) - some-child - HtmlAttribute - - - - HtmlAttributeValue - - - IntermediateToken - - Html - 1 - HtmlContent - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Nested text + ComponentChildContent - - ChildContent + HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text + HtmlElement - (66:1,35 [42] x:\dir\subdir\Test\TestComponent.cshtml) - some-child + HtmlAttribute - - - + HtmlAttributeValue - - + IntermediateToken - - Html - 1 + HtmlContent - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Nested text ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithElementOnlyChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithElementOnlyChildContent/TestComponent.ir.txt index be1cbcc72b..9dc149f9ce 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithElementOnlyChildContent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithElementOnlyChildContent/TestComponent.ir.txt @@ -23,6 +23,7 @@ Document - HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n ComponentExtensionNode - (31:1,0 [47] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - HtmlElement - (44:1,13 [20] x:\dir\subdir\Test\TestComponent.cshtml) - child - HtmlContent - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - hello + ComponentChildContent - - ChildContent + HtmlElement - (44:1,13 [20] x:\dir\subdir\Test\TestComponent.cshtml) - child + HtmlContent - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - hello diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..37a3009656 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.codegen.cs @@ -0,0 +1,36 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..8b2563d0d8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.ir.txt @@ -0,0 +1,28 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (31:1,0 [61] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (44:1,13 [34] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + HtmlContent - (58:1,27 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (58:1,27 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - hello diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..75b2c90a92 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..d651e6bdb1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.codegen.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((context) => (builder2) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context; + +#line default +#line hidden + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..2304ddd218 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.ir.txt @@ -0,0 +1,28 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (31:1,0 [64] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (44:1,13 [37] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + CSharpExpression - (59:1,28 [7] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (59:1,28 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..940513b3ec --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (59:1,28 [7] x:\dir\subdir\Test\TestComponent.cshtml) +|context| +Generated Location: (1208:30,28 [7] ) +|context| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..781ebf72c9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.codegen.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((context) => (builder2) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.ToLowerInvariant(); + +#line default +#line hidden + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..f493489dfe --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.ir.txt @@ -0,0 +1,37 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (31:1,0 [107] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text + HtmlElement - (66:1,35 [58] x:\dir\subdir\Test\TestComponent.cshtml) - some-child + HtmlAttribute - - - + HtmlAttributeValue - - + IntermediateToken - - Html - 1 + CSharpExpression - (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant() + ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr + HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..902f1572d2 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml) +|context.ToLowerInvariant()| +Generated Location: (1234:30,54 [26] ) +|context.ToLowerInvariant()| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.codegen.cs new file mode 100644 index 0000000000..1b1a8b108c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.codegen.cs @@ -0,0 +1,41 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((item) => (builder2) => { +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = item.ToLowerInvariant(); + +#line default +#line hidden + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.ir.txt new file mode 100644 index 0000000000..9e4657e098 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.ir.txt @@ -0,0 +1,39 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (31:1,0 [164] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (61:2,2 [118] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + HtmlContent - (90:2,31 [15] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (90:2,31 [15] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some text + HtmlElement - (105:3,13 [55] x:\dir\subdir\Test\TestComponent.cshtml) - some-child + HtmlAttribute - - - + HtmlAttributeValue - - + IntermediateToken - - Html - 1 + CSharpExpression - (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - item.ToLowerInvariant() + HtmlContent - (160:3,68 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (160:3,68 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr + HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.mappings.txt new file mode 100644 index 0000000000..585184e8bb --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) +|item.ToLowerInvariant()| +Generated Location: (1209:30,32 [23] ) +|item.ToLowerInvariant()| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.codegen.cs index 665a271300..64e8e3703f 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.codegen.cs @@ -28,7 +28,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; base.BuildRenderTree(builder); __o = new System.Action( #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - (e) => { Increment(); } + e => { Increment(); } #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.ir.txt index 9ab3373d6f..f5eec3c96d 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.ir.txt @@ -22,11 +22,11 @@ Document - IntermediateToken - - CSharp - base.BuildRenderTree(builder); HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - ComponentExtensionNode - (31:1,0 [51] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - ComponentAttributeExtensionNode - (53:1,22 [26] x:\dir\subdir\Test\TestComponent.cshtml) - OnClick - OnClick - CSharpExpression - (54:1,23 [25] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (55:1,24 [23] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - (e) => { Increment(); } - HtmlContent - (82:1,51 [4] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (82:1,51 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n - CSharpCode - (98:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (98:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private int counter;\n private void Increment() {\n counter++;\n }\n + ComponentExtensionNode - (31:1,0 [49] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (53:1,22 [24] x:\dir\subdir\Test\TestComponent.cshtml) - OnClick - OnClick + CSharpExpression - (54:1,23 [23] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (55:1,24 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - e => { Increment(); } + HtmlContent - (80:1,49 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (80:1,49 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + CSharpCode - (96:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (96:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private int counter;\n private void Increment() {\n counter++;\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.mappings.txt index f938240b14..175657d740 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithLambdaEventHandler/TestComponent.mappings.txt @@ -3,19 +3,19 @@ Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (559:16,38 [15] ) |*, TestAssembly| -Source Location: (55:1,24 [23] x:\dir\subdir\Test\TestComponent.cshtml) -|(e) => { Increment(); }| -Generated Location: (1140:30,24 [23] ) -|(e) => { Increment(); }| +Source Location: (55:1,24 [21] x:\dir\subdir\Test\TestComponent.cshtml) +|e => { Increment(); }| +Generated Location: (1140:30,24 [21] ) +|e => { Increment(); }| -Source Location: (98:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (96:3,12 [87] x:\dir\subdir\Test\TestComponent.cshtml) | private int counter; private void Increment() { counter++; } | -Generated Location: (1471:41,12 [87] ) +Generated Location: (1469:41,12 [87] ) | private int counter; private void Increment() { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.codegen.cs new file mode 100644 index 0000000000..aa907c15d3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.codegen.cs @@ -0,0 +1,46 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + [Microsoft.AspNetCore.Blazor.Components.RouteAttribute("/MyPage")] + [Microsoft.AspNetCore.Blazor.Components.RouteAttribute("/AnotherRoute/{id}")] + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + ((System.Action)(() => { +global::System.Object __typeHelper = "/MyPage"; + } + ))(); + ((System.Action)(() => { +global::System.Object __typeHelper = "/AnotherRoute/{id}"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.ir.txt new file mode 100644 index 0000000000..f87c22ab81 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.ir.txt @@ -0,0 +1,29 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + RouteAttributeExtensionNode - - /MyPage + RouteAttributeExtensionNode - - /AnotherRoute/{id} + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + DirectiveToken - (37:1,6 [9] x:\dir\subdir\Test\TestComponent.cshtml) - "/MyPage" + DirectiveToken - (54:2,6 [20] x:\dir\subdir\Test\TestComponent.cshtml) - "/AnotherRoute/{id}" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (76:3,0 [15] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.mappings.txt new file mode 100644 index 0000000000..53489fb33f --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithPageDirective/TestComponent.mappings.txt @@ -0,0 +1,15 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (714:18,38 [15] ) +|*, TestAssembly| + +Source Location: (37:1,6 [9] x:\dir\subdir\Test\TestComponent.cshtml) +|"/MyPage"| +Generated Location: (830:22,37 [9] ) +|"/MyPage"| + +Source Location: (54:2,6 [20] x:\dir\subdir\Test\TestComponent.cshtml) +|"/AnotherRoute/{id}"| +Generated Location: (939:26,37 [20] ) +|"/AnotherRoute/{id}"| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.codegen.cs index 054893de86..8710dff3b6 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.codegen.cs @@ -38,9 +38,8 @@ global::System.Object __typeHelper = "*, TestAssembly"; #pragma warning restore 1998 #line 4 "x:\dir\subdir\Test\TestComponent.cshtml" - Test.MyComponent myInstance; - - void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning + private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.ir.txt index d472c3cd92..adee9b617c 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.ir.txt @@ -32,7 +32,7 @@ Document - IntermediateToken - (94:1,63 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - after HtmlContent - (103:1,72 [4] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (103:1,72 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n - HtmlContent - (253:7,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (253:7,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpCode - (119:3,12 [133] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (119:3,12 [133] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n Test.MyComponent myInstance;\n\n void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning\n + HtmlContent - (224:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (224:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Test.MyComponent myInstance;\n public void Foo() { System.GC.KeepAlive(myInstance); }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.mappings.txt index 61b26413c6..23bc888573 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef/TestComponent.mappings.txt @@ -8,16 +8,14 @@ Source Location: (70:1,39 [10] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (1223:32,39 [10] ) |myInstance| -Source Location: (119:3,12 [133] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) | - Test.MyComponent myInstance; - - void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning + private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } | -Generated Location: (1407:39,12 [133] ) +Generated Location: (1407:39,12 [104] ) | - Test.MyComponent myInstance; - - void DoSomething() { myInstance.GetHashCode(); } // Avoid 'assigned but not used' warning + private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..8e1d3edc04 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.codegen.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + myInstance = default(Test.MyComponent); + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 6 "x:\dir\subdir\Test\TestComponent.cshtml" + + private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..8bcf5f5a02 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.ir.txt @@ -0,0 +1,43 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (31:1,0 [96] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some + HtmlElement - (87:2,9 [16] x:\dir\subdir\Test\TestComponent.cshtml) - el + HtmlContent - (91:2,13 [7] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (91:2,13 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - further + HtmlContent - (103:2,25 [10] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (103:2,25 [10] x:\dir\subdir\Test\TestComponent.cshtml) - Html - content\n + RefExtensionNode - (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml) - myInstance - Test.MyComponent + ComponentAttributeExtensionNode - - SomeProp - + HtmlContent - (71:1,40 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (71:1,40 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - val + HtmlContent - (127:3,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (127:3,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlContent - (248:8,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (248:8,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Test.MyComponent myInstance;\n public void Foo() { System.GC.KeepAlive(myInstance); }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..49b2528ce4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.mappings.txt @@ -0,0 +1,21 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml) +|myInstance| +Generated Location: (1202:32,18 [10] ) +|myInstance| + +Source Location: (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) +| + private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } +| +Generated Location: (1386:39,12 [104] ) +| + private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.codegen.cs index c29205053a..c430656f63 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.codegen.cs @@ -31,9 +31,8 @@ namespace Test #pragma warning restore 1998 #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" - Microsoft.AspNetCore.Blazor.ElementRef myElem; - - void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning + private Microsoft.AspNetCore.Blazor.ElementRef myElem; + public void Foo() { System.GC.KeepAlive(myElem); } #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.ir.txt index bdf90a1f8c..2c8d389e39 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.ir.txt @@ -31,7 +31,7 @@ Document - IntermediateToken - (60:0,60 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - after HtmlContent - (79:0,79 [4] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (79:0,79 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n - HtmlContent - (243:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (243:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpCode - (95:2,12 [147] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (95:2,12 [147] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n Microsoft.AspNetCore.Blazor.ElementRef myElem;\n\n void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning\n + HtmlContent - (214:5,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (214:5,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Microsoft.AspNetCore.Blazor.ElementRef myElem;\n public void Foo() { System.GC.KeepAlive(myElem); }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.mappings.txt index cd0b6cb8cb..9cc58eaa96 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Element_WithRef/TestComponent.mappings.txt @@ -3,16 +3,14 @@ Source Location: (36:0,36 [6] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (956:25,36 [6] ) |myElem| -Source Location: (95:2,12 [147] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml) | - Microsoft.AspNetCore.Blazor.ElementRef myElem; - - void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning + private Microsoft.AspNetCore.Blazor.ElementRef myElem; + public void Foo() { System.GC.KeepAlive(myElem); } | -Generated Location: (1158:32,12 [147] ) +Generated Location: (1158:32,12 [118] ) | - Microsoft.AspNetCore.Blazor.ElementRef myElem; - - void DoSomething() { myElem.GetHashCode(); } // Avoid 'assigned but not used' warning + private Microsoft.AspNetCore.Blazor.ElementRef myElem; + public void Foo() { System.GC.KeepAlive(myElem); } | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.codegen.cs new file mode 100644 index 0000000000..f959903880 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.codegen.cs @@ -0,0 +1,37 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue(OnClick); + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + void OnClick(UIEventArgs e) { + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.ir.txt new file mode 100644 index 0000000000..4e62bc1fb6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [28] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - (16:0,16 [8] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - " + CSharpExpressionAttributeValue - - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue( + IntermediateToken - (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - OnClick + IntermediateToken - - CSharp - ) + HtmlContent - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (42:1,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (42:1,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void OnClick(UIEventArgs e) {\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.mappings.txt new file mode 100644 index 0000000000..c85b977fbd --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_ArbitraryEventName_WithEventArgsMethodGroup/TestComponent.mappings.txt @@ -0,0 +1,16 @@ +Source Location: (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) +|OnClick| +Generated Location: (1005:24,136 [7] ) +|OnClick| + +Source Location: (42:1,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) +| + void OnClick(UIEventArgs e) { + } +| +Generated Location: (1128:28,12 [44] ) +| + void OnClick(UIEventArgs e) { + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.codegen.cs new file mode 100644 index 0000000000..9e6ebcefbd --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.codegen.cs @@ -0,0 +1,30 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue(x => { }); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.ir.txt new file mode 100644 index 0000000000..c67fddb05a --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.ir.txt @@ -0,0 +1,27 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [31] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - (16:0,16 [11] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - " + CSharpExpressionAttributeValue - - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue( + IntermediateToken - (18:0,18 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - x => { } + IntermediateToken - - CSharp - ) diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.mappings.txt new file mode 100644 index 0000000000..2da1e51570 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsLambdaDelegate/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (18:0,18 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|x => { }| +Generated Location: (1005:24,136 [8] ) +|x => { }| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.codegen.cs new file mode 100644 index 0000000000..4c994b80df --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.codegen.cs @@ -0,0 +1,37 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue(OnClick); + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + void OnClick(UIMouseEventArgs e) { + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.ir.txt new file mode 100644 index 0000000000..1637168f24 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [28] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - (16:0,16 [8] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - " + CSharpExpressionAttributeValue - - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue( + IntermediateToken - (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - OnClick + IntermediateToken - - CSharp - ) + HtmlContent - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void OnClick(UIMouseEventArgs e) {\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.mappings.txt new file mode 100644 index 0000000000..646a3d5f65 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithEventArgsMethodGroup/TestComponent.mappings.txt @@ -0,0 +1,16 @@ +Source Location: (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) +|OnClick| +Generated Location: (1005:24,136 [7] ) +|OnClick| + +Source Location: (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) +| + void OnClick(UIMouseEventArgs e) { + } +| +Generated Location: (1128:28,12 [49] ) +| + void OnClick(UIMouseEventArgs e) { + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.codegen.cs new file mode 100644 index 0000000000..7a84a849de --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.codegen.cs @@ -0,0 +1,37 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue(OnClick); + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + void OnClick() { + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.ir.txt new file mode 100644 index 0000000000..09083f3dec --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [28] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - (16:0,16 [8] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - " + CSharpExpressionAttributeValue - - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue( + IntermediateToken - (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - OnClick + IntermediateToken - - CSharp - ) + HtmlContent - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (28:0,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (42:1,12 [31] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (42:1,12 [31] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void OnClick() {\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.mappings.txt new file mode 100644 index 0000000000..c6fefa55b1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgMethodGroup/TestComponent.mappings.txt @@ -0,0 +1,16 @@ +Source Location: (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) +|OnClick| +Generated Location: (1005:24,136 [7] ) +|OnClick| + +Source Location: (42:1,12 [31] x:\dir\subdir\Test\TestComponent.cshtml) +| + void OnClick() { + } +| +Generated Location: (1128:28,12 [31] ) +| + void OnClick() { + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.codegen.cs new file mode 100644 index 0000000000..2b38a71db1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.codegen.cs @@ -0,0 +1,30 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue(() => { }); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.ir.txt new file mode 100644 index 0000000000..af1e2ba553 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.ir.txt @@ -0,0 +1,27 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [32] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - (16:0,16 [12] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - " + CSharpExpressionAttributeValue - - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue( + IntermediateToken - (18:0,18 [9] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - () => { } + IntermediateToken - - CSharp - ) diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.mappings.txt new file mode 100644 index 0000000000..8e4e60f6b0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/EventHandler_OnElement_WithNoArgsLambdaDelegate/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (18:0,18 [9] x:\dir\subdir\Test\TestComponent.cshtml) +|() => { }| +Generated Location: (1005:24,136 [9] ) +|() => { }| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..60ed593377 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.codegen.cs @@ -0,0 +1,34 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = "My value"; + +#line default +#line hidden + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..b39e7880dd --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.ir.txt @@ -0,0 +1,28 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (2:0,2 [10] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [10] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "My value" + HtmlContent - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlElement - (17:2,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..fb7c9fa184 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithCSharpExpression/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (2:0,2 [10] x:\dir\subdir\Test\TestComponent.cshtml) +|"My value"| +Generated Location: (926:25,6 [10] ) +|"My value"| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.codegen.cs new file mode 100644 index 0000000000..37a3009656 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.codegen.cs @@ -0,0 +1,36 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.ir.txt new file mode 100644 index 0000000000..2e241fc492 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.ir.txt @@ -0,0 +1,30 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [7] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n \n + ComponentExtensionNode - (36:2,0 [22] x:\dir\subdir\Test\TestComponent.cshtml) - SomeOtherComponent - Test.SomeOtherComponent + HtmlContent - (58:2,22 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (58:2,22 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlElement - (62:4,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (66:4,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (66:4,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.mappings.txt new file mode 100644 index 0000000000..75b2c90a92 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithComponent/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.codegen.cs new file mode 100644 index 0000000000..aa179a2ea6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.codegen.cs @@ -0,0 +1,33 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +using System; + +#line default +#line hidden + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.ir.txt new file mode 100644 index 0000000000..bd386d9345 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.ir.txt @@ -0,0 +1,26 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (1:0,1 [12] x:\dir\subdir\Test\TestComponent.cshtml) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlElement - (17:2,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.mappings.txt new file mode 100644 index 0000000000..35951811e5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/LeadingWhiteSpace_WithDirective/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (1:0,1 [12] x:\dir\subdir\Test\TestComponent.cshtml) +|using System| +Generated Location: (140:6,0 [12] ) +|using System| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..c1814adecd --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.codegen.cs @@ -0,0 +1,44 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "Header", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + builder.AddAttribute(-1, "Footer", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = "bye!"; + +#line default +#line hidden + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..237f236559 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (31:1,0 [87] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (50:2,4 [20] x:\dir\subdir\Test\TestComponent.cshtml) - Header + HtmlContent - (58:2,12 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (58:2,12 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hi! + ComponentChildContent - (76:3,4 [26] x:\dir\subdir\Test\TestComponent.cshtml) - Footer + CSharpExpression - (86:3,14 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (86:3,14 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "bye!" diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..bc5f908a26 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (86:3,14 [6] x:\dir\subdir\Test\TestComponent.cshtml) +|"bye!"| +Generated Location: (1301:33,14 [6] ) +|"bye!"| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs index 8e50513756..6cf479f40e 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs @@ -31,7 +31,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; #line default #line hidden - (builder2, context) => { + (builder2) => { #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" __o = context.Name; diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt index 4f631de376..9d437ce2d4 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt @@ -10,16 +10,16 @@ Generated Location: (1039:29,2 [35] ) Source Location: (77:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) |context.Name| -Generated Location: (1240:35,44 [12] ) +Generated Location: (1231:35,44 [12] ) |context.Name| Source Location: (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1414:41,62 [2] ) +Generated Location: (1405:41,62 [2] ) |; | Source Location: (130:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) |template| -Generated Location: (1610:47,30 [8] ) +Generated Location: (1601:47,30 [8] ) |template| diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs index d21e72efaf..f07f1324ca 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs @@ -27,24 +27,24 @@ global::System.Object __typeHelper = "*, TestAssembly"; { base.BuildRenderTree(builder); #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - RenderFragment template = + RenderFragment template = (context) => #line default #line hidden - (builder2, context) => { + (builder2) => { #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - __o = context.Index; + __o = context.Index; #line default #line hidden #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - __o = context.Item.ToLower(); + __o = context.Item.ToLower(); #line default #line hidden } #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - ; + ; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt index 3541c5d421..62076ad6d3 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt @@ -22,23 +22,23 @@ Document - IntermediateToken - - CSharp - base.BuildRenderTree(builder); HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpCode - (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = - Template - (77:1,44 [48] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (77:1,44 [50] x:\dir\subdir\Test\TestComponent.cshtml) - li - HtmlContent - (81:1,48 [1] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (81:1,48 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Html - # - CSharpExpression - (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Index - HtmlContent - (96:1,63 [3] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (96:1,63 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \- - CSharpExpression - (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Item.ToLower() - CSharpCode - (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; - ComponentExtensionNode - (132:2,0 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - ComponentAttributeExtensionNode - (155:2,23 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Template - Template - CSharpExpression - (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template - HtmlContent - (167:2,35 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (167:2,35 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (35:1,2 [54] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [54] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = (context) => + Template - (90:1,57 [48] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (90:1,57 [50] x:\dir\subdir\Test\TestComponent.cshtml) - li + HtmlContent - (94:1,61 [1] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (94:1,61 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Html - # + CSharpExpression - (96:1,63 [13] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (96:1,63 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Index + HtmlContent - (109:1,76 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (109:1,76 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \- + CSharpExpression - (113:1,80 [22] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (113:1,80 [22] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Item.ToLower() + CSharpCode - (140:1,107 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (140:1,107 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (145:2,0 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (168:2,23 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Template - Template + CSharpExpression - (169:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (169:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template + HtmlContent - (180:2,35 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (180:2,35 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt index 38cefa4950..09183888bc 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt @@ -3,28 +3,28 @@ Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (558:16,37 [17] ) |"*, TestAssembly"| -Source Location: (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) -| RenderFragment template = | -Generated Location: (1039:29,2 [41] ) -| RenderFragment template = | +Source Location: (35:1,2 [54] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = (context) => | +Generated Location: (1039:29,2 [54] ) +| RenderFragment template = (context) => | -Source Location: (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (96:1,63 [13] x:\dir\subdir\Test\TestComponent.cshtml) |context.Index| -Generated Location: (1252:35,50 [13] ) +Generated Location: (1269:35,63 [13] ) |context.Index| -Source Location: (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (113:1,80 [22] x:\dir\subdir\Test\TestComponent.cshtml) |context.Item.ToLower()| -Generated Location: (1417:40,67 [22] ) +Generated Location: (1447:40,80 [22] ) |context.Item.ToLower()| -Source Location: (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (140:1,107 [2] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1633:46,94 [2] ) +Generated Location: (1676:46,107 [2] ) |; | -Source Location: (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (169:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) |template| -Generated Location: (1824:52,24 [8] ) +Generated Location: (1867:52,24 [8] ) |template| diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs index 4082d38712..b89987f9ad 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs @@ -28,14 +28,14 @@ global::System.Object __typeHelper = "*, TestAssembly"; base.BuildRenderTree(builder); #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - RenderFragment p = + RenderFragment p = (person) => #line default #line hidden - (builder2, context) => { + (builder2) => { __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" - context.Name + person.Name #line default #line hidden @@ -45,7 +45,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; )); } #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" - ; + ; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt index fce1ae8629..5757b61821 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt @@ -22,15 +22,15 @@ Document - IntermediateToken - - CSharp - base.BuildRenderTree(builder); HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpCode - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = - Template - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - div - ComponentExtensionNode - (74:2,37 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - ComponentAttributeExtensionNode - (93:2,56 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name - CSharpExpression - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name - CSharpCode - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n - CSharpCode - (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n + CSharpCode - (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = (person) => + Template - (81:2,44 [45] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (81:2,44 [45] x:\dir\subdir\Test\TestComponent.cshtml) - div + ComponentExtensionNode - (86:2,49 [34] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (105:2,68 [12] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name + CSharpExpression - (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + CSharpCode - (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (144:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (144:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt index 84665112d5..0d3c926dc3 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt @@ -3,33 +3,33 @@ Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (558:16,37 [17] ) |"*, TestAssembly"| -Source Location: (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) | - RenderFragment p = | -Generated Location: (1039:29,2 [33] ) + RenderFragment p = (person) => | +Generated Location: (1039:29,2 [45] ) | - RenderFragment p = | + RenderFragment p = (person) => | -Source Location: (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) -|context.Name| -Generated Location: (1354:37,57 [12] ) -|context.Name| +Source Location: (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) +|person.Name| +Generated Location: (1369:37,69 [11] ) +|person.Name| -Source Location: (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1723:47,78 [3] ) +Generated Location: (1748:47,89 [3] ) |; | -Source Location: (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (144:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) | class Person { public string Name { get; set; } } | -Generated Location: (1869:54,12 [76] ) +Generated Location: (1894:54,12 [76] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs index 30475cf8a9..47d4f7a8c4 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs @@ -28,14 +28,14 @@ global::System.Object __typeHelper = "*, TestAssembly"; base.BuildRenderTree(builder); #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - RenderFragment p = + RenderFragment p = (person) => #line default #line hidden - (builder2, context) => { + (builder2) => { __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" - context.Name + person.Name #line default #line hidden @@ -45,7 +45,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; )); } #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" - ; + ; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt index 7d07d0fb6c..a8f64cd644 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt @@ -22,24 +22,25 @@ Document - IntermediateToken - - CSharp - base.BuildRenderTree(builder); HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpCode - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = - Template - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - div - ComponentExtensionNode - (74:2,37 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - ComponentAttributeExtensionNode - (93:2,56 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name - CSharpExpression - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name - CSharpCode - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n - ComponentExtensionNode - (121:4,0 [49] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - HtmlContent - (134:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (134:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpExpression - (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hello, world!" - HtmlContent - (154:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (154:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - HtmlContent - (170:6,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (170:6,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n - CSharpCode - (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n + CSharpCode - (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = (person) => + Template - (81:2,44 [45] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (81:2,44 [45] x:\dir\subdir\Test\TestComponent.cshtml) - div + ComponentExtensionNode - (86:2,49 [34] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (105:2,68 [12] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name + CSharpExpression - (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + CSharpCode - (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + ComponentExtensionNode - (132:4,0 [49] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (145:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (145:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpExpression - (149:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (149:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hello, world!" + HtmlContent - (165:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (165:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + HtmlContent - (181:6,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (181:6,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + CSharpCode - (197:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (197:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt index a185a62885..d053ab758b 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt @@ -3,38 +3,38 @@ Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (558:16,37 [17] ) |"*, TestAssembly"| -Source Location: (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) | - RenderFragment p = | -Generated Location: (1039:29,2 [33] ) + RenderFragment p = (person) => | +Generated Location: (1039:29,2 [45] ) | - RenderFragment p = | + RenderFragment p = (person) => | -Source Location: (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) -|context.Name| -Generated Location: (1354:37,57 [12] ) -|context.Name| +Source Location: (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) +|person.Name| +Generated Location: (1369:37,69 [11] ) +|person.Name| -Source Location: (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1723:47,78 [3] ) +Generated Location: (1748:47,89 [3] ) |; | -Source Location: (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (149:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) |"hello, world!"| -Generated Location: (1929:53,6 [15] ) +Generated Location: (1954:53,6 [15] ) |"hello, world!"| -Source Location: (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (197:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) | class Person { public string Name { get; set; } } | -Generated Location: (2122:62,12 [76] ) +Generated Location: (2147:62,12 [76] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.codegen.cs new file mode 100644 index 0000000000..d0607a92b3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.codegen.cs @@ -0,0 +1,60 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment template = (person) => + +#line default +#line hidden + (builder2) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = person.Name; + +#line default +#line hidden + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + __o = new Microsoft.AspNetCore.Blazor.RenderFragment( +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + template + +#line default +#line hidden + ); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.ir.txt new file mode 100644 index 0000000000..78cc76ac69 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.ir.txt @@ -0,0 +1,38 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) - "*, TestAssembly" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (35:1,2 [47] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [47] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = (person) => + Template - (83:1,50 [22] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (83:1,50 [23] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (89:1,56 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (89:1,56 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + CSharpCode - (106:1,73 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (106:1,73 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (111:2,0 [41] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (140:2,29 [9] x:\dir\subdir\Test\TestComponent.cshtml) - PersonTemplate - PersonTemplate + CSharpExpression - (141:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (141:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template + HtmlContent - (152:2,41 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (152:2,41 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.mappings.txt new file mode 100644 index 0000000000..44cfddf80b --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.mappings.txt @@ -0,0 +1,25 @@ +Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|"*, TestAssembly"| +Generated Location: (558:16,37 [17] ) +|"*, TestAssembly"| + +Source Location: (35:1,2 [47] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = (person) => | +Generated Location: (1039:29,2 [47] ) +| RenderFragment template = (person) => | + +Source Location: (89:1,56 [11] x:\dir\subdir\Test\TestComponent.cshtml) +|person.Name| +Generated Location: (1255:35,56 [11] ) +|person.Name| + +Source Location: (106:1,73 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1439:41,73 [2] ) +|; | + +Source Location: (141:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|template| +Generated Location: (1635:47,30 [8] ) +|template| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..a590086a8b --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.codegen.cs @@ -0,0 +1,52 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = RenderPerson((person) => (builder2) => { +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = person.Name; + +#line default +#line hidden +} +); + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..c8db0f08eb --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.ir.txt @@ -0,0 +1,32 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (1:0,1 [48] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (1:0,1 [25] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson((person) => + Template - (27:0,27 [22] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (27:0,27 [23] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (33:0,33 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (33:0,33 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + IntermediateToken - (50:0,50 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + HtmlContent - (51:0,51 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (51:0,51 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (65:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (65:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..dd80c12c60 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.mappings.txt @@ -0,0 +1,34 @@ +Source Location: (1:0,1 [25] x:\dir\subdir\Test\TestComponent.cshtml) +|RenderPerson((person) => | +Generated Location: (926:25,6 [25] ) +|RenderPerson((person) => | + +Source Location: (33:0,33 [11] x:\dir\subdir\Test\TestComponent.cshtml) +|person.Name| +Generated Location: (1052:27,33 [11] ) +|person.Name| + +Source Location: (50:0,50 [1] x:\dir\subdir\Test\TestComponent.cshtml) +|)| +Generated Location: (1100:32,0 [1] ) +|)| + +Source Location: (65:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| +Generated Location: (1247:39,12 [138] ) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs index 968f7ca5b8..08f3ab4473 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs @@ -24,19 +24,19 @@ namespace Test base.BuildRenderTree(builder); #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" - RenderFragment p = + RenderFragment p = (person) => #line default #line hidden - (builder2, context) => { + (builder2) => { #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - __o = context.Name; + __o = person.Name; #line default #line hidden } #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - ; + ; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt index 28e58777c7..0daa3f2173 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt @@ -19,13 +19,13 @@ Document - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - CSharpCode - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = - Template - (36:1,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (36:1,32 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div - CSharpExpression - (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name - CSharpCode - (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n - CSharpCode - (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n + CSharpCode - (2:0,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = (person) => + Template - (48:1,44 [22] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (48:1,44 [23] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (54:1,50 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (54:1,50 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + CSharpCode - (71:1,67 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (71:1,67 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (89:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (89:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt index 54db326ba9..ad61715d04 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt @@ -1,30 +1,30 @@ -Source Location: (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (2:0,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) | - RenderFragment p = | -Generated Location: (922:25,2 [33] ) + RenderFragment p = (person) => | +Generated Location: (922:25,2 [45] ) | - RenderFragment p = | + RenderFragment p = (person) => | -Source Location: (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) -|context.Name| -Generated Location: (1115:32,38 [12] ) -|context.Name| +Source Location: (54:1,50 [11] x:\dir\subdir\Test\TestComponent.cshtml) +|person.Name| +Generated Location: (1130:32,50 [11] ) +|person.Name| -Source Location: (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (71:1,67 [3] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1283:38,56 [3] ) +Generated Location: (1308:38,67 [3] ) |; | -Source Location: (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (89:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) | class Person { public string Name { get; set; } } | -Generated Location: (1429:45,12 [76] ) +Generated Location: (1454:45,12 [76] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs index 7de4a55463..ccf68e72b2 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs @@ -23,9 +23,9 @@ namespace Test { base.BuildRenderTree(builder); #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" -__o = RenderPerson((builder2, context) => { +__o = RenderPerson((person) => (builder2) => { #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" - __o = context.Name; + __o = person.Name; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt index 6f2bc6c9ad..bda53687d1 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt @@ -19,14 +19,14 @@ Document - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - CSharpExpression - (2:0,2 [37] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson( - Template - (16:0,16 [23] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (16:0,16 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div - CSharpExpression - (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name - IntermediateToken - (40:0,40 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) - HtmlContent - (42:0,42 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (42:0,42 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpCode - (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n + CSharpExpression - (2:0,2 [48] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [25] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson((person) => + Template - (28:0,28 [22] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (28:0,28 [23] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (34:0,34 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (34:0,34 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + IntermediateToken - (51:0,51 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + HtmlContent - (53:0,53 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (53:0,53 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (67:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (67:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt index 31784c6e77..fd279ffbcb 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt @@ -1,19 +1,19 @@ -Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.cshtml) -|RenderPerson(| -Generated Location: (926:25,6 [13] ) -|RenderPerson(| +Source Location: (2:0,2 [25] x:\dir\subdir\Test\TestComponent.cshtml) +|RenderPerson((person) => | +Generated Location: (926:25,6 [25] ) +|RenderPerson((person) => | -Source Location: (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) -|context.Name| -Generated Location: (1038:27,22 [12] ) -|context.Name| +Source Location: (34:0,34 [11] x:\dir\subdir\Test\TestComponent.cshtml) +|person.Name| +Generated Location: (1053:27,34 [11] ) +|person.Name| -Source Location: (40:0,40 [1] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (51:0,51 [1] x:\dir\subdir\Test\TestComponent.cshtml) |)| -Generated Location: (1087:32,0 [1] ) +Generated Location: (1101:32,0 [1] ) |)| -Source Location: (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (67:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) | class Person { @@ -22,7 +22,7 @@ Source Location: (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) object RenderPerson(RenderFragment p) => null; | -Generated Location: (1234:39,12 [138] ) +Generated Location: (1248:39,12 [138] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs index b58d53d9d5..db863eb6bb 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs @@ -23,7 +23,7 @@ namespace Test { base.BuildRenderTree(builder); #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" -__o = RenderPerson((builder2, context) => { +__o = RenderPerson((builder2) => { #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" __o = context.Name; diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt index 02adc91104..99bbf63272 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt @@ -5,12 +5,12 @@ Generated Location: (926:25,6 [13] ) Source Location: (21:0,21 [12] x:\dir\subdir\Test\TestComponent.cshtml) |context.Name| -Generated Location: (1037:27,21 [12] ) +Generated Location: (1028:27,21 [12] ) |context.Name| Source Location: (39:0,39 [1] x:\dir\subdir\Test\TestComponent.cshtml) |)| -Generated Location: (1086:32,0 [1] ) +Generated Location: (1077:32,0 [1] ) |)| Source Location: (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) @@ -22,7 +22,7 @@ Source Location: (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) object RenderPerson(RenderFragment p) => null; | -Generated Location: (1233:39,12 [138] ) +Generated Location: (1224:39,12 [138] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.codegen.cs new file mode 100644 index 0000000000..7a58682253 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.codegen.cs @@ -0,0 +1,55 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment template = + +#line default +#line hidden + (builder2) => { + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + __o = +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + template + +#line default +#line hidden + ; + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.ir.txt new file mode 100644 index 0000000000..e84c84fa27 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.ir.txt @@ -0,0 +1,38 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) - "*, TestAssembly" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (35:1,2 [27] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [27] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = + Template - (63:1,30 [15] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (63:1,30 [15] x:\dir\subdir\Test\TestComponent.cshtml) - div + HtmlContent - (68:1,35 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (68:1,35 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Joey + CSharpCode - (78:1,45 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (78:1,45 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (83:2,0 [33] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - - Person - + CSharpExpression - (104:2,21 [9] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (105:2,22 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template + HtmlContent - (116:2,33 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (116:2,33 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.mappings.txt new file mode 100644 index 0000000000..659c7d4ab7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|"*, TestAssembly"| +Generated Location: (558:16,37 [17] ) +|"*, TestAssembly"| + +Source Location: (35:1,2 [27] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = | +Generated Location: (1039:29,2 [27] ) +| RenderFragment template = | + +Source Location: (78:1,45 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1239:36,45 [2] ) +|; | + +Source Location: (105:2,22 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|template| +Generated Location: (1367:42,22 [8] ) +|template| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..d6048816b1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.codegen.cs @@ -0,0 +1,42 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = RenderPerson((builder2) => { +} +); + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + object RenderPerson(RenderFragment p) => null; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..d9beb963b4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.ir.txt @@ -0,0 +1,32 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (1:0,1 [27] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (1:0,1 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson( + Template - (15:0,15 [13] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (15:0,15 [13] x:\dir\subdir\Test\TestComponent.cshtml) - div + HtmlContent - (20:0,20 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (20:0,20 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - HI + IntermediateToken - (28:0,28 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (43:1,12 [54] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (43:1,12 [54] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..64452dbc9c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.mappings.txt @@ -0,0 +1,19 @@ +Source Location: (1:0,1 [13] x:\dir\subdir\Test\TestComponent.cshtml) +|RenderPerson(| +Generated Location: (926:25,6 [13] ) +|RenderPerson(| + +Source Location: (28:0,28 [1] x:\dir\subdir\Test\TestComponent.cshtml) +|)| +Generated Location: (959:27,0 [1] ) +|)| + +Source Location: (43:1,12 [54] x:\dir\subdir\Test\TestComponent.cshtml) +| + object RenderPerson(RenderFragment p) => null; +| +Generated Location: (1106:34,12 [54] ) +| + object RenderPerson(RenderFragment p) => null; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ScriptTag_WithErrorSuppressed/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ScriptTag_WithErrorSuppressed/TestComponent.codegen.cs new file mode 100644 index 0000000000..6119cd65df --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ScriptTag_WithErrorSuppressed/TestComponent.codegen.cs @@ -0,0 +1,29 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ScriptTag_WithErrorSuppressed/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ScriptTag_WithErrorSuppressed/TestComponent.ir.txt new file mode 100644 index 0000000000..6305970ba5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ScriptTag_WithErrorSuppressed/TestComponent.ir.txt @@ -0,0 +1,37 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [144] x:\dir\subdir\Test\TestComponent.cshtml) - div + HtmlContent - (5:0,5 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (5:0,5 [6] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + HtmlElement - (11:1,4 [125] x:\dir\subdir\Test\TestComponent.cshtml) - script + HtmlAttribute - - - + HtmlAttributeValue - - + IntermediateToken - - Html - some/url.js + HtmlAttribute - - - + HtmlAttributeValue - - + IntermediateToken - - Html - + HtmlContent - (78:1,71 [49] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (78:1,71 [49] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n some text\n some more text\n + HtmlContent - (136:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (136:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + HtmlContent - (144:5,6 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (144:5,6 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..4885f2d2c4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.codegen.cs @@ -0,0 +1,34 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = "My value"; + +#line default +#line hidden + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..69d6d4daa9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.ir.txt @@ -0,0 +1,30 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (4:0,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (4:0,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello + HtmlContent - (14:0,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (14:0,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + CSharpExpression - (20:2,2 [10] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (20:2,2 [10] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "My value" + HtmlContent - (31:2,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (31:2,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..c0996e985f --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithCSharpExpression/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (20:2,2 [10] x:\dir\subdir\Test\TestComponent.cshtml) +|"My value"| +Generated Location: (926:25,6 [10] ) +|"My value"| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.codegen.cs new file mode 100644 index 0000000000..37a3009656 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.codegen.cs @@ -0,0 +1,36 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.ir.txt new file mode 100644 index 0000000000..9a88c5efea --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.ir.txt @@ -0,0 +1,32 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) - *, TestAssembly + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (29:0,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + HtmlElement - (31:1,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (35:1,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello + HtmlContent - (45:1,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (45:1,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + ComponentExtensionNode - (49:3,0 [22] x:\dir\subdir\Test\TestComponent.cshtml) - SomeOtherComponent - Test.SomeOtherComponent + HtmlContent - (71:3,22 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (71:3,22 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.mappings.txt new file mode 100644 index 0000000000..75b2c90a92 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithComponent/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.codegen.cs new file mode 100644 index 0000000000..44ab249f7e --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.codegen.cs @@ -0,0 +1,34 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + [Microsoft.AspNetCore.Blazor.Components.RouteAttribute("/my/url")] + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "/my/url"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.ir.txt new file mode 100644 index 0000000000..928f611cd5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.ir.txt @@ -0,0 +1,30 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + RouteAttributeExtensionNode - - /my/url + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (24:2,6 [9] x:\dir\subdir\Test\TestComponent.cshtml) - "/my/url" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (4:0,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (4:0,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello + HtmlContent - (14:0,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (14:0,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlContent - (35:3,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:3,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.mappings.txt new file mode 100644 index 0000000000..cba8722d11 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/TrailingWhiteSpace_WithDirective/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (24:2,6 [9] x:\dir\subdir\Test\TestComponent.cshtml) +|"/my/url"| +Generated Location: (630:17,37 [9] ) +|"/my/url"| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..3472503d55 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.codegen.cs @@ -0,0 +1,44 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment header = (context) => + +#line default +#line hidden + (builder2) => { + builder2.OpenElement(0, "div"); + builder2.AddContent(1, context.ToLowerInvariant()); + builder2.CloseElement(); + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + builder.OpenComponent(2); + builder.AddAttribute(3, "Header", new Microsoft.AspNetCore.Blazor.RenderFragment(header)); + builder.AddAttribute(4, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + builder2.AddContent(5, "\n Some Content\n"); + } + )); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..7a970ce612 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.ir.txt @@ -0,0 +1,27 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment header = (context) => + Template - (80:1,49 [37] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (80:1,49 [38] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant() + CSharpCode - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (123:2,0 [62] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (151:2,28 [20] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (151:2,28 [20] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some Content\n + ComponentAttributeExtensionNode - (143:2,20 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Header - Header + CSharpExpression - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - header diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..cbaabc54dc --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndAttributeChildContent/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment header = (context) => | +Generated Location: (654:18,2 [46] ) +| RenderFragment header = (context) => | + +Source Location: (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1075:28,87 [2] ) +|; | + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..180d2f0cf5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.codegen.cs @@ -0,0 +1,48 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment header = (context) => + +#line default +#line hidden + (builder2) => { + builder2.OpenElement(0, "div"); + builder2.AddContent(1, context.ToLowerInvariant()); + builder2.CloseElement(); + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + builder.OpenComponent(2); + builder.AddAttribute(3, "Header", new Microsoft.AspNetCore.Blazor.RenderFragment(header)); + builder.AddAttribute(4, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + builder2.AddContent(5, "Some Content"); + } + )); + builder.AddAttribute(6, "Footer", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + builder2.AddContent(7, "Bye!"); + } + )); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..91d66478eb --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.ir.txt @@ -0,0 +1,30 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment header = (context) => + Template - (80:1,49 [37] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (80:1,49 [38] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (86:1,55 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant() + CSharpCode - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (123:2,0 [114] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (155:3,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + HtmlContent - (169:3,16 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (169:3,16 [12] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some Content + ComponentChildContent - (200:4,2 [21] x:\dir\subdir\Test\TestComponent.cshtml) - Footer + HtmlContent - (208:4,10 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (208:4,10 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Bye! + ComponentAttributeExtensionNode - (143:2,20 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Header - Header + CSharpExpression - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (144:2,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - header diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..cbaabc54dc --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/BodyAndExplicitChildContent/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (33:1,2 [46] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment header = (context) => | +Generated Location: (654:18,2 [46] ) +| RenderFragment header = (context) => | + +Source Location: (118:1,87 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1075:28,87 [2] ) +|; | + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.ir.txt index ef778dd366..53b69a78d0 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.ir.txt @@ -11,9 +11,10 @@ Document - CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); ComponentExtensionNode - (31:1,0 [91] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text - HtmlBlock - - Nested text + ComponentChildContent - - ChildContent + HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text + HtmlBlock - - Nested text ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithElementOnlyChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithElementOnlyChildContent/TestComponent.ir.txt index a232d19fb4..52c0670d90 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithElementOnlyChildContent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithElementOnlyChildContent/TestComponent.ir.txt @@ -11,4 +11,5 @@ Document - CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); ComponentExtensionNode - (31:1,0 [47] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - HtmlBlock - - hello + ComponentChildContent - - ChildContent + HtmlBlock - - hello diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..1f212fdd04 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.codegen.cs @@ -0,0 +1,28 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.OpenComponent(0); + builder.AddAttribute(1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + builder2.AddContent(2, "hello"); + } + )); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..eb26477cfa --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitChildContent/TestComponent.ir.txt @@ -0,0 +1,16 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + ComponentExtensionNode - (31:1,0 [61] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (44:1,13 [34] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + HtmlContent - (58:1,27 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (58:1,27 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - hello diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..d14c503d76 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.codegen.cs @@ -0,0 +1,28 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.OpenComponent(0); + builder.AddAttribute(1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((context) => (builder2) => { + builder2.AddContent(2, context); + } + )); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..eb9f83e603 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithExplicitGenericChildContent/TestComponent.ir.txt @@ -0,0 +1,16 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + ComponentExtensionNode - (31:1,0 [64] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (44:1,13 [37] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + CSharpExpression - (59:1,28 [7] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (59:1,28 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..5bbf681fec --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.codegen.cs @@ -0,0 +1,33 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.OpenComponent(0); + builder.AddAttribute(1, "MyAttr", "abc"); + builder.AddAttribute(2, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((context) => (builder2) => { + builder2.AddContent(3, "Some text"); + builder2.OpenElement(4, "some-child"); + builder2.AddAttribute(5, "a", "1"); + builder2.AddContent(6, context.ToLowerInvariant()); + builder2.CloseElement(); + } + )); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..d5911f9d84 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent/TestComponent.ir.txt @@ -0,0 +1,25 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + ComponentExtensionNode - (31:1,0 [107] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text + HtmlElement - (66:1,35 [58] x:\dir\subdir\Test\TestComponent.cshtml) - some-child + HtmlAttribute - - - + HtmlAttributeValue - - + IntermediateToken - - Html - 1 + CSharpExpression - (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLowerInvariant() + ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr + HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.codegen.cs new file mode 100644 index 0000000000..476e4d4103 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.codegen.cs @@ -0,0 +1,34 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.OpenComponent(0); + builder.AddAttribute(1, "MyAttr", "abc"); + builder.AddAttribute(2, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((item) => (builder2) => { + builder2.AddContent(3, "\n Some text"); + builder2.OpenElement(4, "some-child"); + builder2.AddAttribute(5, "a", "1"); + builder2.AddContent(6, item.ToLowerInvariant()); + builder2.CloseElement(); + builder2.AddContent(7, "\n "); + } + )); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.ir.txt new file mode 100644 index 0000000000..611158ed29 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_WithGenericChildContent_SetsParameterName/TestComponent.ir.txt @@ -0,0 +1,27 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + ComponentExtensionNode - (31:1,0 [164] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (61:2,2 [118] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + HtmlContent - (90:2,31 [15] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (90:2,31 [15] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some text + HtmlElement - (105:3,13 [55] x:\dir\subdir\Test\TestComponent.cshtml) - some-child + HtmlAttribute - - - + HtmlAttributeValue - - + IntermediateToken - - Html - 1 + CSharpExpression - (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - item.ToLowerInvariant() + HtmlContent - (160:3,68 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (160:3,68 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr + HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.codegen.cs index ff75de6c6a..e480e46328 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.codegen.cs @@ -32,6 +32,7 @@ namespace Test #line 4 "x:\dir\subdir\Test\TestComponent.cshtml" private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.ir.txt index 7c5be1da8c..985d13d3be 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.ir.txt @@ -18,5 +18,5 @@ Document - ComponentAttributeExtensionNode - - ParamAfter - HtmlContent - (94:1,63 [5] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (94:1,63 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - after - CSharpCode - (119:3,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (119:3,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Test.MyComponent myInstance;\n + CSharpCode - (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Test.MyComponent myInstance;\n public void Foo() { System.GC.KeepAlive(myInstance); }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.mappings.txt index c57c9d55d1..fad95126c6 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef/TestComponent.mappings.txt @@ -3,12 +3,14 @@ Source Location: (70:1,39 [10] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (940:22,39 [10] ) |myInstance| -Source Location: (119:3,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) | private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } | -Generated Location: (1194:32,12 [44] ) +Generated Location: (1194:32,12 [104] ) | private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.codegen.cs index 3b9e68efaa..644cfa4c4d 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.codegen.cs @@ -36,6 +36,7 @@ namespace Test #line 6 "x:\dir\subdir\Test\TestComponent.cshtml" private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.ir.txt index a24b6860a7..b3af27df44 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.ir.txt @@ -11,12 +11,13 @@ Document - CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); ComponentExtensionNode - (31:1,0 [96] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - HtmlContent - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some - HtmlBlock - - further content\n + ComponentChildContent - - ChildContent + HtmlContent - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some + HtmlBlock - - further content\n RefExtensionNode - (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml) - myInstance - Test.MyComponent ComponentAttributeExtensionNode - - SomeProp - HtmlContent - (71:1,40 [3] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (71:1,40 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - val - CSharpCode - (143:5,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (143:5,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Test.MyComponent myInstance;\n + CSharpCode - (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Test.MyComponent myInstance;\n public void Foo() { System.GC.KeepAlive(myInstance); }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.mappings.txt index 0c8c2b2eb6..b7b4f8d3cd 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Component_WithRef_WithChildContent/TestComponent.mappings.txt @@ -3,12 +3,14 @@ Source Location: (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (1131:27,18 [10] ) |myInstance| -Source Location: (143:5,12 [44] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) | private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } | -Generated Location: (1385:37,12 [44] ) +Generated Location: (1385:37,12 [104] ) | private Test.MyComponent myInstance; + public void Foo() { System.GC.KeepAlive(myInstance); } | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.codegen.cs index d1b4f6ea12..a1da1779c2 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.codegen.cs @@ -33,6 +33,7 @@ namespace Test #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" private Microsoft.AspNetCore.Blazor.ElementRef myElem; + public void Foo() { System.GC.KeepAlive(myElem); } #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.ir.txt index 0a10abd84a..7519b928d4 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.ir.txt @@ -20,5 +20,5 @@ Document - HtmlAttribute - - attributeafter=" - " HtmlAttributeValue - (60:0,60 [5] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (60:0,60 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - after - CSharpCode - (95:2,12 [62] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (95:2,12 [62] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Microsoft.AspNetCore.Blazor.ElementRef myElem;\n + CSharpCode - (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private Microsoft.AspNetCore.Blazor.ElementRef myElem;\n public void Foo() { System.GC.KeepAlive(myElem); }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.mappings.txt index 3b8dc820bf..70f8152136 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/Element_WithRef/TestComponent.mappings.txt @@ -3,12 +3,14 @@ Source Location: (36:0,36 [6] x:\dir\subdir\Test\TestComponent.cshtml) Generated Location: (931:22,36 [6] ) |myElem| -Source Location: (95:2,12 [62] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (95:2,12 [118] x:\dir\subdir\Test\TestComponent.cshtml) | private Microsoft.AspNetCore.Blazor.ElementRef myElem; + public void Foo() { System.GC.KeepAlive(myElem); } | -Generated Location: (1206:33,12 [62] ) +Generated Location: (1206:33,12 [118] ) | private Microsoft.AspNetCore.Blazor.ElementRef myElem; + public void Foo() { System.GC.KeepAlive(myElem); } | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.codegen.cs index b3f3686b47..61f2ee883d 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.codegen.cs @@ -8,6 +8,7 @@ namespace Test using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent { #pragma warning disable 1998 @@ -17,10 +18,9 @@ namespace Test builder.OpenElement(0, "input"); builder.AddAttribute(1, "onclick", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue(OnClick)); builder.CloseElement(); - builder.AddContent(2, "\n"); } #pragma warning restore 1998 -#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" void OnClick(UIMouseEventArgs e) { } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.ir.txt index ecf6331fca..2e944a3486 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.ir.txt @@ -4,21 +4,17 @@ Document - UsingDirective - (18:2,1 [34] ) - System.Collections.Generic UsingDirective - (53:3,1 [19] ) - System.Linq UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks - UsingDirective - (1:0,1 [35] x:\dir\subdir\Test\TestComponent.cshtml) - Microsoft.AspNetCore.Blazor + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - HtmlContent - - IntermediateToken - - Html - ( - IntermediateToken - (53:1,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - OnClick - IntermediateToken - - CSharp - ) - HtmlContent - - IntermediateToken - - Html - /> - HtmlContent - (64:1,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (64:1,28 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpCode - (78:2,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (78:2,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void OnClick(UIMouseEventArgs e) {\n }\n + HtmlElement - (0:0,0 [28] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - (16:0,16 [8] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - " + CSharpExpressionAttributeValue - - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue( + IntermediateToken - (17:0,17 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - OnClick + IntermediateToken - - CSharp - ) + CSharpCode - (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n void OnClick(UIMouseEventArgs e) {\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.mappings.txt index 2b525eee21..db716b1e55 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithDelegate/TestComponent.mappings.txt @@ -1,9 +1,9 @@ -Source Location: (78:2,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (42:1,12 [49] x:\dir\subdir\Test\TestComponent.cshtml) | void OnClick(UIMouseEventArgs e) { } | -Generated Location: (964:23,12 [49] ) +Generated Location: (973:23,12 [49] ) | void OnClick(UIMouseEventArgs e) { } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithLambdaDelegate/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithLambdaDelegate/TestComponent.codegen.cs index 7e58c05413..633aa0fc97 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithLambdaDelegate/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithLambdaDelegate/TestComponent.codegen.cs @@ -8,6 +8,7 @@ namespace Test using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent { #pragma warning disable 1998 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithLambdaDelegate/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithLambdaDelegate/TestComponent.ir.txt index 58a90a079b..ffdd649aec 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithLambdaDelegate/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/EventHandler_OnElement_WithLambdaDelegate/TestComponent.ir.txt @@ -4,17 +4,15 @@ Document - UsingDirective - (18:2,1 [34] ) - System.Collections.Generic UsingDirective - (53:3,1 [19] ) - System.Linq UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks - UsingDirective - (1:0,1 [35] x:\dir\subdir\Test\TestComponent.cshtml) - Microsoft.AspNetCore.Blazor + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - HtmlContent - - IntermediateToken - - Html - ( - IntermediateToken - (54:1,18 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - x => { } - IntermediateToken - - CSharp - ) - HtmlContent - - IntermediateToken - - Html - /> + HtmlElement - (0:0,0 [31] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - (16:0,16 [11] x:\dir\subdir\Test\TestComponent.cshtml) - onclick=" - " + CSharpExpressionAttributeValue - - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetEventHandlerValue( + IntermediateToken - (18:0,18 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - x => { } + IntermediateToken - - CSharp - ) diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..84e1c9c51f --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.codegen.cs @@ -0,0 +1,32 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.OpenComponent(0); + builder.AddAttribute(1, "Header", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + builder2.AddContent(2, "Hi!"); + } + )); + builder.AddAttribute(3, "Footer", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + builder2.AddContent(4, "bye!"); + } + )); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.ir.txt new file mode 100644 index 0000000000..d7e62756e6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/MultipleExplictChildContent/TestComponent.ir.txt @@ -0,0 +1,19 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + ComponentExtensionNode - (31:1,0 [87] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - (50:2,4 [20] x:\dir\subdir\Test\TestComponent.cshtml) - Header + HtmlContent - (58:2,12 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (58:2,12 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hi! + ComponentChildContent - (76:3,4 [26] x:\dir\subdir\Test\TestComponent.cshtml) - Footer + CSharpExpression - (86:3,14 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (86:3,14 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "bye!" diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs index bc44e0278f..918cb0bebb 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs @@ -20,7 +20,7 @@ namespace Test #line default #line hidden - (builder2, context) => { + (builder2) => { builder2.OpenElement(0, "div"); builder2.AddContent(1, context.Name); builder2.CloseElement(); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt index 38cba423b0..fe05054ad1 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt @@ -5,6 +5,6 @@ Generated Location: (654:18,2 [35] ) Source Location: (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1034:28,62 [2] ) +Generated Location: (1025:28,62 [2] ) |; | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs index 48625f2519..f805d53281 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs @@ -16,11 +16,11 @@ namespace Test { base.BuildRenderTree(builder); #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - RenderFragment template = + RenderFragment template = (context) => #line default #line hidden - (builder2, context) => { + (builder2) => { builder2.OpenElement(0, "li"); builder2.AddContent(1, "#"); builder2.AddContent(2, context.Index); @@ -29,7 +29,7 @@ namespace Test builder2.CloseElement(); } #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - ; + ; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt index 67d104b4c4..9fa7ec52e1 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt @@ -10,21 +10,21 @@ Document - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - CSharpCode - (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = - Template - (77:1,44 [48] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (77:1,44 [50] x:\dir\subdir\Test\TestComponent.cshtml) - li - HtmlContent - (81:1,48 [1] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (81:1,48 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Html - # - CSharpExpression - (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Index - HtmlContent - (96:1,63 [3] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (96:1,63 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \- - CSharpExpression - (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Item.ToLower() - CSharpCode - (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; - ComponentExtensionNode - (132:2,0 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - ComponentAttributeExtensionNode - (155:2,23 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Template - Template - CSharpExpression - (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template + CSharpCode - (35:1,2 [54] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [54] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = (context) => + Template - (90:1,57 [48] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (90:1,57 [50] x:\dir\subdir\Test\TestComponent.cshtml) - li + HtmlContent - (94:1,61 [1] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (94:1,61 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Html - # + CSharpExpression - (96:1,63 [13] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (96:1,63 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Index + HtmlContent - (109:1,76 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (109:1,76 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \- + CSharpExpression - (113:1,80 [22] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (113:1,80 [22] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Item.ToLower() + CSharpCode - (140:1,107 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (140:1,107 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (145:2,0 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (168:2,23 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Template - Template + CSharpExpression - (169:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (169:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt index 957f6b1cfc..23134836c8 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt @@ -1,10 +1,10 @@ -Source Location: (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) -| RenderFragment template = | -Generated Location: (654:18,2 [41] ) -| RenderFragment template = | +Source Location: (35:1,2 [54] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = (context) => | +Generated Location: (654:18,2 [54] ) +| RenderFragment template = (context) => | -Source Location: (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (140:1,107 [2] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1231:31,94 [2] ) +Generated Location: (1248:31,107 [2] ) |; | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs index 6048c7ea24..e5002b7870 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs @@ -17,19 +17,19 @@ namespace Test base.BuildRenderTree(builder); #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - RenderFragment p = + RenderFragment p = (person) => #line default #line hidden - (builder2, context) => { + (builder2) => { builder2.OpenElement(0, "div"); builder2.OpenComponent(1); - builder2.AddAttribute(2, "Name", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(context.Name)); + builder2.AddAttribute(2, "Name", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(person.Name)); builder2.CloseComponent(); builder2.CloseElement(); } #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" - ; + ; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt index e4f216fe5b..a69b6bbfab 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt @@ -10,15 +10,15 @@ Document - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - CSharpCode - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = - Template - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - div - ComponentExtensionNode - (74:2,37 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - ComponentAttributeExtensionNode - (93:2,56 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name - CSharpExpression - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name - CSharpCode - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n - CSharpCode - (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n + CSharpCode - (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = (person) => + Template - (81:2,44 [45] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (81:2,44 [45] x:\dir\subdir\Test\TestComponent.cshtml) - div + ComponentExtensionNode - (86:2,49 [34] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (105:2,68 [12] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name + CSharpExpression - (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + CSharpCode - (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (144:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (144:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt index 58511127b8..d25e4e29d7 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt @@ -1,25 +1,25 @@ -Source Location: (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) | - RenderFragment p = | -Generated Location: (654:18,2 [33] ) + RenderFragment p = (person) => | +Generated Location: (654:18,2 [45] ) | - RenderFragment p = | + RenderFragment p = (person) => | -Source Location: (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1244:31,78 [3] ) +Generated Location: (1257:31,89 [3] ) |; | -Source Location: (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (144:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) | class Person { public string Name { get; set; } } | -Generated Location: (1390:38,12 [76] ) +Generated Location: (1403:38,12 [76] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs index 674bd7003d..0775f60712 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs @@ -17,19 +17,19 @@ namespace Test base.BuildRenderTree(builder); #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - RenderFragment p = + RenderFragment p = (person) => #line default #line hidden - (builder2, context) => { + (builder2) => { builder2.OpenElement(0, "div"); builder2.OpenComponent(1); - builder2.AddAttribute(2, "Name", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(context.Name)); + builder2.AddAttribute(2, "Name", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(person.Name)); builder2.CloseComponent(); builder2.CloseElement(); } #line 3 "x:\dir\subdir\Test\TestComponent.cshtml" - ; + ; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt index a5a184e80e..359c73d681 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt @@ -10,22 +10,23 @@ Document - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - CSharpCode - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = - Template - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - div - ComponentExtensionNode - (74:2,37 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - ComponentAttributeExtensionNode - (93:2,56 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name - CSharpExpression - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name - CSharpCode - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n - ComponentExtensionNode - (121:4,0 [49] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent - HtmlContent - (134:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (134:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpExpression - (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hello, world!" - HtmlContent - (154:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (154:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n - CSharpCode - (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n + CSharpCode - (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = (person) => + Template - (81:2,44 [45] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (81:2,44 [45] x:\dir\subdir\Test\TestComponent.cshtml) - div + ComponentExtensionNode - (86:2,49 [34] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (105:2,68 [12] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name + CSharpExpression - (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (106:2,69 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + CSharpCode - (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + ComponentExtensionNode - (132:4,0 [49] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (145:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (145:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpExpression - (149:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (149:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hello, world!" + HtmlContent - (165:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (165:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (197:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (197:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt index a70f88f50a..d9fd813328 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt @@ -1,25 +1,25 @@ -Source Location: (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (35:1,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) | - RenderFragment p = | -Generated Location: (654:18,2 [33] ) + RenderFragment p = (person) => | +Generated Location: (654:18,2 [45] ) | - RenderFragment p = | + RenderFragment p = (person) => | -Source Location: (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (126:2,89 [3] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1244:31,78 [3] ) +Generated Location: (1257:31,89 [3] ) |; | -Source Location: (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (197:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) | class Person { public string Name { get; set; } } | -Generated Location: (1784:46,12 [76] ) +Generated Location: (1797:46,12 [76] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.codegen.cs new file mode 100644 index 0000000000..6b858cb853 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.codegen.cs @@ -0,0 +1,40 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment template = (person) => + +#line default +#line hidden + (builder2) => { + builder2.OpenElement(0, "div"); + builder2.AddContent(1, person.Name); + builder2.CloseElement(); + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + builder.OpenComponent(2); + builder.AddAttribute(3, "PersonTemplate", new Microsoft.AspNetCore.Blazor.RenderFragment(template)); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.ir.txt new file mode 100644 index 0000000000..319b871451 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.ir.txt @@ -0,0 +1,24 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (35:1,2 [47] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [47] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = (person) => + Template - (83:1,50 [22] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (83:1,50 [23] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (89:1,56 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (89:1,56 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + CSharpCode - (106:1,73 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (106:1,73 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (111:2,0 [41] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (140:2,29 [9] x:\dir\subdir\Test\TestComponent.cshtml) - PersonTemplate - PersonTemplate + CSharpExpression - (141:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (141:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.mappings.txt new file mode 100644 index 0000000000..5f8bf908da --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_AsComponentParameter/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (35:1,2 [47] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = (person) => | +Generated Location: (654:18,2 [47] ) +| RenderFragment template = (person) => | + +Source Location: (106:1,73 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1047:28,73 [2] ) +|; | + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..cedb1fbd2c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.codegen.cs @@ -0,0 +1,39 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddContent(0, RenderPerson((person) => (builder2) => { + builder2.OpenElement(1, "div"); + builder2.AddContent(2, person.Name); + builder2.CloseElement(); + } + )); + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..477190a5db --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.ir.txt @@ -0,0 +1,21 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (1:0,1 [48] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (1:0,1 [25] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson((person) => + Template - (27:0,27 [22] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (27:0,27 [23] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (33:0,33 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (33:0,33 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + IntermediateToken - (50:0,50 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + CSharpCode - (65:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (65:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..cfd4eca5d3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_Generic_InImplicitExpression/TestComponent.mappings.txt @@ -0,0 +1,19 @@ +Source Location: (65:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| +Generated Location: (966:26,12 [138] ) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs index ee583ec422..e965d1304a 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs @@ -17,17 +17,17 @@ namespace Test base.BuildRenderTree(builder); #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" - RenderFragment p = + RenderFragment p = (person) => #line default #line hidden - (builder2, context) => { + (builder2) => { builder2.OpenElement(0, "div"); - builder2.AddContent(1, context.Name); + builder2.AddContent(1, person.Name); builder2.CloseElement(); } #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" - ; + ; #line default #line hidden diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt index a9cb531cf4..f5f71d3ca8 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt @@ -10,13 +10,13 @@ Document - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - CSharpCode - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = - Template - (36:1,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (36:1,32 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div - CSharpExpression - (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name - CSharpCode - (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n - CSharpCode - (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n + CSharpCode - (2:0,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = (person) => + Template - (48:1,44 [22] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (48:1,44 [23] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (54:1,50 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (54:1,50 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + CSharpCode - (71:1,67 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (71:1,67 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (89:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (89:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt index 69bfe294e0..9e5b2787f8 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt @@ -1,25 +1,25 @@ -Source Location: (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (2:0,2 [45] x:\dir\subdir\Test\TestComponent.cshtml) | - RenderFragment p = | -Generated Location: (654:18,2 [33] ) + RenderFragment p = (person) => | +Generated Location: (654:18,2 [45] ) | - RenderFragment p = | + RenderFragment p = (person) => | -Source Location: (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (71:1,67 [3] x:\dir\subdir\Test\TestComponent.cshtml) |; | -Generated Location: (1026:29,56 [3] ) +Generated Location: (1039:29,67 [3] ) |; | -Source Location: (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (89:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) | class Person { public string Name { get; set; } } | -Generated Location: (1172:36,12 [76] ) +Generated Location: (1185:36,12 [76] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs index 579dae9c2d..cedb1fbd2c 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs @@ -15,9 +15,9 @@ namespace Test protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); - builder.AddContent(0, RenderPerson((builder2, context) => { + builder.AddContent(0, RenderPerson((person) => (builder2) => { builder2.OpenElement(1, "div"); - builder2.AddContent(2, context.Name); + builder2.AddContent(2, person.Name); builder2.CloseElement(); } )); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt index 23100c99b0..1d656c5582 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt @@ -10,12 +10,12 @@ Document - MethodDeclaration - - protected override - void - BuildRenderTree CSharpCode - IntermediateToken - - CSharp - base.BuildRenderTree(builder); - CSharpExpression - (2:0,2 [37] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson( - Template - (16:0,16 [23] x:\dir\subdir\Test\TestComponent.cshtml) - HtmlElement - (16:0,16 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div - CSharpExpression - (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name - IntermediateToken - (40:0,40 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) - CSharpCode - (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n + CSharpExpression - (2:0,2 [48] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [25] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson((person) => + Template - (28:0,28 [22] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (28:0,28 [23] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (34:0,34 [11] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (34:0,34 [11] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - person.Name + IntermediateToken - (51:0,51 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + CSharpCode - (67:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (67:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt index 7984dc9042..f1afdb42e6 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt @@ -1,4 +1,4 @@ -Source Location: (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (67:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) | class Person { @@ -7,7 +7,7 @@ Source Location: (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) object RenderPerson(RenderFragment p) => null; | -Generated Location: (964:26,12 [138] ) +Generated Location: (966:26,12 [138] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs index 579dae9c2d..72f9bb503a 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs @@ -15,7 +15,7 @@ namespace Test protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); - builder.AddContent(0, RenderPerson((builder2, context) => { + builder.AddContent(0, RenderPerson((builder2) => { builder2.OpenElement(1, "div"); builder2.AddContent(2, context.Name); builder2.CloseElement(); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt index e80f72f7bc..9ea6166b91 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt @@ -7,7 +7,7 @@ Source Location: (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) object RenderPerson(RenderFragment p) => null; | -Generated Location: (964:26,12 [138] ) +Generated Location: (955:26,12 [138] ) | class Person { diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.codegen.cs new file mode 100644 index 0000000000..86b9e4f4ef --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.codegen.cs @@ -0,0 +1,38 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment template = + +#line default +#line hidden + (builder2) => { + builder2.AddMarkupContent(0, "
    Joey
    "); + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + builder.OpenComponent(1); + builder.AddAttribute(2, "Person", template); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.ir.txt new file mode 100644 index 0000000000..5c3acc9a52 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.ir.txt @@ -0,0 +1,22 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (35:1,2 [27] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [27] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = + Template - (63:1,30 [15] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlBlock - -
    Joey
    + CSharpCode - (78:1,45 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (78:1,45 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (83:2,0 [33] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - - Person - + CSharpExpression - (104:2,21 [9] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (105:2,22 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.mappings.txt new file mode 100644 index 0000000000..3d66fb2842 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_AsComponentParameter/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (35:1,2 [27] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = | +Generated Location: (654:18,2 [27] ) +| RenderFragment template = | + +Source Location: (78:1,45 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (920:26,45 [2] ) +|; | + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..dbd4f73615 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.codegen.cs @@ -0,0 +1,32 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddContent(0, RenderPerson((builder2) => { + builder2.AddMarkupContent(1, "
    HI
    "); + } + )); + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + object RenderPerson(RenderFragment p) => null; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..f7ece2bb5f --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.ir.txt @@ -0,0 +1,19 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (1:0,1 [27] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (1:0,1 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson( + Template - (15:0,15 [13] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlBlock - -
    HI
    + IntermediateToken - (28:0,28 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + CSharpCode - (43:1,12 [54] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (43:1,12 [54] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..eec6669210 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_NonGeneric_InImplicitExpression/TestComponent.mappings.txt @@ -0,0 +1,9 @@ +Source Location: (43:1,12 [54] x:\dir\subdir\Test\TestComponent.cshtml) +| + object RenderPerson(RenderFragment p) => null; +| +Generated Location: (873:24,12 [54] ) +| + object RenderPerson(RenderFragment p) => null; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs index e5a87975bb..a5b1641854 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs @@ -507,6 +507,33 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests e => Assert.Equal("#3 - c", e.Text)); } + [Fact] + public void CanRenderMultipleChildContent() + { + var appElement = MountTestComponent(); + + var table = appElement.FindElement(By.TagName("table")); + + var thead = table.FindElement(By.TagName("thead")); + Assert.Collection( + thead.FindElements(By.TagName("th")), + e => Assert.Equal("Col1", e.Text), + e => Assert.Equal("Col2", e.Text), + e => Assert.Equal("Col3", e.Text)); + + var tfoot = table.FindElement(By.TagName("tfoot")); + Assert.Empty(tfoot.FindElements(By.TagName("td"))); + + var toggle = appElement.FindElement(By.Id("toggle")); + toggle.Click(); + + Assert.Collection( + tfoot.FindElements(By.TagName("td")), + e => Assert.Equal("The", e.Text), + e => Assert.Equal("", e.Text), + e => Assert.Equal("End", e.Text)); + } + static IAlert SwitchToAlert(IWebDriver driver) { try diff --git a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/BaseTagHelperDescriptorProviderTest.cs b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/BaseTagHelperDescriptorProviderTest.cs index f8234f7971..67ffd4e3d7 100644 --- a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/BaseTagHelperDescriptorProviderTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/BaseTagHelperDescriptorProviderTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.Extensions.DependencyModel; -namespace Microsoft.AspNetCore.Blazor.Razor.Extensions +namespace Microsoft.AspNetCore.Blazor.Razor { public abstract class BaseTagHelperDescriptorProviderTest { diff --git a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/BindTagHelperDescriptorProviderTest.cs b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/BindTagHelperDescriptorProviderTest.cs index 64ffa6b41a..4aeb4aad49 100644 --- a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/BindTagHelperDescriptorProviderTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/BindTagHelperDescriptorProviderTest.cs @@ -1,13 +1,12 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Razor; using Xunit; -namespace Microsoft.AspNetCore.Blazor.Razor.Extensions +namespace Microsoft.AspNetCore.Blazor.Razor { public class BindTagHelperDescriptorProviderTest : BaseTagHelperDescriptorProviderTest { diff --git a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/ComponentTagHelperDescriptorProviderTest.cs b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/ComponentTagHelperDescriptorProviderTest.cs index 8a9343e92e..87aa02767e 100644 --- a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/ComponentTagHelperDescriptorProviderTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/ComponentTagHelperDescriptorProviderTest.cs @@ -3,11 +3,10 @@ using System.Linq; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Razor; using Xunit; -namespace Microsoft.AspNetCore.Blazor.Razor.Extensions +namespace Microsoft.AspNetCore.Blazor.Razor { public class ComponentTagHelperDescriptorProviderTest : BaseTagHelperDescriptorProviderTest { @@ -311,6 +310,198 @@ namespace Test Assert.False(attribute.IsEnum); Assert.False(attribute.IsStringProperty); Assert.True(attribute.IsDelegateProperty()); + Assert.False(attribute.IsChildContentProperty()); + } + + [Fact] + public void Execute_RenderFragmentProperty_CreatesDescriptors() + { + // Arrange + + var compilation = BaseCompilation.AddSyntaxTrees(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment ChildContent2 { get; set; } + } +} + +")); + + Assert.Empty(compilation.GetDiagnostics()); + + var context = TagHelperDescriptorProviderContext.Create(); + context.SetCompilation(compilation); + + var provider = new ComponentTagHelperDescriptorProvider(); + + // Act + provider.Execute(context); + + // Assert + var components = ExcludeBuiltInComponents(context); + var component = Assert.Single(components, c => c.IsComponentTagHelper()); + + Assert.Equal("TestAssembly", component.AssemblyName); + Assert.Equal("Test.MyComponent", component.Name); + + var attribute = Assert.Single(component.BoundAttributes); + Assert.Equal("ChildContent2", attribute.Name); + Assert.Equal("Microsoft.AspNetCore.Blazor.RenderFragment", attribute.TypeName); + + Assert.False(attribute.HasIndexer); + Assert.False(attribute.IsBooleanProperty); + Assert.False(attribute.IsEnum); + Assert.False(attribute.IsStringProperty); + Assert.False(attribute.IsDelegateProperty()); // We treat RenderFragment as separate from generalized delegates + Assert.True(attribute.IsChildContentProperty()); + Assert.False(attribute.IsParameterizedChildContentProperty()); + + var childContent = Assert.Single(components, c => c.IsChildContentTagHelper()); + + Assert.Equal("TestAssembly", childContent.AssemblyName); + Assert.Equal("Test.MyComponent.ChildContent2", childContent.Name); + + Assert.Empty(childContent.BoundAttributes); + } + + [Fact] + public void Execute_RenderFragmentOfTProperty_CreatesDescriptor() + { + // Arrange + + var compilation = BaseCompilation.AddSyntaxTrees(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment ChildContent2 { get; set; } + } +} + +")); + + Assert.Empty(compilation.GetDiagnostics()); + + var context = TagHelperDescriptorProviderContext.Create(); + context.SetCompilation(compilation); + + var provider = new ComponentTagHelperDescriptorProvider(); + + // Act + provider.Execute(context); + + // Assert + var components = ExcludeBuiltInComponents(context); + var component = Assert.Single(components, c => c.IsComponentTagHelper()); + + Assert.Equal("TestAssembly", component.AssemblyName); + Assert.Equal("Test.MyComponent", component.Name); + + var attribute = Assert.Single(component.BoundAttributes); + Assert.Equal("ChildContent2", attribute.Name); + Assert.Equal("Microsoft.AspNetCore.Blazor.RenderFragment", attribute.TypeName); + + Assert.False(attribute.HasIndexer); + Assert.False(attribute.IsBooleanProperty); + Assert.False(attribute.IsEnum); + Assert.False(attribute.IsStringProperty); + Assert.False(attribute.IsDelegateProperty()); // We treat RenderFragment as separate from generalized delegates + Assert.True(attribute.IsChildContentProperty()); + Assert.True(attribute.IsParameterizedChildContentProperty()); + + var childContent = Assert.Single(components, c => c.IsChildContentTagHelper()); + + Assert.Equal("TestAssembly", childContent.AssemblyName); + Assert.Equal("Test.MyComponent.ChildContent2", childContent.Name); + + // A RenderFragment tag helper has a parameter to allow you to set the lambda parameter name. + var contextAttribute = Assert.Single(childContent.BoundAttributes); + Assert.Equal("Context", contextAttribute.Name); + Assert.Equal("System.String", contextAttribute.TypeName); + Assert.Equal("Specifies the parameter name for the 'ChildContent2' lambda expression.", contextAttribute.Documentation); + } + + [Fact] + public void Execute_MultipleRenderFragmentProperties_CreatesDescriptor() + { + // Arrange + + var compilation = BaseCompilation.AddSyntaxTrees(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + RenderFragment ChildContent { get; set; } + + [Parameter] + RenderFragment Header { get; set; } + + [Parameter] + RenderFragment Footer { get; set; } + } +} + +")); + + Assert.Empty(compilation.GetDiagnostics()); + + var context = TagHelperDescriptorProviderContext.Create(); + context.SetCompilation(compilation); + + var provider = new ComponentTagHelperDescriptorProvider(); + + // Act + provider.Execute(context); + + // Assert + var components = ExcludeBuiltInComponents(context); + var component = Assert.Single(components, c => c.IsComponentTagHelper()); + + Assert.Equal("TestAssembly", component.AssemblyName); + Assert.Equal("Test.MyComponent", component.Name); + + Assert.Collection( + component.BoundAttributes.OrderBy(a => a.Name), + a => + { + Assert.Equal("ChildContent", a.Name); + Assert.Equal("Microsoft.AspNetCore.Blazor.RenderFragment", a.TypeName); + Assert.True(a.IsChildContentProperty()); + }, + a => + { + Assert.Equal("Footer", a.Name); + Assert.Equal("Microsoft.AspNetCore.Blazor.RenderFragment", a.TypeName); + Assert.True(a.IsChildContentProperty()); + }, + a => + { + Assert.Equal("Header", a.Name); + Assert.Equal("Microsoft.AspNetCore.Blazor.RenderFragment", a.TypeName); + Assert.True(a.IsChildContentProperty()); + }); + + + var childContents = components.Where(c => c.IsChildContentTagHelper()).OrderBy(c => c.Name); + Assert.Collection( + childContents, + c => Assert.Equal("Test.MyComponent.ChildContent", c.Name), + c => Assert.Equal("Test.MyComponent.Footer", c.Name), + c => Assert.Equal("Test.MyComponent.Header", c.Name)); } [Fact] // This component has lots of properties that don't become components. diff --git a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/EventHandlerTagHelperDescriptorProviderTest.cs b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/EventHandlerTagHelperDescriptorProviderTest.cs index 5f6d7959ad..4c0344202a 100644 --- a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/EventHandlerTagHelperDescriptorProviderTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/EventHandlerTagHelperDescriptorProviderTest.cs @@ -4,11 +4,10 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Razor.Language; -using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Razor; using Xunit; -namespace Microsoft.AspNetCore.Blazor.Razor.Extensions +namespace Microsoft.AspNetCore.Blazor.Razor { public class EventHandlerTagHelperDescriptorProviderTest : BaseTagHelperDescriptorProviderTest { diff --git a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/RefTagHelperDescriptorProviderTest.cs b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/RefTagHelperDescriptorProviderTest.cs index cf38cdac5b..e149f37f35 100644 --- a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/RefTagHelperDescriptorProviderTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/RefTagHelperDescriptorProviderTest.cs @@ -1,11 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Razor.Language; using System.Linq; using Xunit; -namespace Microsoft.AspNetCore.Blazor.Razor.Extensions.Test +namespace Microsoft.AspNetCore.Blazor.Razor { public class RefTagHelperDescriptorProviderTest : BaseTagHelperDescriptorProviderTest { diff --git a/test/testapps/BasicTestApp/Index.cshtml b/test/testapps/BasicTestApp/Index.cshtml index 88108c5d48..ab0f6f49e1 100644 --- a/test/testapps/BasicTestApp/Index.cshtml +++ b/test/testapps/BasicTestApp/Index.cshtml @@ -40,6 +40,7 @@ + @if (SelectedComponentType != null) diff --git a/test/testapps/BasicTestApp/MultipleChildContent.cshtml b/test/testapps/BasicTestApp/MultipleChildContent.cshtml new file mode 100644 index 0000000000..5e6b42cbda --- /dev/null +++ b/test/testapps/BasicTestApp/MultipleChildContent.cshtml @@ -0,0 +1,25 @@ + +
    Col1Col2Col3
    +
    + @if (ShowFooter) + { + TheEnd + } +
    + + @context.Col1@context.Col2@context.Col3 + +
    + +Toggle: + +@functions { + List Items { get; } = new List() + { + new TemplatedTable.Item(){ Col1 = "a0", Col2 = "b0", Col3 = "c0", }, + new TemplatedTable.Item(){ Col1 = "a1", Col2 = "b1", Col3 = "c1", }, + new TemplatedTable.Item(){ Col1 = "a2", Col2 = "b2", Col3 = "c2", }, + }; + + bool ShowFooter; +} \ No newline at end of file diff --git a/test/testapps/BasicTestApp/OrderedList.cshtml b/test/testapps/BasicTestApp/OrderedList.cshtml index a410635a73..111b88b585 100644 --- a/test/testapps/BasicTestApp/OrderedList.cshtml +++ b/test/testapps/BasicTestApp/OrderedList.cshtml @@ -4,7 +4,7 @@ } @foreach (var item in Items) { - @Template.WithValue(new Context() { Index = index++, Item = item, }); + @Template(new Context() { Index = index++, Item = item, }); } diff --git a/test/testapps/BasicTestApp/RazorTemplates.cshtml b/test/testapps/BasicTestApp/RazorTemplates.cshtml index e2ef8cc7ff..721056f922 100644 --- a/test/testapps/BasicTestApp/RazorTemplates.cshtml +++ b/test/testapps/BasicTestApp/RazorTemplates.cshtml @@ -4,7 +4,7 @@
    @{ - RenderFragment template = @
  • #@context.Index - @context.Item.ToLower()
  • ; + RenderFragment template = (context) => @
  • #@context.Index - @context.Item.ToLower()
  • ; }
    diff --git a/test/testapps/BasicTestApp/TemplatedTable.cshtml b/test/testapps/BasicTestApp/TemplatedTable.cshtml new file mode 100644 index 0000000000..e0ac565f5b --- /dev/null +++ b/test/testapps/BasicTestApp/TemplatedTable.cshtml @@ -0,0 +1,41 @@ + + @if (Header != null) + { + + @Header + + } + + @for (var i = 0; i < Items.Count; i++) + { + var item = Items[i]; + @ItemTemplate(item) + } + + + @if (Footer != null) + { + @Footer + } +
    + +@functions { + [Parameter] + RenderFragment Header { get; set; } + + [Parameter] + RenderFragment ItemTemplate { get; set; } + + [Parameter] + RenderFragment Footer { get; set; } + + [Parameter] + IReadOnlyList Items { get; set; } + + public class Item + { + public string Col1 { get; set; } + public string Col2 { get; set; } + public string Col3 { get; set; } + } +} \ No newline at end of file