diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs index bf4e604b52..ddf672c431 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor { private readonly ScopeStack _scopeStack = new ScopeStack(); - private readonly static string DesignTimeVariable = "__o"; + private static readonly string DesignTimeVariable = "__o"; public override void WriteHtmlBlock(CodeRenderingContext context, HtmlBlockIntermediateNode node) { @@ -343,40 +343,121 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - foreach (var typeArgument in node.TypeArguments) + if (node.TypeInferenceNode == null) { - context.RenderNode(typeArgument); - } - - foreach (var attribute in node.Attributes) - { - context.RenderNode(attribute); - } - - if (node.ChildContents.Any()) - { - foreach (var childContent in node.ChildContents) + // Writes something like: + // + // builder.OpenComponent(0); + // builder.AddAttribute(1, "Foo", ...); + // builder.AddAttribute(2, "ChildContent", ...); + // builder.AddElementCapture(3, (__value) => _field = __value); + // builder.CloseComponent(); + foreach (var typeArgument in node.TypeArguments) { - context.RenderNode(childContent); + context.RenderNode(typeArgument); + } + + foreach (var attribute in node.Attributes) + { + context.RenderNode(attribute); + } + + if (node.ChildContents.Any()) + { + 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() + { + TypeName = BlazorApi.RenderFragment.FullTypeName, + }); + } + + foreach (var capture in node.Captures) + { + context.RenderNode(capture); } } else { - // We eliminate 'empty' child content when building the tree so that usage like - // '\r\n' doesn't create a child content. + // When we're doing type inference, we can't write all of the code inline to initialize + // the component on the builder. We generate a method elsewhere, and then pass all of the information + // to that method. We pass in all of the attribute values + the sequence numbers. // - // 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() - { - TypeName = BlazorApi.RenderFragment.FullTypeName, - }); - } + // __Blazor.MyComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, ..., 2, ..., 3, ....); + var attributes = node.Attributes.ToList(); + var childContents = node.ChildContents.ToList(); + var captures = node.Captures.ToList(); + var remaining = attributes.Count + childContents.Count + captures.Count; - foreach (var capture in node.Captures) - { - context.RenderNode(capture); + context.CodeWriter.Write(node.TypeInferenceNode.FullTypeName); + context.CodeWriter.Write("."); + context.CodeWriter.Write(node.TypeInferenceNode.MethodName); + context.CodeWriter.Write("("); + + context.CodeWriter.Write(_scopeStack.BuilderVarName); + context.CodeWriter.Write(", "); + + context.CodeWriter.Write("-1"); + context.CodeWriter.Write(", "); + + for (var i = 0; i < attributes.Count; i++) + { + context.CodeWriter.Write("-1"); + context.CodeWriter.Write(", "); + + // Don't type check generics, since we can't actually write the type name. + // The type checking with happen anyway since we defined a method and we're generating + // a call to it. + WriteComponentAttributeInnards(context, attributes[i], canTypeCheck: false); + + remaining--; + if (remaining > 0) + { + context.CodeWriter.Write(", "); + } + } + + for (var i = 0; i < childContents.Count; i++) + { + context.CodeWriter.Write("-1"); + context.CodeWriter.Write(", "); + + WriteComponentChildContentInnards(context, childContents[i]); + + remaining--; + if (remaining > 0) + { + context.CodeWriter.Write(", "); + } + } + + for (var i = 0; i < captures.Count; i++) + { + context.CodeWriter.Write("-1"); + context.CodeWriter.Write(", "); + + WriteReferenceCaptureInnards(context, captures[i], shouldTypeCheck: false); + + remaining--; + if (remaining > 0) + { + context.CodeWriter.Write(", "); + } + } + + context.CodeWriter.Write(");"); + context.CodeWriter.WriteLine(); } } @@ -392,15 +473,28 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - // For design time we only care about the case where the attribute has c# code. - // - // We also limit component attributes to simple cases. However there is still a lot of complexity + // Looks like: + // __o = 17; + context.CodeWriter.Write(DesignTimeVariable); + context.CodeWriter.Write(" = "); + + // Following the same design pattern as the runtime codegen + WriteComponentAttributeInnards(context, node, canTypeCheck: true); + + context.CodeWriter.Write(";"); + context.CodeWriter.WriteLine(); + } + + private void WriteComponentAttributeInnards(CodeRenderingContext context, ComponentAttributeExtensionNode node, bool canTypeCheck) + { + // We limit component attributes to simple cases. However there is still a lot of complexity // to handle here, since there are a few different cases for how an attribute might be structured. // // This roughly follows the design of the runtime writer for simplicity. if (node.AttributeStructure == AttributeStructure.Minimized) { - // Do nothing + // Minimized attributes always map to 'true' + context.CodeWriter.Write("true"); } else if (node.Children.Count > 1) { @@ -409,7 +503,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor } else if (node.Children.Count == 1 && node.Children[0] is HtmlContentIntermediateNode) { - // Do nothing + // We don't actually need the content at designtime, an empty string will do. + context.CodeWriter.Write("\"\""); } else { @@ -430,11 +525,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor { // We always surround the expression with the delegate constructor. This makes type // inference inside lambdas, and method group conversion do the right thing. - context.CodeWriter.Write(DesignTimeVariable); - context.CodeWriter.Write(" = "); - context.CodeWriter.Write("new "); - context.CodeWriter.Write(node.TypeName); - context.CodeWriter.Write("("); + if (canTypeCheck) + { + context.CodeWriter.Write("new "); + context.CodeWriter.Write(node.TypeName); + context.CodeWriter.Write("("); + } context.CodeWriter.WriteLine(); for (var i = 0; i < tokens.Count; i++) @@ -442,17 +538,17 @@ namespace Microsoft.AspNetCore.Blazor.Razor WriteCSharpToken(context, tokens[i]); } - context.CodeWriter.Write(");"); - context.CodeWriter.WriteLine(); + if (canTypeCheck) + { + context.CodeWriter.Write(")"); + } } else { // This is the case when an attribute contains C# code - context.CodeWriter.Write(DesignTimeVariable); - context.CodeWriter.Write(" = "); - + // // If we have a parameter type, then add a type check. - if (NeedsTypeCheck(node)) + if (canTypeCheck && NeedsTypeCheck(node)) { context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck); context.CodeWriter.Write("<"); @@ -466,13 +562,10 @@ namespace Microsoft.AspNetCore.Blazor.Razor WriteCSharpToken(context, tokens[i]); } - if (NeedsTypeCheck(node)) + if (canTypeCheck && NeedsTypeCheck(node)) { context.CodeWriter.Write(")"); } - - context.CodeWriter.Write(";"); - context.CodeWriter.WriteLine(); } } @@ -500,10 +593,30 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } + // Writes something like: + // + // builder.AddAttribute(1, "ChildContent", (RenderFragment)((__builder73) => { ... })); + // OR + // builder.AddAttribute(1, "ChildContent", (RenderFragment)((person) => (__builder73) => { ... })); + BeginWriteAttribute(context.CodeWriter, node.AttributeName); + context.CodeWriter.Write($"({node.TypeName})("); + + WriteComponentChildContentInnards(context, node); + + context.CodeWriter.Write(")"); + context.CodeWriter.WriteEndMethodInvocation(); + } + + private void WriteComponentChildContentInnards(CodeRenderingContext context, ComponentChildContentIntermediateNode node) + { + // Writes something like: + // + // ((__builder73) => { ... }) + // OR + // ((person) => (__builder73) => { }) _scopeStack.OpenComponentScope( context, node.AttributeName, - node.TypeName, node.IsParameterized ? node.ParameterName : null); for (var i = 0; i < node.Children.Count; i++) { @@ -559,42 +672,83 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } + // Looks like: + // + // (__builder73) => { ... } _scopeStack.OpenTemplateScope(context); context.RenderChildren(node); _scopeStack.CloseScope(context); } - public override void WriteReferenceCapture(CodeRenderingContext context, RefExtensionNode refNode) + public override void WriteReferenceCapture(CodeRenderingContext context, RefExtensionNode node) { if (context == null) { throw new ArgumentNullException(nameof(context)); } - if (refNode == null) + if (node == null) { - throw new ArgumentNullException(nameof(refNode)); + throw new ArgumentNullException(nameof(node)); } - // The runtime node writer moves the call elsewhere. At design time we - // just want sufficiently similar code that any unknown-identifier or type - // errors will be equivalent - var captureTypeName = refNode.IsComponentCapture - ? refNode.ComponentCaptureTypeName - : BlazorApi.ElementRef.FullTypeName; - WriteCSharpCode(context, new CSharpCodeIntermediateNode + // Looks like: + // + // __field = default(MyComponent); + WriteReferenceCaptureInnards(context, node, shouldTypeCheck: true); + } + + protected override void WriteReferenceCaptureInnards(CodeRenderingContext context, RefExtensionNode node, bool shouldTypeCheck) + { + // We specialize this code based on whether or not we can type check. When we're calling into + // a type-inferenced component, we can't do the type check. See the comments in WriteTypeInferenceMethod. + if (shouldTypeCheck) { - Source = refNode.Source, - Children = + // The runtime node writer moves the call elsewhere. At design time we + // just want sufficiently similar code that any unknown-identifier or type + // errors will be equivalent + var captureTypeName = node.IsComponentCapture + ? node.ComponentCaptureTypeName + : BlazorApi.ElementRef.FullTypeName; + WriteCSharpCode(context, new CSharpCodeIntermediateNode { - refNode.IdentifierToken, - new IntermediateToken + Source = node.Source, + Children = { - Kind = TokenKind.CSharp, - Content = $" = default({captureTypeName});" + node.IdentifierToken, + new IntermediateToken + { + Kind = TokenKind.CSharp, + Content = $" = default({captureTypeName});" + } } + }); + } + else + { + // Looks like: + // + // (__value) = { _field = (MyComponent)__value; } + // OR + // (__value) = { _field = (ElementRef)__value; } + const string refCaptureParamName = "__value"; + using (var lambdaScope = context.CodeWriter.BuildLambda(refCaptureParamName)) + { + WriteCSharpCode(context, new CSharpCodeIntermediateNode + { + Source = node.Source, + Children = + { + node.IdentifierToken, + new IntermediateToken + { + Kind = TokenKind.CSharp, + Content = $" = {refCaptureParamName};" + } + } + }); } - }); + } } private void WriteCSharpToken(CodeRenderingContext context, IntermediateToken token) diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs index cae48af8f1..563a1edebe 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs @@ -280,6 +280,24 @@ namespace Microsoft.AspNetCore.Blazor.Razor var attributesText = string.Join(", ", attributes.Select(a => $"'{a.Name}'")); return RazorDiagnostic.Create(GenericComponentMissingTypeArgument, source ?? SourceSpan.Undefined, component.TagName, attributesText); } + + public static readonly RazorDiagnosticDescriptor GenericComponentTypeInferenceUnderspecified = + new RazorDiagnosticDescriptor( + "BL10001", + () => "The type of component '{0}' cannot be inferred based on the values provided. Consider specifying the type arguments " + + "directly using the following attributes: {1}.", + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic Create_GenericComponentTypeInferenceUnderspecified( + SourceSpan? source, + ComponentExtensionNode component, + IEnumerable attributes) + { + Debug.Assert(component.Component.IsGenericTypedComponent()); + + var attributesText = string.Join(", ", attributes.Select(a => $"'{a.Name}'")); + return RazorDiagnostic.Create(GenericComponentTypeInferenceUnderspecified, source ?? SourceSpan.Undefined, component.TagName, attributesText); + } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs index 63d266d708..432dec10cc 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs @@ -1,11 +1,13 @@ // 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.Linq; +using Microsoft.AspNetCore.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; +using System; +using System.Collections.Generic; +using System.Linq; namespace Microsoft.AspNetCore.Blazor.Razor { @@ -27,6 +29,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor public abstract void WriteReferenceCapture(CodeRenderingContext context, RefExtensionNode node); + protected abstract void WriteReferenceCaptureInnards(CodeRenderingContext context, RefExtensionNode node, bool shouldTypeCheck); + public abstract void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node); public sealed override void BeginWriterScope(CodeRenderingContext context, string writer) @@ -49,5 +53,166 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.Diagnostics.Add(BlazorDiagnosticFactory.Create_CodeBlockInAttribute(node.Source, content)); return; } + + + // Currently the same for design time and runtime + public void WriteComponentTypeInferenceMethod(CodeRenderingContext context, ComponentTypeInferenceMethodIntermediateNode node) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (node == null) + { + throw new ArgumentNullException(nameof(node)); + } + + // This is ugly because CodeWriter doesn't allow us to erase, but we need to comma-delimit. So we have to + // materizalize something can iterate, or use string.Join. We'll need this multiple times, so materializing + // it. + var parameters = GetParameterDeclarations(); + + // This is really similar to the code in WriteComponentAttribute and WriteComponentChildContent - except simpler because + // attributes and child contents look like variables. + // + // Looks like: + // + // public static void CreateFoo_0(RenderTreeBuilder builder, int seq, int __seq0, T1 __arg0, int __seq1, global::System.Collections.Generic.List __arg1, int __seq2, string __arg2) + // { + // builder.OpenComponent>(); + // builder.AddAttribute(__seq0, "Attr0", __arg0); + // builder.AddAttribute(__seq1, "Attr1", __arg1); + // builder.AddAttribute(__seq2, "Attr2", __arg2); + // builder.CloseComponent(); + // } + // + // As a special case, we need to generate a thunk for captures in this block instead of using + // them verbatim. + // + // The problem is that RenderTreeBuilder wants an Action. The caller can't write the type + // name if it contains generics, and we can't write the variable they want to assign to. + var writer = context.CodeWriter; + + writer.Write("public static void "); + writer.Write(node.MethodName); + + writer.Write("<"); + writer.Write(string.Join(", ", node.Component.Component.GetTypeParameters().Select(a => a.Name))); + writer.Write(">"); + + writer.Write("("); + writer.Write("global::"); + writer.Write(BlazorApi.RenderTreeBuilder.FullTypeName); + writer.Write(" builder"); + writer.Write(", "); + writer.Write("int seq"); + + if (parameters.Count > 0) + { + writer.Write(", "); + } + + for (var i = 0; i < parameters.Count; i++) + { + writer.Write("int "); + writer.Write(parameters[i].seqName); + + writer.Write(", "); + writer.Write(parameters[i].typeName); + writer.Write(" "); + writer.Write(parameters[i].parameterName); + + if (i < parameters.Count - 1) + { + writer.Write(", "); + } + } + + writer.Write(")"); + writer.WriteLine(); + + writer.WriteLine("{"); + + // builder.OpenComponent(42); + context.CodeWriter.Write("builder"); + context.CodeWriter.Write("."); + context.CodeWriter.Write(BlazorApi.RenderTreeBuilder.OpenComponent); + context.CodeWriter.Write("<"); + context.CodeWriter.Write(node.Component.TypeName); + context.CodeWriter.Write(">("); + context.CodeWriter.Write("seq"); + context.CodeWriter.Write(");"); + context.CodeWriter.WriteLine(); + + var index = 0; + foreach (var attribute in node.Component.Attributes) + { + context.CodeWriter.WriteStartInstanceMethodInvocation("builder", BlazorApi.RenderTreeBuilder.AddAttribute); + context.CodeWriter.Write(parameters[index].seqName); + context.CodeWriter.Write(", "); + + context.CodeWriter.Write($"\"{attribute.AttributeName}\""); + context.CodeWriter.Write(", "); + + context.CodeWriter.Write(parameters[index].parameterName); + context.CodeWriter.WriteEndMethodInvocation(); + + index++; + } + + foreach (var childContent in node.Component.ChildContents) + { + context.CodeWriter.WriteStartInstanceMethodInvocation("builder", BlazorApi.RenderTreeBuilder.AddAttribute); + context.CodeWriter.Write(parameters[index].seqName); + context.CodeWriter.Write(", "); + + context.CodeWriter.Write($"\"{childContent.AttributeName}\""); + context.CodeWriter.Write(", "); + + context.CodeWriter.Write(parameters[index].parameterName); + context.CodeWriter.WriteEndMethodInvocation(); + + index++; + } + + foreach (var capture in node.Component.Captures) + { + context.CodeWriter.WriteStartInstanceMethodInvocation("builder", capture.IsComponentCapture ? BlazorApi.RenderTreeBuilder.AddComponentReferenceCapture : BlazorApi.RenderTreeBuilder.AddElementReferenceCapture); + context.CodeWriter.Write(parameters[index].seqName); + context.CodeWriter.Write(", "); + + var cast = capture.IsComponentCapture ? $"({capture.ComponentCaptureTypeName})" : string.Empty; + context.CodeWriter.Write($"(__value) => {{ {parameters[index].parameterName}({cast}__value); }}"); + context.CodeWriter.WriteEndMethodInvocation(); + + index++; + } + + context.CodeWriter.WriteInstanceMethodInvocation("builder", BlazorApi.RenderTreeBuilder.CloseComponent); + + writer.WriteLine("}"); + + List<(string seqName, string typeName, string parameterName)> GetParameterDeclarations() + { + var p = new List<(string seqName, string typeName, string parameterName)>(); + foreach (var attribute in node.Component.Attributes) + { + p.Add(($"__seq{p.Count}", attribute.TypeName, $"__arg{p.Count}")); + } + + foreach (var childContent in node.Component.ChildContents) + { + p.Add(($"__seq{p.Count}", childContent.TypeName, $"__arg{p.Count}")); + } + + foreach (var capture in node.Component.Captures) + { + p.Add(($"__seq{p.Count}", capture.TypeName, $"__arg{p.Count}")); + } + + return p; + } + } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs index bd0b85a57c..043aea851a 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs @@ -197,16 +197,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.RenderNode(capture); } - _scopeStack.OpenElementScope(node.TagName); - // Render body of the tag inside the scope foreach (var child in node.Body) { context.RenderNode(child); } - _scopeStack.CloseScope(context); - context.CodeWriter .WriteStartMethodInvocation($"{_scopeStack.BuilderVarName}.{BlazorApi.RenderTreeBuilder.CloseElement}") .WriteEndMethodInvocation(); @@ -296,41 +292,126 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - // builder.OpenComponent(42); - context.CodeWriter.Write(_scopeStack.BuilderVarName); - context.CodeWriter.Write("."); - context.CodeWriter.Write(BlazorApi.RenderTreeBuilder.OpenComponent); - context.CodeWriter.Write("<"); - context.CodeWriter.Write(node.TypeName); - context.CodeWriter.Write(">("); - context.CodeWriter.Write((_sourceSequence++).ToString()); - context.CodeWriter.Write(");"); - context.CodeWriter.WriteLine(); - - // We can skip type arguments during runtime codegen, they are handled in the - // type/parameter declarations. - - foreach (var attribute in node.Attributes) + if (node.TypeInferenceNode == null) { - context.RenderNode(attribute); - } - - foreach (var childContent in node.ChildContents) - { - context.RenderNode(childContent); - } + // If the component is using not using type inference then we just write an open/close with a series + // of add attribute calls in between. + // + // Writes something like: + // + // builder.OpenComponent(0); + // builder.AddAttribute(1, "Foo", ...); + // builder.AddAttribute(2, "ChildContent", ...); + // builder.AddElementCapture(3, (__value) => _field = __value); + // builder.CloseComponent(); - foreach (var capture in node.Captures) - { - context.RenderNode(capture); - } + // builder.OpenComponent(42); + context.CodeWriter.Write(_scopeStack.BuilderVarName); + context.CodeWriter.Write("."); + context.CodeWriter.Write(BlazorApi.RenderTreeBuilder.OpenComponent); + context.CodeWriter.Write("<"); + context.CodeWriter.Write(node.TypeName); + context.CodeWriter.Write(">("); + context.CodeWriter.Write((_sourceSequence++).ToString()); + context.CodeWriter.Write(");"); + context.CodeWriter.WriteLine(); - // builder.CloseComponent(); - context.CodeWriter.Write(_scopeStack.BuilderVarName); - context.CodeWriter.Write("."); - context.CodeWriter.Write(BlazorApi.RenderTreeBuilder.CloseComponent); - context.CodeWriter.Write("();"); - context.CodeWriter.WriteLine(); + // We can skip type arguments during runtime codegen, they are handled in the + // type/parameter declarations. + + foreach (var attribute in node.Attributes) + { + context.RenderNode(attribute); + } + + foreach (var childContent in node.ChildContents) + { + context.RenderNode(childContent); + } + + foreach (var capture in node.Captures) + { + context.RenderNode(capture); + } + + // builder.CloseComponent(); + context.CodeWriter.Write(_scopeStack.BuilderVarName); + context.CodeWriter.Write("."); + context.CodeWriter.Write(BlazorApi.RenderTreeBuilder.CloseComponent); + context.CodeWriter.Write("();"); + context.CodeWriter.WriteLine(); + } + else + { + // When we're doing type inference, we can't write all of the code inline to initialize + // the component on the builder. We generate a method elsewhere, and then pass all of the information + // to that method. We pass in all of the attribute values + the sequence numbers. + // + // __Blazor.MyComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, ..., 2, ..., 3, ...); + var attributes = node.Attributes.ToList(); + var childContents = node.ChildContents.ToList(); + var captures = node.Captures.ToList(); + var remaining = attributes.Count + childContents.Count + captures.Count; + + context.CodeWriter.Write(node.TypeInferenceNode.FullTypeName); + context.CodeWriter.Write("."); + context.CodeWriter.Write(node.TypeInferenceNode.MethodName); + context.CodeWriter.Write("("); + + context.CodeWriter.Write(_scopeStack.BuilderVarName); + context.CodeWriter.Write(", "); + + context.CodeWriter.Write((_sourceSequence++).ToString()); + context.CodeWriter.Write(", "); + + for (var i = 0; i < attributes.Count; i++) + { + context.CodeWriter.Write((_sourceSequence++).ToString()); + context.CodeWriter.Write(", "); + + // Don't type check generics, since we can't actually write the type name. + // The type checking with happen anyway since we defined a method and we're generating + // a call to it. + WriteComponentAttributeInnards(context, attributes[i], canTypeCheck: false); + + remaining--; + if (remaining > 0) + { + context.CodeWriter.Write(", "); + } + } + + for (var i = 0; i < childContents.Count; i++) + { + context.CodeWriter.Write((_sourceSequence++).ToString()); + context.CodeWriter.Write(", "); + + WriteComponentChildContentInnards(context, childContents[i]); + + remaining--; + if (remaining > 0) + { + context.CodeWriter.Write(", "); + } + } + + for (var i = 0; i < captures.Count; i++) + { + context.CodeWriter.Write((_sourceSequence++).ToString()); + context.CodeWriter.Write(", "); + + WriteReferenceCaptureInnards(context, captures[i], shouldTypeCheck: false); + + remaining--; + if (remaining > 0) + { + context.CodeWriter.Write(", "); + } + } + + context.CodeWriter.Write(");"); + context.CodeWriter.WriteLine(); + } } public override void WriteComponentAttribute(CodeRenderingContext context, ComponentAttributeExtensionNode node) @@ -345,7 +426,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } - // builder.OpenComponent(42); + // builder.AddAttribute(1, "Foo", 42); context.CodeWriter.Write(_scopeStack.BuilderVarName); context.CodeWriter.Write("."); context.CodeWriter.Write(BlazorApi.RenderTreeBuilder.AddAttribute); @@ -355,6 +436,14 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.CodeWriter.WriteStringLiteral(node.AttributeName); context.CodeWriter.Write(", "); + WriteComponentAttributeInnards(context, node, canTypeCheck: true); + + context.CodeWriter.Write(");"); + context.CodeWriter.WriteLine(); + } + + private void WriteComponentAttributeInnards(CodeRenderingContext context, ComponentAttributeExtensionNode node, bool canTypeCheck) + { if (node.AttributeStructure == AttributeStructure.Minimized) { // Minimized attributes always map to 'true' @@ -378,20 +467,26 @@ namespace Microsoft.AspNetCore.Blazor.Razor if ((node.BoundAttribute?.IsDelegateProperty() ?? false) || (node.BoundAttribute?.IsChildContentProperty() ?? false)) { - context.CodeWriter.Write("new "); - context.CodeWriter.Write(node.TypeName); - context.CodeWriter.Write("("); + if (canTypeCheck) + { + context.CodeWriter.Write("new "); + context.CodeWriter.Write(node.TypeName); + context.CodeWriter.Write("("); + } for (var i = 0; i < tokens.Count; i++) { context.CodeWriter.Write(tokens[i].Content); } - context.CodeWriter.Write(")"); + if (canTypeCheck) + { + context.CodeWriter.Write(")"); + } } else { - if (NeedsTypeCheck(node)) + if (canTypeCheck && NeedsTypeCheck(node)) { context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck); context.CodeWriter.Write("<"); @@ -405,16 +500,13 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.CodeWriter.Write(tokens[i].Content); } - if (NeedsTypeCheck(node)) + if (canTypeCheck && NeedsTypeCheck(node)) { context.CodeWriter.Write(")"); } } } - context.CodeWriter.Write(");"); - context.CodeWriter.WriteLine(); - IReadOnlyList GetCSharpTokens(ComponentAttributeExtensionNode attribute) { // We generally expect all children to be CSharp, this is here just in case. @@ -445,10 +537,30 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } + // Writes something like: + // + // builder.AddAttribute(1, "ChildContent", (RenderFragment)((__builder73) => { ... })); + // OR + // builder.AddAttribute(1, "ChildContent", (RenderFragment)((person) => (__builder73) => { ... })); + BeginWriteAttribute(context.CodeWriter, node.AttributeName); + context.CodeWriter.Write($"({node.TypeName})("); + + WriteComponentChildContentInnards(context, node); + + context.CodeWriter.Write(")"); + context.CodeWriter.WriteEndMethodInvocation(); + } + + private void WriteComponentChildContentInnards(CodeRenderingContext context, ComponentChildContentIntermediateNode node) + { + // Writes something like: + // + // ((__builder73) => { ... }) + // OR + // ((person) => (__builder73) => { }) _scopeStack.OpenComponentScope( context, node.AttributeName, - node.TypeName, node.IsParameterized ? node.ParameterName : null); for (var i = 0; i < node.Children.Count; i++) { @@ -475,6 +587,9 @@ namespace Microsoft.AspNetCore.Blazor.Razor throw new ArgumentNullException(nameof(node)); } + // Looks like: + // + // (__builder73) => { ... } _scopeStack.OpenTemplateScope(context); context.RenderChildren(node); _scopeStack.CloseScope(context); @@ -482,6 +597,11 @@ namespace Microsoft.AspNetCore.Blazor.Razor public override void WriteReferenceCapture(CodeRenderingContext context, RefExtensionNode node) { + // Looks like: + // + // builder.AddComponentReferenceCapture(2, (__value) = { _field = (MyComponent)__value; }); + // OR + // builder.AddElementReferenceCapture(2, (__value) = { _field = (ElementRef)__value; }); var codeWriter = context.CodeWriter; var methodName = node.IsComponentCapture @@ -492,25 +612,36 @@ namespace Microsoft.AspNetCore.Blazor.Razor .Write((_sourceSequence++).ToString()) .WriteParameterSeparator(); + WriteReferenceCaptureInnards(context, node, shouldTypeCheck: true); + + codeWriter.WriteEndMethodInvocation(); + } + + protected override void WriteReferenceCaptureInnards(CodeRenderingContext context, RefExtensionNode node, bool shouldTypeCheck) + { + // Looks like: + // + // (__value) = { _field = (MyComponent)__value; } + // OR + // (__value) = { _field = (ElementRef)__value; } const string refCaptureParamName = "__value"; - using (var lambdaScope = codeWriter.BuildLambda(refCaptureParamName)) + using (var lambdaScope = context.CodeWriter.BuildLambda(refCaptureParamName)) { - var typecastIfNeeded = node.IsComponentCapture ? $"({node.ComponentCaptureTypeName})" : string.Empty; + var typecastIfNeeded = shouldTypeCheck && node.IsComponentCapture ? $"({node.ComponentCaptureTypeName})" : string.Empty; WriteCSharpCode(context, new CSharpCodeIntermediateNode { Source = node.Source, Children = { node.IdentifierToken, - new IntermediateToken { + new IntermediateToken + { Kind = TokenKind.CSharp, Content = $" = {typecastIfNeeded}{refCaptureParamName};" } } }); } - - codeWriter.WriteEndMethodInvocation(); } private void WriteAttribute(CodeWriter codeWriter, string key, IList value) diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentExtensionNode.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentExtensionNode.cs index 45e955ffb5..226aa5aa88 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentExtensionNode.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentExtensionNode.cs @@ -27,6 +27,10 @@ namespace Microsoft.AspNetCore.Blazor.Razor public string TagName { get; set; } + // An optional type inference node. This will be populated (and point to a different part of the tree) + // if this component call site requires type inference. + public ComponentTypeInferenceMethodIntermediateNode TypeInferenceNode { get; set; } + public string TypeName { get; set; } public override void Accept(IntermediateNodeVisitor visitor) diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentTypeInferenceMethodIntermediateNode.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentTypeInferenceMethodIntermediateNode.cs new file mode 100644 index 0000000000..cf08c02f57 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ComponentTypeInferenceMethodIntermediateNode.cs @@ -0,0 +1,61 @@ +// 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.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Blazor.Razor +{ + /// + /// Represents a type-inference thunk that is used by the generated component code. + /// + internal class ComponentTypeInferenceMethodIntermediateNode : ExtensionIntermediateNode + { + public Dictionary Bindings { get; set; } + + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; + + /// + /// Gets the component usage linked to this type inference method. + /// + public ComponentExtensionNode Component { get; set; } + + /// + /// Gets the full type name of the generated class containing this method. + /// + public string FullTypeName { get; internal set; } + + /// + /// Gets the name of the generated method. + /// + public string MethodName { get; set; } + + 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.WriteComponentTypeInferenceMethod(context, this); + } + } +} diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/GenericComponentPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/GenericComponentPass.cs index cef0a2dad4..b0d9d881c8 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/GenericComponentPass.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/GenericComponentPass.cs @@ -1,12 +1,11 @@ // 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 System.Linq; +using Microsoft.AspNetCore.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Intermediate; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -28,9 +27,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor visitor.Visit(documentNode); } - + private class Visitor : IntermediateNodeWalker, IExtensionIntermediateNodeVisitor { + // Incrementing ID for type inference method names + private int _id; + public void VisitExtension(ComponentExtensionNode node) { if (node.Component.IsGenericTypedComponent()) @@ -45,20 +47,112 @@ namespace Microsoft.AspNetCore.Blazor.Razor private void Process(ComponentExtensionNode node) { // First collect all of the information we have about each type parameter + // + // Listing all type parameters that exist var bindings = new Dictionary(); foreach (var attribute in node.Component.GetTypeParameters()) { bindings.Add(attribute.Name, new GenericTypeNameRewriter.Binding() { Attribute = attribute, }); } + // Listing all type arguments that have been specified. + var hasTypeArgumentSpecified = false; foreach (var typeArgumentNode in node.TypeArguments) { + hasTypeArgumentSpecified = true; + var binding = bindings[typeArgumentNode.TypeParameterName]; binding.Node = typeArgumentNode; binding.Content = GetContent(typeArgumentNode); } - // Right now we don't have type inference, so all type arguments are required. + if (hasTypeArgumentSpecified) + { + // OK this means that the developer has specified at least one type parameter. + // Either they specified everything and its OK to rewrite, or its an error. + if (ValidateTypeArguments(node, bindings)) + { + RewriteTypeNames(new GenericTypeNameRewriter(bindings), node); + } + + return; + } + + // OK if we get here that means that no type arguments were specified, so we will try to infer + // the type. + // + // The actual inference is done by the C# compiler, we just emit an a method that represents the + // use of this component. + + // Since we're generating code in a different namespace, we need to 'global qualify' all of the types + // to avoid clashes with our generated code. + RewriteTypeNames(new GlobalQualifiedTypeNameRewriter(bindings.Keys), node); + + // + // We need to verify that an argument was provided that 'covers' each type parameter. + // + // For example, consider a repeater where the generic type is the 'item' type, but the developer has + // not set the items. We won't be able to do type inference on this and so it will just be nonesense. + var attributes = node.Attributes.Select(a => a.BoundAttribute).Concat(node.ChildContents.Select(c => c.BoundAttribute)); + foreach (var attribute in attributes) + { + if (attribute == null) + { + // Will be null for attributes set on the component that don't match a declared component parameter + continue; + } + + // Now we need to parse the type name and extract the generic parameters. + // + // Two cases; + // 1. name is a simple identifier like TItem + // 2. name contains type parameters like Dictionary + if (!attribute.IsGenericTypedProperty()) + { + continue; + } + + var parsed = SyntaxFactory.ParseTypeName(attribute.TypeName); + if (parsed is IdentifierNameSyntax identifier) + { + bindings.Remove(identifier.ToString()); + } + else + { + var typeParameters = parsed.DescendantNodesAndSelf().OfType().SelectMany(arg => arg.Arguments); + foreach (var typeParameter in typeParameters) + { + bindings.Remove(typeParameter.ToString()); + } + } + } + + // If any bindings remain then this means we would never be able to infer the arguments of this + // component usage because the user hasn't set properties that include all of the types. + if (bindings.Count > 0) + { + // However we still want to generate 'type inference' code because we want the errors to be as + // helpful as possible. So let's substitute 'object' for all of those type parameters, and add + // an error. + RewriteTypeNames(new GenericTypeNameRewriter(bindings), node); + + node.Diagnostics.Add(BlazorDiagnosticFactory.Create_GenericComponentTypeInferenceUnderspecified(node.Source, node, node.Component.GetTypeParameters())); + } + + // Next we need to generate a type inference 'method' node. This repesents a method that we will codegen that + // contains all of the operations on the render tree building. Calling a method to operate on the builder + // will allow the C# compiler to perform type inference. + var documentNode = (DocumentIntermediateNode)Ancestors[Ancestors.Count - 1]; + CreateTypeInferenceMethod(documentNode, node, bindings); + } + + private string GetContent(ComponentTypeArgumentExtensionNode node) + { + return string.Join(string.Empty, node.FindDescendantNodes().Where(t => t.IsCSharp).Select(t => t.Content)); + } + + private static bool ValidateTypeArguments(ComponentExtensionNode node, Dictionary bindings) + { var missing = new List(); foreach (var binding in bindings) { @@ -74,10 +168,14 @@ namespace Microsoft.AspNetCore.Blazor.Razor // to incorrect codegen without the types. Our errors message will pretty clearly indicate // what to do, whereas the other errors might be confusing. node.Diagnostics.Add(BlazorDiagnosticFactory.Create_GenericComponentMissingTypeArgument(node.Source, node, missing)); + return false; } - var rewriter = new GenericTypeNameRewriter(bindings); + return true; + } + private void RewriteTypeNames(CSharpSyntaxRewriter rewriter, ComponentExtensionNode node) + { // Rewrite the component type name node.TypeName = RewriteTypeName(rewriter, node.TypeName); @@ -89,6 +187,28 @@ namespace Microsoft.AspNetCore.Blazor.Razor // the known types. attribute.TypeName = RewriteTypeName(rewriter, attribute.TypeName); } + else if (attribute.TypeName == null && (attribute.BoundAttribute?.IsDelegateProperty() ?? false)) + { + // This is a weakly typed delegate, treat it as Action + attribute.TypeName = "System.Action"; + } + else if (attribute.TypeName == null) + { + // This is a weakly typed attribute, treat it as System.Object + attribute.TypeName = "System.Object"; + } + } + + foreach (var capture in node.Captures) + { + if (capture.IsComponentCapture && capture.ComponentCaptureTypeName != null) + { + capture.ComponentCaptureTypeName = RewriteTypeName(rewriter, capture.ComponentCaptureTypeName); + } + else if (capture.IsComponentCapture) + { + capture.ComponentCaptureTypeName = "System.Object"; + } } foreach (var childContent in node.ChildContents) @@ -99,19 +219,86 @@ namespace Microsoft.AspNetCore.Blazor.Razor // the known types. childContent.TypeName = RewriteTypeName(rewriter, childContent.TypeName); } + else if (childContent.IsParameterized) + { + // This is a weakly typed parameterized child content, treat it as RenderFragment + childContent.TypeName = BlazorApi.RenderFragment.FullTypeName + ""; + } + else + { + // This is a weakly typed child content, treat it as RenderFragment + childContent.TypeName = BlazorApi.RenderFragment.FullTypeName; + } } } - private string RewriteTypeName(GenericTypeNameRewriter rewriter, string typeName) + private string RewriteTypeName(CSharpSyntaxRewriter rewriter, string typeName) { var parsed = SyntaxFactory.ParseTypeName(typeName); var rewritten = (TypeSyntax)rewriter.Visit(parsed); return rewritten.ToFullString(); } - private string GetContent(ComponentTypeArgumentExtensionNode node) + private void CreateTypeInferenceMethod( + DocumentIntermediateNode documentNode, + ComponentExtensionNode node, + Dictionary bindings) { - return string.Join(string.Empty, node.FindDescendantNodes().Where(t => t.IsCSharp).Select(t => t.Content)); + var @namespace = documentNode.FindPrimaryNamespace().Content; + @namespace = string.IsNullOrEmpty(@namespace) ? "__Blazor" : "__Blazor." + @namespace; + @namespace += "." + documentNode.FindPrimaryClass().ClassName; + + var typeInferenceNode = new ComponentTypeInferenceMethodIntermediateNode() + { + Bindings = bindings, + Component = node, + + // Method name is generated and guaraneteed not to collide, since it's unique for each + // component call site. + MethodName = $"Create{node.TagName}_{_id++}", + FullTypeName = @namespace + ".TypeInference", + }; + + node.TypeInferenceNode = typeInferenceNode; + + // Now we need to insert the type inference node into the tree. + var namespaceNode = documentNode.Children + .OfType() + .Where(n => n.Annotations.Contains(new KeyValuePair(BlazorMetadata.Component.GenericTypedKey, bool.TrueString))) + .FirstOrDefault(); + if (namespaceNode == null) + { + namespaceNode = new NamespaceDeclarationIntermediateNode() + { + Annotations = + { + { BlazorMetadata.Component.GenericTypedKey, bool.TrueString }, + }, + Content = @namespace, + }; + + documentNode.Children.Add(namespaceNode); + } + + var classNode = namespaceNode.Children + .OfType() + .Where(n => n.ClassName == "TypeInference") + .FirstOrDefault(); + if (classNode == null) + { + classNode = new ClassDeclarationIntermediateNode() + { + ClassName = "TypeInference", + Modifiers = + { + "internal", + "static", + }, + }; + namespaceNode.Children.Add(classNode); + } + + classNode.Children.Add(typeInferenceNode); } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/GlobalQualifiedTypeNameRewriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/GlobalQualifiedTypeNameRewriter.cs new file mode 100644 index 0000000000..a5ca68c8d9 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/GlobalQualifiedTypeNameRewriter.cs @@ -0,0 +1,62 @@ +// 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.Collections.Generic; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Microsoft.AspNetCore.Blazor.Razor +{ + // Rewrites type names to use the 'global::' prefix for identifiers. + // + // This is useful when we're generating code in a different namespace than + // what the user code lives in. When we synthesize a namespace it's easy to have + // clashes. + internal class GlobalQualifiedTypeNameRewriter : CSharpSyntaxRewriter + { + // List of names to ignore. + // + // NOTE: this is the list of type parameters defined on the component. + private readonly HashSet _ignore; + + public GlobalQualifiedTypeNameRewriter(IEnumerable ignore) + { + _ignore = new HashSet(ignore); + } + + public override SyntaxNode Visit(SyntaxNode node) + { + return base.Visit(node); + } + + public override SyntaxNode VisitQualifiedName(QualifiedNameSyntax node) + { + if (node.Parent is QualifiedNameSyntax) + { + return base.VisitQualifiedName(node); + } + + // Need to rewrite postorder so we can rewrite the names of generic type arguments. + node = (QualifiedNameSyntax)base.VisitQualifiedName(node); + + // Rewriting these is complicated, best to just tostring and parse again. + return SyntaxFactory.ParseTypeName("global::" + node.ToString()); + } + + public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node) + { + if (_ignore.Contains(node.ToString())) + { + return node; + } + + if (node.Parent != null) + { + return node; + } + + return SyntaxFactory.AliasQualifiedName(SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)), node); + } + } +} diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/RefExtensionNode.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/RefExtensionNode.cs index e0904eaa5d..22a23ac9ea 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/RefExtensionNode.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/RefExtensionNode.cs @@ -1,6 +1,7 @@ -// 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.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using Microsoft.AspNetCore.Razor.Language.Intermediate; using System; @@ -9,14 +10,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor { internal class RefExtensionNode : ExtensionIntermediateNode { - public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; - - public IntermediateToken IdentifierToken { get; } - - public bool IsComponentCapture { get; } - - public string ComponentCaptureTypeName { get; } - public RefExtensionNode(IntermediateToken identifierToken) { IdentifierToken = identifierToken ?? throw new ArgumentNullException(nameof(identifierToken)); @@ -35,6 +28,16 @@ namespace Microsoft.AspNetCore.Blazor.Razor ComponentCaptureTypeName = componentCaptureTypeName; } + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; + + public IntermediateToken IdentifierToken { get; } + + public bool IsComponentCapture { get; } + + public string ComponentCaptureTypeName { get; set; } + + public string TypeName => $"global::System.Action<{(IsComponentCapture ? ComponentCaptureTypeName : "global::" + BlazorApi.ElementRef.FullTypeName)}>"; + public override void Accept(IntermediateNodeVisitor visitor) { if (visitor == null) diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs index df758a606a..db015b9317 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs @@ -1,11 +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 Microsoft.AspNetCore.Blazor.Shared; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Language.CodeGeneration; using System; using System.Collections.Generic; +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; namespace Microsoft.AspNetCore.Blazor.Razor { @@ -21,27 +19,18 @@ namespace Microsoft.AspNetCore.Blazor.Razor public string BuilderVarName { get; private set; } = "builder"; - public void OpenElementScope(string tagName) - { - _stack.Push(new ScopeEntry(tagName, ScopeKind.Element)); - } - - public void OpenComponentScope(CodeRenderingContext context, string name, string type, string parameterName) + public void OpenComponentScope(CodeRenderingContext context, string name, string parameterName) { 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) => { ... })); + // ((__builder) => { ... }) // OR - // builder.AddAttribute(0, "{name}", ({type})((context) => (__builder) => { ... })); - - context.CodeWriter.Write($"({type})("); + // ((context) => (__builder) => { ... }) if (parameterName != null) { @@ -59,26 +48,13 @@ namespace Microsoft.AspNetCore.Blazor.Razor // Templates always get a lambda scope, because they are defined as a lambda. OffsetBuilderVarNumber(1); currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName); - } public void CloseScope(CodeRenderingContext context) { var currentScope = _stack.Pop(); - - // When closing the scope for a component with children, it's time to close the lambda - if (currentScope.LambdaScope != null) - { - currentScope.LambdaScope.Dispose(); - - if (currentScope.Kind == ScopeKind.Component) - { - context.CodeWriter.Write(")"); - context.CodeWriter.WriteEndMethodInvocation(); - } - - OffsetBuilderVarNumber(-1); - } + currentScope.LambdaScope.Dispose(); + OffsetBuilderVarNumber(-1); } private void OffsetBuilderVarNumber(int delta) @@ -108,7 +84,6 @@ namespace Microsoft.AspNetCore.Blazor.Razor private enum ScopeKind { - Element, Component, Template, } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/CodeGenerationTestBase.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/CodeGenerationTestBase.cs index e820360060..66471b5370 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/CodeGenerationTestBase.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/CodeGenerationTestBase.cs @@ -1258,6 +1258,116 @@ namespace Test CompileToAssembly(generated); } + [Fact] + public void ChildComponent_Generic_TypeInference() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_Generic_TypeInference_Multiple() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_GenericWeaklyTypedAttribute() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_GenericWeaklyTypedAttribute_TypeInference() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [Fact] public void ChildComponent_GenericBind() { @@ -1271,10 +1381,10 @@ namespace Test public class MyComponent : BlazorComponent { [Parameter] - TItem Value { get; set; } + TItem Item { get; set; } [Parameter] - Action ValueChanged { get; set; } + Action ItemChanged { get; set; } } } ")); @@ -1293,6 +1403,102 @@ namespace Test CompileToAssembly(generated); } + [Fact] + public void ChildComponent_GenericBind_TypeInference() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] + TItem Item { get; set; } + + [Parameter] + Action ItemChanged { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + string Value; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_GenericBindWeaklyTyped() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + string Value; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void ChildComponent_GenericBindWeaklyTyped_TypeInference() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem Value { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +@functions { + string Value; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [Fact] public void ChildComponent_GenericChildContent() { @@ -1325,6 +1531,38 @@ namespace Test CompileToAssembly(generated); } + [Fact] + public void ChildComponent_GenericChildContent_TypeInference() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem Item { get; set; } + + [Parameter] RenderFragment ChildContent { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + +
@context.ToLower()
+
"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [Fact] public void ChildComponent_MultipleGenerics() { @@ -1367,6 +1605,119 @@ namespace Test CompileToAssembly(generated); } + [Fact] + public void ChildComponent_MultipleGenerics_TypeInference() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using System.Collections.Generic; +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem1 Item { get; set; } + + [Parameter] List Items { get; set; } + + [Parameter] RenderFragment ChildContent { get; set; } + + [Parameter] RenderFragment AnotherChildContent { get; set; } + + public class Context + { + public TItem2 Item { get; set; } + } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly +())> +
@context.ToLower()
+ + @System.Math.Max(0, item.Item); + +
"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void GenericComponent_WithComponentRef() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +@functions { + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void GenericComponent_WithComponentRef_TypeInference() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] TItem Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper *, TestAssembly + + +@functions { + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +} +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + #endregion #region Ref diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/GenericComponentRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/GenericComponentRazorIntegrationTest.cs index addde66eaa..f52c7c2e5f 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/GenericComponentRazorIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/GenericComponentRazorIntegrationTest.cs @@ -1,10 +1,12 @@ // 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.Blazor.Components; using Microsoft.AspNetCore.Blazor.Razor; using Microsoft.AspNetCore.Blazor.RenderTree; using Microsoft.AspNetCore.Blazor.Test.Helpers; using Microsoft.CodeAnalysis.CSharp; +using System; using System.Collections.Generic; using System.Linq; using Xunit; @@ -28,7 +30,14 @@ namespace Test var items = (IReadOnlyList)Items ?? Array.Empty(); for (var i = 0; i < items.Count; i++) { - builder.AddContent(i, ChildContent, new Context() { Index = i, Item = items[i], }); + if (ChildContent == null) + { + builder.AddContent(i, Items[i]); + } + else + { + builder.AddContent(i, ChildContent, new Context() { Index = i, Item = items[i], }); + } } } @@ -76,6 +85,66 @@ namespace Test internal override bool UseTwoPhaseCompilation => true; + [Fact] + public void Render_GenericComponent_WithoutChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(GenericContextComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +() { 1, 2, })"" />"); + + // Act + var frames = GetRenderTree(component); + + // Assert + var genericComponentType = component.GetType().Assembly.DefinedTypes + .Where(t => t.Name == "GenericContext`1") + .Single() + .MakeGenericType(typeof(int)); + + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, genericComponentType.FullName, 2, 0), + frame => AssertFrame.Attribute(frame, "Items", typeof(List), 1), + frame => AssertFrame.Text(frame, "1", 0), + frame => AssertFrame.Text(frame, "2", 1)); + } + + [Fact] + public void Render_GenericComponent_WithRef() + { + // Arrange + AdditionalSyntaxTrees.Add(GenericContextComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +() { 1, 2, })"" ref=""_my"" /> + +@functions { + GenericContext _my; + void Foo() { GC.KeepAlive(_my); } +}"); + + // Act + var frames = GetRenderTree(component); + + // Assert + var genericComponentType = component.GetType().Assembly.DefinedTypes + .Where(t => t.Name == "GenericContext`1") + .Single() + .MakeGenericType(typeof(int)); + + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, genericComponentType.FullName, 3, 0), + frame => AssertFrame.Attribute(frame, "Items", typeof(List), 1), + frame => AssertFrame.ComponentReferenceCapture(frame, 2), + frame => AssertFrame.Text(frame, "1", 0), + frame => AssertFrame.Text(frame, "2", 1)); + } + [Fact] public void Render_GenericComponent_WithChildContent() { @@ -112,6 +181,105 @@ namespace Test frame => AssertFrame.Whitespace(frame, 6)); } + [Fact] + public void Render_GenericComponent_TypeInference_WithRef() + { + // Arrange + AdditionalSyntaxTrees.Add(GenericContextComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +() { 1, 2, })"" ref=""_my"" /> + +@functions { + GenericContext _my; + void Foo() { GC.KeepAlive(_my); } +}"); + + // Act + var frames = GetRenderTree(component); + + // Assert + var genericComponentType = component.GetType().Assembly.DefinedTypes + .Where(t => t.Name == "GenericContext`1") + .Single() + .MakeGenericType(typeof(int)); + + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, genericComponentType.FullName, 3, 0), + frame => AssertFrame.Attribute(frame, "Items", typeof(List), 1), + frame => AssertFrame.ComponentReferenceCapture(frame, 2), + frame => AssertFrame.Text(frame, "1", 0), + frame => AssertFrame.Text(frame, "2", 1)); + } + + [Fact] + public void Render_GenericComponent_TypeInference_WithRef_Recursive() + { + // Arrange + AdditionalSyntaxTrees.Add(GenericContextComponent); + + var assembly = CompileToAssembly("Test.cshtml", @" +@addTagHelper *, TestAssembly +@typeparam TItem + + +@functions { + [Parameter] List MyItems { get; set; } + GenericContext _my; + void Foo() { GC.KeepAlive(_my); } +}"); + + var componentType = assembly.Assembly.DefinedTypes + .Where(t => t.Name == "Test`1") + .Single() + .MakeGenericType(typeof(int)); + var component = (IComponent)Activator.CreateInstance(componentType); + + // Act + var frames = GetRenderTree(component); + + // Assert + var genericComponentType = assembly.Assembly.DefinedTypes + .Where(t => t.Name == "GenericContext`1") + .Single() + .MakeGenericType(typeof(int)); + + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, genericComponentType.FullName, 3, 0), + frame => AssertFrame.Attribute(frame, "Items", 1), + frame => AssertFrame.ComponentReferenceCapture(frame, 2)); + } + + [Fact] + public void Render_GenericComponent_TypeInference_WithoutChildContent() + { + // Arrange + AdditionalSyntaxTrees.Add(GenericContextComponent); + + var component = CompileToComponent(@" +@addTagHelper *, TestAssembly +() { 1, 2, })"" />"); + + // Act + var frames = GetRenderTree(component); + + // Assert + var genericComponentType = component.GetType().Assembly.DefinedTypes + .Where(t => t.Name == "GenericContext`1") + .Single() + .MakeGenericType(typeof(int)); + + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, genericComponentType.FullName, 2, 0), + frame => AssertFrame.Attribute(frame, "Items", typeof(List), 1), + frame => AssertFrame.Text(frame, "1", 0), + frame => AssertFrame.Text(frame, "2", 1)); + } + [Fact] public void Render_GenericComponent_MultipleParameters_WithChildContent() { @@ -161,9 +329,10 @@ namespace Test // Assert var diagnostic = Assert.Single(generated.Diagnostics); - Assert.Same(BlazorDiagnosticFactory.GenericComponentMissingTypeArgument.Id, diagnostic.Id); + Assert.Same(BlazorDiagnosticFactory.GenericComponentTypeInferenceUnderspecified.Id, diagnostic.Id); Assert.Equal( - "The component 'GenericContext' is missing required type arguments. Specify the missing types using the attributes: 'TItem'.", + "The type of component 'GenericContext' cannot be inferred based on the values provided. Consider " + + "specifying the type arguments directly using the following attributes: 'TItem'.", diagnostic.GetMessage()); } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/IntermediateNodeWriter.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/IntermediateNodeWriter.cs index b3496ca6cc..a4d56fa40d 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/IntermediateNodeWriter.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/Razor/IntermediateNodeWriter.cs @@ -20,6 +20,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor, + IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor, IExtensionIntermediateNodeVisitor { @@ -297,6 +298,11 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests WriteContentNode(node, node.TypeParameterName); } + void IExtensionIntermediateNodeVisitor.VisitExtension(ComponentTypeInferenceMethodIntermediateNode node) + { + WriteContentNode(node, node.FullTypeName, node.MethodName); + } + void IExtensionIntermediateNodeVisitor.VisitExtension(RouteAttributeExtensionNode node) { WriteContentNode(node, node.Template); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.codegen.cs index 68a6c9d5cc..731424d4b4 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.codegen.cs @@ -33,14 +33,15 @@ global::System.Object __typeHelper = "*, TestAssembly"; #line default #line hidden ); - __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" Value #line default #line hidden - ); - __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value); + )); + __o = new System.Action( + __value => Value = __value); builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { } )); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.ir.txt index 716a6113c3..d3374ea9b2 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.ir.txt @@ -25,14 +25,14 @@ Document - ComponentExtensionNode - (31:1,0 [43] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent ComponentTypeArgumentExtensionNode - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - TItem IntermediateToken - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - string - ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - + ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item CSharpExpression - IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( IntermediateToken - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Value IntermediateToken - - CSharp - ) - ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - + ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - ItemChanged CSharpExpression - - IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value) + IntermediateToken - - CSharp - __value => Value = __value HtmlContent - (74:1,43 [2] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (74:1,43 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n CSharpCode - (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.mappings.txt index 24f508cdda..7d8a6b0341 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.mappings.txt @@ -10,14 +10,14 @@ Generated Location: (1083:30,19 [6] ) Source Location: (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) |Value| -Generated Location: (1305:37,36 [5] ) +Generated Location: (1377:37,36 [5] ) |Value| Source Location: (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) | string Value; | -Generated Location: (1740:49,12 [21] ) +Generated Location: (1779:50,12 [21] ) | string Value; | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.codegen.cs new file mode 100644 index 0000000000..68a6c9d5cc --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.codegen.cs @@ -0,0 +1,57 @@ +// +#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); + __o = typeof( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + string + +#line default +#line hidden + ); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + Value + +#line default +#line hidden + ); + __o = Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + string Value; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.ir.txt new file mode 100644 index 0000000000..716a6113c3 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/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 [43] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentTypeArgumentExtensionNode - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - TItem + IntermediateToken - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - string + ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Value + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value) + HtmlContent - (74:1,43 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (74:1,43 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string Value;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.mappings.txt new file mode 100644 index 0000000000..24f508cdda --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.mappings.txt @@ -0,0 +1,24 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) +|string| +Generated Location: (1083:30,19 [6] ) +|string| + +Source Location: (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) +|Value| +Generated Location: (1305:37,36 [5] ) +|Value| + +Source Location: (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) +| + string Value; +| +Generated Location: (1740:49,12 [21] ) +| + string Value; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..2b1ad577e0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,67 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + 18 + +#line default +#line hidden + , -1, Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + Value + +#line default +#line hidden + ), -1, Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value)); + } + #pragma warning restore 1998 +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + string Value; + +#line default +#line hidden + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, System.Object __arg1, int __seq2, System.Object __arg2) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Value", __arg0); + builder.AddAttribute(__seq1, "Item", __arg1); + builder.AddAttribute(__seq2, "ItemChanged", __arg2); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..eed79cdf1a --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/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 [42] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (66:1,35 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Value - Value + CSharpExpression - (67:1,36 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (68:1,37 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 18 + ComponentAttributeExtensionNode - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Value + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value) + HtmlContent - (73:1,42 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (73:1,42 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (87:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (87:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string Value;\n + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..2003c3d8a1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.mappings.txt @@ -0,0 +1,24 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (68:1,37 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|18| +Generated Location: (1167:30,37 [2] ) +|18| + +Source Location: (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) +|Value| +Generated Location: (1356:36,23 [5] ) +|Value| + +Source Location: (87:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) +| + string Value; +| +Generated Location: (1630:44,12 [21] ) +| + string Value; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..45133e3c61 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,61 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1, Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + Value + +#line default +#line hidden + ), -1, + __value => Value = __value); + } + #pragma warning restore 1998 +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + string Value; + +#line default +#line hidden + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, global::System.Action __arg1) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddAttribute(__seq1, "ItemChanged", __arg1); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..574589d5a2 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.ir.txt @@ -0,0 +1,40 @@ +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 [30] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Value + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - ItemChanged + CSharpExpression - + IntermediateToken - - CSharp - __value => Value = __value + HtmlContent - (61:1,30 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (61:1,30 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (75:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (75:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string Value;\n + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..811a36f0ba --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.mappings.txt @@ -0,0 +1,19 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) +|Value| +Generated Location: (1213:30,23 [5] ) +|Value| + +Source Location: (75:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) +| + string Value; +| +Generated Location: (1426:39,12 [21] ) +| + string Value; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..7e11a1c1ae --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,61 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + "hi" + +#line default +#line hidden + , -1, (context) => (builder2) => { +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.ToLower(); + +#line default +#line hidden + } + ); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, global::Microsoft.AspNetCore.Blazor.RenderFragment __arg1) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddAttribute(__seq1, "ChildContent", __arg1); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..4ad0e2263a --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/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 [77] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (59:1,28 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (59:1,28 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + HtmlElement - (63:2,2 [29] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (69:2,8 [17] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (69:2,8 [17] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLower() + HtmlContent - (92:2,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (92:2,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..f87ad7df1c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.mappings.txt @@ -0,0 +1,15 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) +|"hi"| +Generated Location: (1151:30,21 [4] ) +|"hi"| + +Source Location: (69:2,8 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|context.ToLower()| +Generated Location: (1295:36,8 [17] ) +|context.ToLower()| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.codegen.cs new file mode 100644 index 0000000000..4eb9857737 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.codegen.cs @@ -0,0 +1,57 @@ +// +#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); + __o = typeof( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + string + +#line default +#line hidden + ); + __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + "hi" + +#line default +#line hidden + ); + __o = +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + 17 + +#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/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.ir.txt new file mode 100644 index 0000000000..2cd9694d0c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.ir.txt @@ -0,0 +1,33 @@ +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 [56] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentTypeArgumentExtensionNode - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - TItem + IntermediateToken - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - string + ComponentAttributeExtensionNode - (63:1,32 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (64:1,33 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (65:1,34 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + ComponentAttributeExtensionNode - - Other - + CSharpExpression - (79:1,48 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (81:1,50 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 17 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.mappings.txt new file mode 100644 index 0000000000..a1b8e804ac --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) +|string| +Generated Location: (1083:30,19 [6] ) +|string| + +Source Location: (65:1,34 [4] x:\dir\subdir\Test\TestComponent.cshtml) +|"hi"| +Generated Location: (1315:37,34 [4] ) +|"hi"| + +Source Location: (81:1,50 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|17| +Generated Location: (1489:44,50 [2] ) +|17| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..f361f20baf --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + "hi" + +#line default +#line hidden + , -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + 17 + +#line default +#line hidden + ); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, System.Object __arg1) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddAttribute(__seq1, "Other", __arg1); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..405e24e50c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.ir.txt @@ -0,0 +1,34 @@ +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 [43] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + ComponentAttributeExtensionNode - - Other - + CSharpExpression - (66:1,35 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (68:1,37 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 17 + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..4c5632823c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.mappings.txt @@ -0,0 +1,15 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) +|"hi"| +Generated Location: (1151:30,21 [4] ) +|"hi"| + +Source Location: (68:1,37 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|17| +Generated Location: (1296:36,37 [2] ) +|17| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..1d555832f7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,53 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + "hi" + +#line default +#line hidden + ); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..7c43878069 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/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 [29] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..08fbfce21e --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference/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: (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) +|"hi"| +Generated Location: (1151:30,21 [4] ) +|"hi"| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.codegen.cs new file mode 100644 index 0000000000..5e55330f4c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.codegen.cs @@ -0,0 +1,79 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + "hi" + +#line default +#line hidden + ); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_1(builder, -1, -1, +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + "how are you?" + +#line default +#line hidden + ); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_2(builder, -1, -1, +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + "bye!" + +#line default +#line hidden + ); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.CloseComponent(); + } + public static void CreateMyComponent_1(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.CloseComponent(); + } + public static void CreateMyComponent_2(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.ir.txt new file mode 100644 index 0000000000..7b1d927756 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.ir.txt @@ -0,0 +1,45 @@ +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 [29] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + HtmlContent - (60:1,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (60:1,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (62:2,0 [39] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (81:2,19 [17] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (82:2,20 [16] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (83:2,21 [14] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "how are you?" + HtmlContent - (101:2,39 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (101:2,39 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (103:3,0 [31] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (122:3,19 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (123:3,20 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (124:3,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "bye!" + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_1 + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_2 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.mappings.txt new file mode 100644 index 0000000000..bf76f5458d --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) +|"hi"| +Generated Location: (1151:30,21 [4] ) +|"hi"| + +Source Location: (83:2,21 [14] x:\dir\subdir\Test\TestComponent.cshtml) +|"how are you?"| +Generated Location: (1369:37,21 [14] ) +|"how are you?"| + +Source Location: (124:3,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) +|"bye!"| +Generated Location: (1597:44,21 [6] ) +|"bye!"| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..a83b0b0f09 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,76 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + "hi" + +#line default +#line hidden + , -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + new List() + +#line default +#line hidden + , -1, (context) => (builder2) => { +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.ToLower(); + +#line default +#line hidden + } + , -1, (item) => (builder2) => { +#line 5 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = System.Math.Max(0, item.Item); + +#line default +#line hidden + } + ); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem1 __arg0, int __seq1, global::System.Collections.Generic.List __arg1, int __seq2, global::Microsoft.AspNetCore.Blazor.RenderFragment __arg2, int __seq3, global::Microsoft.AspNetCore.Blazor.RenderFragment.Context> __arg3) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddAttribute(__seq1, "Items", __arg1); + builder.AddAttribute(__seq2, "ChildContent", __arg2); + builder.AddAttribute(__seq3, "AnotherChildContent", __arg3); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..ae43425ed4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.ir.txt @@ -0,0 +1,45 @@ +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 [229] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentChildContent - (89:2,2 [58] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + HtmlElement - (103:2,16 [29] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (109:2,22 [17] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (109:2,22 [17] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLower() + ComponentChildContent - (149:3,0 [95] x:\dir\subdir\Test\TestComponent.cshtml) - AnotherChildContent + HtmlContent - (185:3,36 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (185:3,36 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpExpression - (190:4,3 [29] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (190:4,3 [29] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - System.Math.Max(0, item.Item) + HtmlContent - (219:4,32 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (219:4,32 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - ;\n + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + ComponentAttributeExtensionNode - (65:1,34 [19] x:\dir\subdir\Test\TestComponent.cshtml) - Items - Items + CSharpExpression - (66:1,35 [18] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (67:1,36 [16] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new List() + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..7303b56d69 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/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: (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) +|"hi"| +Generated Location: (1151:30,21 [4] ) +|"hi"| + +Source Location: (67:1,36 [16] x:\dir\subdir\Test\TestComponent.cshtml) +|new List()| +Generated Location: (1295:36,36 [16] ) +|new List()| + +Source Location: (109:2,22 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|context.ToLower()| +Generated Location: (1465:42,22 [17] ) +|context.ToLower()| + +Source Location: (190:4,3 [29] x:\dir\subdir\Test\TestComponent.cshtml) +|System.Math.Max(0, item.Item)| +Generated Location: (1633:49,6 [29] ) +|System.Math.Max(0, item.Item)| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.codegen.cs index d8aec62c7a..aa5576e830 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithChildContent/TestComponent.codegen.cs @@ -26,6 +26,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); + __o = ""; builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { } )); 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 index 781ebf72c9..4839a7dc97 100644 --- 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 @@ -26,6 +26,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); + __o = ""; builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((context) => (builder2) => { #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" __o = context.ToLowerInvariant(); 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 index 902f1572d2..a9d74640da 100644 --- 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 @@ -5,6 +5,6 @@ Generated Location: (559:16,38 [15] ) Source Location: (85:1,54 [26] x:\dir\subdir\Test\TestComponent.cshtml) |context.ToLowerInvariant()| -Generated Location: (1234:30,54 [26] ) +Generated Location: (1257:31,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 index 1b1a8b108c..6e6d1eeb9f 100644 --- 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 @@ -26,6 +26,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); + __o = ""; builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((item) => (builder2) => { #line 4 "x:\dir\subdir\Test\TestComponent.cshtml" __o = item.ToLowerInvariant(); 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 index 585184e8bb..611fa5c8c0 100644 --- 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 @@ -5,6 +5,6 @@ Generated Location: (559:16,38 [15] ) Source Location: (124:3,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) |item.ToLowerInvariant()| -Generated Location: (1209:30,32 [23] ) +Generated Location: (1232:31,32 [23] ) |item.ToLowerInvariant()| diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithNonPropertyAttributes/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithNonPropertyAttributes/TestComponent.codegen.cs index 0ee60d4afc..2b54e070d1 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithNonPropertyAttributes/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithNonPropertyAttributes/TestComponent.codegen.cs @@ -26,6 +26,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); + __o = ""; __o = #line 2 "x:\dir\subdir\Test\TestComponent.cshtml" 43.ToString() diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithNonPropertyAttributes/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithNonPropertyAttributes/TestComponent.mappings.txt index d4d374fbbe..dc2183fe16 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithNonPropertyAttributes/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithNonPropertyAttributes/TestComponent.mappings.txt @@ -5,6 +5,6 @@ Generated Location: (559:16,38 [15] ) Source Location: (86:1,55 [13] x:\dir\subdir\Test\TestComponent.cshtml) |43.ToString()| -Generated Location: (1112:30,55 [13] ) +Generated Location: (1135:31,55 [13] ) |43.ToString()| diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs index ef017e32b0..785d034906 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.codegen.cs @@ -40,6 +40,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; #line default #line hidden ); + __o = ""; __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( #line 6 "x:\dir\subdir\Test\TestComponent.cshtml" new SomeType() diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.mappings.txt index c5335f3026..3ac58aa15e 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/ChildComponent_WithParameters/TestComponent.mappings.txt @@ -15,6 +15,6 @@ Generated Location: (1373:37,18 [4] ) Source Location: (146:5,20 [14] x:\dir\subdir\Test\TestComponent.cshtml) |new SomeType()| -Generated Location: (1596:44,20 [14] ) +Generated Location: (1619:45,20 [14] ) |new SomeType()| 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 8710dff3b6..164b0e5ebb 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 @@ -26,6 +26,8 @@ global::System.Object __typeHelper = "*, TestAssembly"; protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); + __o = ""; + __o = ""; builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { } )); 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 23bc888573..00f26500e7 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 @@ -5,7 +5,7 @@ Generated Location: (559:16,38 [15] ) Source Location: (70:1,39 [10] x:\dir\subdir\Test\TestComponent.cshtml) |myInstance| -Generated Location: (1223:32,39 [10] ) +Generated Location: (1269:34,39 [10] ) |myInstance| Source Location: (119:3,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) @@ -13,7 +13,7 @@ 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: (1407:39,12 [104] ) +Generated Location: (1453:41,12 [104] ) | 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 index 8e1d3edc04..dbbf2adf12 100644 --- 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 @@ -26,6 +26,7 @@ global::System.Object __typeHelper = "*, TestAssembly"; protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); + __o = ""; builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { } )); 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 index 49b2528ce4..8f0e86512f 100644 --- 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 @@ -5,7 +5,7 @@ Generated Location: (559:16,38 [15] ) Source Location: (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml) |myInstance| -Generated Location: (1202:32,18 [10] ) +Generated Location: (1225:33,18 [10] ) |myInstance| Source Location: (143:5,12 [104] x:\dir\subdir\Test\TestComponent.cshtml) @@ -13,7 +13,7 @@ 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] ) +Generated Location: (1409:40,12 [104] ) | private Test.MyComponent myInstance; public void Foo() { System.GC.KeepAlive(myInstance); } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.codegen.cs new file mode 100644 index 0000000000..4a10507370 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.codegen.cs @@ -0,0 +1,62 @@ +// +#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); + __o = typeof( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + int + +#line default +#line hidden + ); + __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + 3 + +#line default +#line hidden + ); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + _my = default(Test.MyComponent); + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.ir.txt new file mode 100644 index 0000000000..74f1d58a21 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.ir.txt @@ -0,0 +1,36 @@ +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 [44] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentTypeArgumentExtensionNode - (50:1,19 [3] x:\dir\subdir\Test\TestComponent.cshtml) - TItem + IntermediateToken - (50:1,19 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - int + ComponentAttributeExtensionNode - (60:1,29 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + IntermediateToken - (60:1,29 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 3 + RefExtensionNode - (68:1,37 [3] x:\dir\subdir\Test\TestComponent.cshtml) - _my - Test.MyComponent + HtmlContent - (75:1,44 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (75:1,44 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlContent - (182:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (182:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (91:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (91:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private MyComponent _my;\n public void Foo() { System.GC.KeepAlive(_my); }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.mappings.txt new file mode 100644 index 0000000000..e4deae0a79 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.mappings.txt @@ -0,0 +1,31 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (50:1,19 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|int| +Generated Location: (1083:30,19 [3] ) +|int| + +Source Location: (60:1,29 [1] x:\dir\subdir\Test\TestComponent.cshtml) +|3| +Generated Location: (1304:37,29 [1] ) +|3| + +Source Location: (68:1,37 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|_my| +Generated Location: (1589:46,37 [3] ) +|_my| + +Source Location: (91:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) +| + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +| +Generated Location: (1771:53,12 [90] ) +| + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..61cdaa1d08 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,68 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, -1, -1, +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + 3 + +#line default +#line hidden + , -1, (__value) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + _my = __value; + +#line default +#line hidden + } + ); + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } + +#line default +#line hidden + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, global::System.Action> __arg1) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddComponentReferenceCapture(__seq1, (__value) => { __arg1((global::Test.MyComponent)__value); }); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..a6918b6ca4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/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 [34] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (50:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + IntermediateToken - (50:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 3 + RefExtensionNode - (58:1,27 [3] x:\dir\subdir\Test\TestComponent.cshtml) - _my - global::Test.MyComponent + HtmlContent - (65:1,34 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (65:1,34 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlContent - (172:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (172:6,1 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (81:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (81:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private MyComponent _my;\n public void Foo() { System.GC.KeepAlive(_my); }\n + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..bfa3514785 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.mappings.txt @@ -0,0 +1,26 @@ +Source Location: (14:0,14 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|*, TestAssembly| +Generated Location: (559:16,38 [15] ) +|*, TestAssembly| + +Source Location: (50:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) +|3| +Generated Location: (1149:30,19 [1] ) +|3| + +Source Location: (58:1,27 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|_my| +Generated Location: (1295:36,27 [3] ) +|_my| + +Source Location: (81:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) +| + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +| +Generated Location: (1485:45,12 [90] ) +| + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_772/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_772/TestComponent.codegen.cs index e2e9bbc888..599e6cbfd4 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_772/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_772/TestComponent.codegen.cs @@ -31,6 +31,7 @@ global::System.Object __typeHelper = "/"; protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); + __o = ""; builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { } )); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_773/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_773/TestComponent.codegen.cs index e2e9bbc888..599e6cbfd4 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_773/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/Regression_773/TestComponent.codegen.cs @@ -31,6 +31,7 @@ global::System.Object __typeHelper = "/"; protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) { base.BuildRenderTree(builder); + __o = ""; builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { } )); diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.codegen.cs index b22e42adf1..eb1f645c1c 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.codegen.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.codegen.cs @@ -16,8 +16,8 @@ namespace Test { base.BuildRenderTree(builder); builder.OpenComponent>(0); - builder.AddAttribute(1, "Item", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(Value)); - builder.AddAttribute(2, "ItemChanged", Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value)); + builder.AddAttribute(1, "Item", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(Value))); + builder.AddAttribute(2, "ItemChanged", new System.Action(__value => Value = __value)); builder.CloseComponent(); } #pragma warning restore 1998 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.ir.txt index 7995a9493c..20b79b012f 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.ir.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.ir.txt @@ -13,13 +13,13 @@ Document - ComponentExtensionNode - (31:1,0 [43] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent ComponentTypeArgumentExtensionNode - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - TItem IntermediateToken - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - string - ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - + ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item CSharpExpression - IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( IntermediateToken - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Value IntermediateToken - - CSharp - ) - ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - + ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - ItemChanged CSharpExpression - - IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value) + IntermediateToken - - CSharp - __value => Value = __value CSharpCode - (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) IntermediateToken - (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string Value;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.mappings.txt index 28f6af134e..f8a0e9a0ea 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.mappings.txt +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind/TestComponent.mappings.txt @@ -2,7 +2,7 @@ Source Location: (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) | string Value; | -Generated Location: (1087:24,12 [21] ) +Generated Location: (1112:24,12 [21] ) | string Value; | diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.codegen.cs new file mode 100644 index 0000000000..b22e42adf1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/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, "Item", Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(Value)); + builder.AddAttribute(2, "ItemChanged", Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value)); + builder.CloseComponent(); + } + #pragma warning restore 1998 +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + string Value; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.ir.txt new file mode 100644 index 0000000000..7995a9493c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/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 [43] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentTypeArgumentExtensionNode - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - TItem + IntermediateToken - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - string + ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Value + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (67:1,36 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value) + CSharpCode - (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string Value;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.mappings.txt new file mode 100644 index 0000000000..28f6af134e --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped/TestComponent.mappings.txt @@ -0,0 +1,9 @@ +Source Location: (88:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) +| + string Value; +| +Generated Location: (1087:24,12 [21] ) +| + string Value; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..24aa779e7d --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, 18, 2, Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(Value), 3, Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value)); + } + #pragma warning restore 1998 +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + string Value; + +#line default +#line hidden + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, System.Object __arg1, int __seq2, System.Object __arg2) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Value", __arg0); + builder.AddAttribute(__seq1, "Item", __arg1); + builder.AddAttribute(__seq2, "ItemChanged", __arg2); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..8cfd2b7ca6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.ir.txt @@ -0,0 +1,29 @@ +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 [42] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (66:1,35 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Value - Value + CSharpExpression - (67:1,36 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (68:1,37 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 18 + ComponentAttributeExtensionNode - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Value + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.SetValueHandler(__value => Value = __value, Value) + CSharpCode - (87:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (87:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string Value;\n + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..c7d44ac836 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBindWeaklyTyped_TypeInference/TestComponent.mappings.txt @@ -0,0 +1,9 @@ +Source Location: (87:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) +| + string Value; +| +Generated Location: (985:21,12 [21] ) +| + string Value; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..20f30fcfc9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,43 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue(Value), 2, __value => Value = __value); + } + #pragma warning restore 1998 +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + string Value; + +#line default +#line hidden + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, global::System.Action __arg1) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddAttribute(__seq1, "ItemChanged", __arg1); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..f94e575c0a --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.ir.txt @@ -0,0 +1,26 @@ +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 [30] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - + IntermediateToken - - CSharp - Microsoft.AspNetCore.Blazor.Components.BindMethods.GetValue( + IntermediateToken - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Value + IntermediateToken - - CSharp - ) + ComponentAttributeExtensionNode - (54:1,23 [5] x:\dir\subdir\Test\TestComponent.cshtml) - ItemChanged - ItemChanged + CSharpExpression - + IntermediateToken - - CSharp - __value => Value = __value + CSharpCode - (75:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (75:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n string Value;\n + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..fca907e4e9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericBind_TypeInference/TestComponent.mappings.txt @@ -0,0 +1,9 @@ +Source Location: (75:2,12 [21] x:\dir\subdir\Test\TestComponent.cshtml) +| + string Value; +| +Generated Location: (903:21,12 [21] ) +| + string Value; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..01db5dbd90 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, "hi", 2, (context) => (builder2) => { + builder2.AddContent(3, "\n "); + builder2.OpenElement(4, "div"); + builder2.AddContent(5, context.ToLower()); + builder2.CloseElement(); + builder2.AddContent(6, "\n"); + } + ); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, global::Microsoft.AspNetCore.Blazor.RenderFragment __arg1) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddAttribute(__seq1, "ChildContent", __arg1); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..2f7909a5e7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericChildContent_TypeInference/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 [77] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentChildContent - - ChildContent + HtmlContent - (59:1,28 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (59:1,28 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + HtmlElement - (63:2,2 [29] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (69:2,8 [17] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (69:2,8 [17] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLower() + HtmlContent - (92:2,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (92:2,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.codegen.cs new file mode 100644 index 0000000000..8b0b949650 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.codegen.cs @@ -0,0 +1,26 @@ +// +#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, "Item", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck("hi")); + builder.AddAttribute(2, "Other", 17); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/TestComponent.ir.txt new file mode 100644 index 0000000000..bfd81b3a1c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute/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); + ComponentExtensionNode - (31:1,0 [56] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentTypeArgumentExtensionNode - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - TItem + IntermediateToken - (50:1,19 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - string + ComponentAttributeExtensionNode - (63:1,32 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (64:1,33 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (65:1,34 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + ComponentAttributeExtensionNode - - Other - + CSharpExpression - (79:1,48 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (81:1,50 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 17 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..5da257cdb0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/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 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, "hi", 2, 17); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, System.Object __arg1) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddAttribute(__seq1, "Other", __arg1); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..ac20b3a5ea --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_GenericWeaklyTypedAttribute_TypeInference/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); + ComponentExtensionNode - (31:1,0 [43] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + ComponentAttributeExtensionNode - - Other - + CSharpExpression - (66:1,35 [5] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (68:1,37 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 17 + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..d7503d5b6a --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference/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 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, "hi"); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..1e7686cc9f --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference/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 [29] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.codegen.cs new file mode 100644 index 0000000000..174f696217 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/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 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, "hi"); + builder.AddContent(2, "\n"); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_1(builder, 3, 4, "how are you?"); + builder.AddContent(5, "\n"); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_2(builder, 6, 7, "bye!"); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.CloseComponent(); + } + public static void CreateMyComponent_1(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.CloseComponent(); + } + public static void CreateMyComponent_2(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.ir.txt new file mode 100644 index 0000000000..c531fce7cb --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_Generic_TypeInference_Multiple/TestComponent.ir.txt @@ -0,0 +1,33 @@ +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 [29] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + HtmlContent - (60:1,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (60:1,29 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (62:2,0 [39] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (81:2,19 [17] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (82:2,20 [16] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (83:2,21 [14] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "how are you?" + HtmlContent - (101:2,39 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (101:2,39 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + ComponentExtensionNode - (103:3,0 [31] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (122:3,19 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (123:3,20 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (124:3,21 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "bye!" + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_1 + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_2 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..2967049d8a --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,49 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, "hi", 2, new List(), 3, (context) => (builder2) => { + builder2.OpenElement(4, "div"); + builder2.AddContent(5, context.ToLower()); + builder2.CloseElement(); + } + , 6, (item) => (builder2) => { + builder2.AddContent(7, "\n "); + builder2.AddContent(8, System.Math.Max(0, item.Item)); + builder2.AddContent(9, ";\n"); + } + ); + } + #pragma warning restore 1998 + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem1 __arg0, int __seq1, global::System.Collections.Generic.List __arg1, int __seq2, global::Microsoft.AspNetCore.Blazor.RenderFragment __arg2, int __seq3, global::Microsoft.AspNetCore.Blazor.RenderFragment.Context> __arg3) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddAttribute(__seq1, "Items", __arg1); + builder.AddAttribute(__seq2, "ChildContent", __arg2); + builder.AddAttribute(__seq3, "AnotherChildContent", __arg3); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..34c4bfbfe0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/ChildComponent_MultipleGenerics_TypeInference/TestComponent.ir.txt @@ -0,0 +1,33 @@ +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 [229] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentChildContent - (89:2,2 [58] x:\dir\subdir\Test\TestComponent.cshtml) - ChildContent + HtmlElement - (103:2,16 [29] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (109:2,22 [17] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (109:2,22 [17] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.ToLower() + ComponentChildContent - (149:3,0 [95] x:\dir\subdir\Test\TestComponent.cshtml) - AnotherChildContent + HtmlContent - (185:3,36 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (185:3,36 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpExpression - (190:4,3 [29] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (190:4,3 [29] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - System.Math.Max(0, item.Item) + HtmlContent - (219:4,32 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (219:4,32 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - ;\n + ComponentAttributeExtensionNode - (50:1,19 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + CSharpExpression - (51:1,20 [6] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (52:1,21 [4] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hi" + ComponentAttributeExtensionNode - (65:1,34 [19] x:\dir\subdir\Test\TestComponent.cshtml) - Items - Items + CSharpExpression - (66:1,35 [18] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (67:1,36 [16] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new List() + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.codegen.cs new file mode 100644 index 0000000000..5d73ee848c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/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); + builder.OpenComponent>(0); + builder.AddAttribute(1, "Item", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(3)); + builder.AddComponentReferenceCapture(2, (__value) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + _my = (Test.MyComponent)__value; + +#line default +#line hidden + } + ); + builder.CloseComponent(); + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.ir.txt new file mode 100644 index 0000000000..0030e2ca6e --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.ir.txt @@ -0,0 +1,20 @@ +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 [44] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentTypeArgumentExtensionNode - (50:1,19 [3] x:\dir\subdir\Test\TestComponent.cshtml) - TItem + IntermediateToken - (50:1,19 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - int + ComponentAttributeExtensionNode - (60:1,29 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + IntermediateToken - (60:1,29 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 3 + RefExtensionNode - (68:1,37 [3] x:\dir\subdir\Test\TestComponent.cshtml) - _my - Test.MyComponent + CSharpCode - (91:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (91:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private MyComponent _my;\n public void Foo() { System.GC.KeepAlive(_my); }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.mappings.txt new file mode 100644 index 0000000000..e28ff3739b --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef/TestComponent.mappings.txt @@ -0,0 +1,16 @@ +Source Location: (68:1,37 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|_my| +Generated Location: (938:21,37 [3] ) +|_my| + +Source Location: (91:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) +| + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +| +Generated Location: (1190:31,12 [90] ) +| + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.codegen.cs new file mode 100644 index 0000000000..9fd36357b9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.codegen.cs @@ -0,0 +1,51 @@ +// +#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); + __Blazor.Test.TestComponent.TypeInference.CreateMyComponent_0(builder, 0, 1, 3, 2, (__value) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + _my = __value; + +#line default +#line hidden + } + ); + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } + +#line default +#line hidden + } +} +namespace __Blazor.Test.TestComponent +{ + #line hidden + internal static class TypeInference + { + public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder, int seq, int __seq0, TItem __arg0, int __seq1, global::System.Action> __arg1) + { + builder.OpenComponent>(seq); + builder.AddAttribute(__seq0, "Item", __arg0); + builder.AddComponentReferenceCapture(__seq1, (__value) => { __arg1((global::Test.MyComponent)__value); }); + builder.CloseComponent(); + } + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.ir.txt new file mode 100644 index 0000000000..597ed9c7e7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/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); + ComponentExtensionNode - (31:1,0 [34] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - global::Test.MyComponent + ComponentAttributeExtensionNode - (50:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item + IntermediateToken - (50:1,19 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - 3 + RefExtensionNode - (58:1,27 [3] x:\dir\subdir\Test\TestComponent.cshtml) - _my - global::Test.MyComponent + CSharpCode - (81:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (81:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private MyComponent _my;\n public void Foo() { System.GC.KeepAlive(_my); }\n + NamespaceDeclaration - - __Blazor.Test.TestComponent + ClassDeclaration - - internal static - TypeInference - - + ComponentTypeInferenceMethod - - __Blazor.Test.TestComponent.TypeInference - CreateMyComponent_0 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.mappings.txt new file mode 100644 index 0000000000..d28faa79f4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/GenericComponent_WithComponentRef_TypeInference/TestComponent.mappings.txt @@ -0,0 +1,16 @@ +Source Location: (58:1,27 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|_my| +Generated Location: (790:19,27 [3] ) +|_my| + +Source Location: (81:3,12 [90] x:\dir\subdir\Test\TestComponent.cshtml) +| + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +| +Generated Location: (980:28,12 [90] ) +| + private MyComponent _my; + public void Foo() { System.GC.KeepAlive(_my); } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/GlobalQualifiedTypeNameRewriterTest.cs b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/GlobalQualifiedTypeNameRewriterTest.cs new file mode 100644 index 0000000000..38bad89663 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/GlobalQualifiedTypeNameRewriterTest.cs @@ -0,0 +1,38 @@ +// 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.Collections.Generic; +using Microsoft.CodeAnalysis.CSharp; +using Xunit; + +namespace Microsoft.AspNetCore.Blazor.Razor +{ + public class GlobalQualifiedTypeNameRewriterTest + { + [Theory] + [InlineData("String", "global::String")] + [InlineData("System.String", "global::System.String")] + [InlineData("TItem2", "TItem2")] + [InlineData("System.Collections.Generic.List", "global::System.Collections.Generic.List")] + [InlineData("System.Collections.Generic.Dictionary", "global::System.Collections.Generic.Dictionary")] + [InlineData("System.Collections.TItem3.Dictionary", "global::System.Collections.TItem3.Dictionary")] + [InlineData("System.Collections.TItem3.TItem1", "global::System.Collections.TItem3.TItem1")] + + // This case is interesting because we know TITem2 to be a generic type parameter, + // and we know that this will never be valid, which is why we don't bother rewriting. + [InlineData("TItem2", "TItem2")] + public void GlobalQualifiedTypeNameRewriter_CanQualifyNames(string original, string expected) + { + // Arrange + var visitor = new GlobalQualifiedTypeNameRewriter(new[] { "TItem1", "TItem2", "TItem3" }); + + var parsed = SyntaxFactory.ParseTypeName(original); + + // Act + var actual = visitor.Visit(parsed); + + // Assert + Assert.Equal(expected, actual.ToString()); + } + } +} diff --git a/test/shared/AssertFrame.cs b/test/shared/AssertFrame.cs index afae68ce5e..173ef35944 100644 --- a/test/shared/AssertFrame.cs +++ b/test/shared/AssertFrame.cs @@ -123,6 +123,13 @@ namespace Microsoft.AspNetCore.Blazor.Test.Helpers AssertFrame.Sequence(frame, sequence); } + public static void ComponentReferenceCapture(RenderTreeFrame frame, int? sequence = null) + { + Assert.Equal(RenderTreeFrameType.ComponentReferenceCapture, frame.FrameType); + Assert.NotNull(frame.ComponentReferenceCaptureAction); + AssertFrame.Sequence(frame, sequence); + } + public static void ComponentReferenceCapture(RenderTreeFrame frame, Action action, int? sequence = null) { Assert.Equal(RenderTreeFrameType.ComponentReferenceCapture, frame.FrameType); diff --git a/test/testapps/BasicTestApp/MultipleChildContent.cshtml b/test/testapps/BasicTestApp/MultipleChildContent.cshtml index b0d1d97076..d383c5adb2 100644 --- a/test/testapps/BasicTestApp/MultipleChildContent.cshtml +++ b/test/testapps/BasicTestApp/MultipleChildContent.cshtml @@ -1,4 +1,4 @@ - +
Col1Col2Col3