diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BindLoweringPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BindLoweringPass.cs index 67bb6a2358..59c20de758 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BindLoweringPass.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BindLoweringPass.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Blazor.Razor @@ -474,6 +475,14 @@ namespace Microsoft.AspNetCore.Blazor.Razor private static IntermediateToken GetAttributeContent(TagHelperPropertyIntermediateNode node) { + var template = node.FindDescendantNodes().FirstOrDefault(); + if (template != null) + { + // See comments in TemplateDiagnosticPass + node.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(template.Source)); + return new IntermediateToken() { Kind = TokenKind.CSharp, Content = string.Empty, }; + } + if (node.Children[0] is HtmlContentIntermediateNode htmlContentNode) { // This case can be hit for a 'string' attribute. We want to turn it into diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs index b6441fd9e7..0e52a2aa2f 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDesignTimeNodeWriter.cs @@ -7,6 +7,7 @@ using System.Linq; using Microsoft.AspNetCore.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Blazor.Razor @@ -351,7 +352,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor // because each component creates a lambda scope for its child content. // // We're hacking it a bit here by just forcing every component to have an empty lambda - _scopeStack.OpenScope(node.TagName, isComponent: true); + _scopeStack.OpenComponentScope(node.TagName); _scopeStack.IncrementCurrentScopeChildCount(context); foreach (var child in node.Body) @@ -397,6 +398,34 @@ namespace Microsoft.AspNetCore.Blazor.Razor { // Do nothing } + else if (node.Children.Count == 1 && node.Children[0] is TemplateIntermediateNode template) + { + // Templates are represented as lambdas assignable for RenderFragment (for some T). + // We don't have a type to write down unless its bound to a stronly typed attribute. + // That's OK because the compiler gives an error if we can't type check it. + context.CodeWriter.Write(DesignTimeVariable); + context.CodeWriter.Write(" = "); + + // If we have a parameter type, then add a type check. + if (NeedsTypeCheck(node)) + { + context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck); + context.CodeWriter.Write("<"); + context.CodeWriter.Write(node.BoundAttribute.TypeName); + context.CodeWriter.Write(">"); + context.CodeWriter.Write("("); + } + + context.RenderNode(template); + + if (NeedsTypeCheck(node)) + { + context.CodeWriter.Write(")"); + } + + context.CodeWriter.Write(";"); + context.CodeWriter.WriteLine(); + } else { // There are a few different forms that could be used to contain all of the tokens, but we don't really care @@ -437,7 +466,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.CodeWriter.Write(" = "); // If we have a parameter type, then add a type check. - if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped()) + if (NeedsTypeCheck(node)) { context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck); context.CodeWriter.Write("<"); @@ -451,7 +480,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor WriteCSharpToken(context, tokens[i]); } - if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped()) + if (NeedsTypeCheck(node)) { context.CodeWriter.Write(")"); } @@ -461,6 +490,11 @@ namespace Microsoft.AspNetCore.Blazor.Razor } } + bool NeedsTypeCheck(ComponentAttributeExtensionNode n) + { + return n.BoundAttribute != null && !n.BoundAttribute.IsWeaklyTyped(); + } + IReadOnlyList GetCSharpTokens(ComponentAttributeExtensionNode attribute) { // We generally expect all children to be CSharp, this is here just in case. @@ -468,6 +502,27 @@ namespace Microsoft.AspNetCore.Blazor.Razor } } + public override void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (node == null) + { + throw new ArgumentNullException(nameof(node)); + } + + // Since the user doesn't write this name themselves, we have to use something hardcoded + // and predicatable. + const string VariableName = "context"; + + _scopeStack.OpenTemplateScope(context, VariableName); + context.RenderChildren(node); + _scopeStack.CloseScope(context); + } + public override void WriteReferenceCapture(CodeRenderingContext context, RefExtensionNode refNode) { if (context == null) diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs index fcf3e1f288..b12218c607 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorDiagnosticFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -153,9 +153,18 @@ namespace Microsoft.AspNetCore.Blazor.Razor new RazorDiagnosticDescriptor( "BL9991", () => "The attribute names could not be inferred from bind attibute '{0}'. Bind attributes should be of the form" + - "'bind', 'bind-value' or 'bind-value-change'", + "'bind', 'bind-value' or 'bind-value-change'", RazorDiagnosticSeverity.Error); + public static RazorDiagnostic CreateBindAttribute_InvalidSyntax(SourceSpan? source, string attribute) + { + var diagnostic = RazorDiagnostic.Create( + BindAttribute_InvalidSyntax, + source ?? SourceSpan.Undefined, + attribute); + return diagnostic; + } + public static readonly RazorDiagnosticDescriptor DisallowedScriptTag = new RazorDiagnosticDescriptor( "BL9992", () => "Script tags should not be placed inside components because they cannot be updated dynamically. To fix this, move the script tag to the 'index.html' file or another static location. For more information see https://go.microsoft.com/fwlink/?linkid=872131", @@ -169,13 +178,15 @@ namespace Microsoft.AspNetCore.Blazor.Razor return diagnostic; } - public static RazorDiagnostic CreateBindAttribute_InvalidSyntax(SourceSpan? source, string attribute) + public static readonly RazorDiagnosticDescriptor Template_InvalidLocation = + new RazorDiagnosticDescriptor( + "BL9994", + () => "Razor templates cannot be used in attributes.", + RazorDiagnosticSeverity.Error); + + public static RazorDiagnostic CreateTemplate_InvalidLocation(SourceSpan? source) { - var diagnostic = RazorDiagnostic.Create( - BindAttribute_InvalidSyntax, - source ?? SourceSpan.Undefined, - attribute); - return diagnostic; + return RazorDiagnostic.Create(Template_InvalidLocation, source ?? SourceSpan.Undefined); } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorExtensionInitializer.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorExtensionInitializer.cs index 55ca4908a8..73f3fc985d 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorExtensionInitializer.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorExtensionInitializer.cs @@ -63,6 +63,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor builder.Features.Add(new ConfigureBlazorCodeGenerationOptions()); + builder.AddTargetExtension(new BlazorTemplateTargetExtension()); + var isDeclarationOnlyCompile = builder.Configuration.ConfigurationName == DeclarationConfiguration.ConfigurationName; // Blazor-specific passes, in order. @@ -79,6 +81,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor builder.Features.Add(new EventHandlerLoweringPass()); builder.Features.Add(new RefLoweringPass()); builder.Features.Add(new BindLoweringPass()); + builder.Features.Add(new TemplateDiagnosticPass()); builder.Features.Add(new HtmlBlockPass()); builder.Features.Add(new ComponentTagHelperDescriptorProvider()); diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs index 3449e937c6..712e78861f 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorNodeWriter.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Blazor.Razor @@ -22,6 +23,8 @@ namespace Microsoft.AspNetCore.Blazor.Razor public abstract void WriteReferenceCapture(CodeRenderingContext context, RefExtensionNode node); + public abstract void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node); + public sealed override void BeginWriterScope(CodeRenderingContext context, string writer) { throw new NotImplementedException(nameof(BeginWriterScope)); diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs index c14cffa68c..a2752b0b62 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorRuntimeNodeWriter.cs @@ -9,6 +9,7 @@ using System.Text; using Microsoft.AspNetCore.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Blazor.Razor @@ -114,7 +115,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor else { // There may be something else inside the expression like a Template or another extension node. - throw new NotImplementedException("Unsupported: CSharpExpression with child node that isn't a CSharp node"); + context.RenderNode(node.Children[i]); } } @@ -202,7 +203,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.RenderNode(capture); } - _scopeStack.OpenScope(tagName: node.TagName, isComponent: false); + _scopeStack.OpenElementScope(node.TagName); // Render body of the tag inside the scope foreach (var child in node.Body) @@ -321,7 +322,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor context.RenderNode(attribute); } - _scopeStack.OpenScope(node.TagName, isComponent: true); + _scopeStack.OpenComponentScope(node.TagName); foreach (var child in node.Body) { context.RenderNode(child); @@ -382,6 +383,29 @@ namespace Microsoft.AspNetCore.Blazor.Razor var content = string.Join(string.Empty, GetHtmlTokens(htmlNode).Select(t => t.Content)); context.CodeWriter.WriteStringLiteral(content); } + else if (node.Children.Count == 1 && node.Children[0] is TemplateIntermediateNode template) + { + // Templates are represented as lambdas assignable for RenderFragment (for some T). + // We don't have a type to write down unless its bound to a stronly typed attribute. + // That's OK because the compiler gives an error if we can't type check it. + + // If we have a parameter type, then add a type check. + if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped()) + { + context.CodeWriter.Write(BlazorApi.RuntimeHelpers.TypeCheck); + context.CodeWriter.Write("<"); + context.CodeWriter.Write(node.BoundAttribute.TypeName); + context.CodeWriter.Write(">"); + context.CodeWriter.Write("("); + } + + context.RenderNode(template); + + if (node.BoundAttribute != null && !node.BoundAttribute.IsWeaklyTyped()) + { + context.CodeWriter.Write(")"); + } + } else { // See comments in BlazorDesignTimeNodeWriter for a description of the cases that are possible. @@ -438,6 +462,27 @@ namespace Microsoft.AspNetCore.Blazor.Razor } } + public override void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (node == null) + { + throw new ArgumentNullException(nameof(node)); + } + + // Since the user doesn't write this name themselves, we have to use something hardcoded + // and predicatable. + const string VariableName = "context"; + + _scopeStack.OpenTemplateScope(context, VariableName); + context.RenderChildren(node); + _scopeStack.CloseScope(context); + } + public override void WriteReferenceCapture(CodeRenderingContext context, RefExtensionNode node) { var codeWriter = context.CodeWriter; diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorTemplateTargetExtension.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorTemplateTargetExtension.cs new file mode 100644 index 0000000000..7c55e2b969 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/BlazorTemplateTargetExtension.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Extensions; + +namespace Microsoft.AspNetCore.Blazor.Razor +{ + internal class BlazorTemplateTargetExtension : ITemplateTargetExtension + { + public void WriteTemplate(CodeRenderingContext context, TemplateIntermediateNode node) + { + ((BlazorNodeWriter)context.NodeWriter).WriteTemplate(context, node); + } + } +} diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/EventHandlerLoweringPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/EventHandlerLoweringPass.cs index c0607e868c..2512fde137 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/EventHandlerLoweringPass.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/EventHandlerLoweringPass.cs @@ -1,10 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Blazor.Shared; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Blazor.Razor @@ -110,6 +111,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor private IntermediateNode RewriteUsage(IntermediateNode parent, TagHelperPropertyIntermediateNode node) { var original = GetAttributeContent(node); + if (original.Count == 0) + { + // This can happen in error cases, the parser will already have flagged this + // as an error, so ignore it. + return node; + } // Now rewrite the content of the value node to look like: // @@ -178,6 +185,14 @@ namespace Microsoft.AspNetCore.Blazor.Razor private static IReadOnlyList GetAttributeContent(TagHelperPropertyIntermediateNode node) { + var template = node.FindDescendantNodes().FirstOrDefault(); + if (template != null) + { + // See comments in TemplateDiagnosticPass + node.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(template.Source)); + return new[] { new IntermediateToken() { Kind = TokenKind.CSharp, Content = string.Empty, }, }; + } + if (node.Children.Count == 1 && node.Children[0] is HtmlContentIntermediateNode htmlContentNode) { // This case can be hit for a 'string' attribute. We want to turn it into diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs index 40f65ba9c4..509ed26f83 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/ScopeStack.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Blazor.Shared; @@ -21,9 +21,25 @@ namespace Microsoft.AspNetCore.Blazor.Razor public string BuilderVarName { get; private set; } = "builder"; - public void OpenScope(string tagName, bool isComponent) + public void OpenElementScope(string tagName) { - _stack.Push(new ScopeEntry(tagName, isComponent)); + _stack.Push(new ScopeEntry(tagName, ScopeKind.Element)); + } + + public void OpenComponentScope(string tagName) + { + _stack.Push(new ScopeEntry(tagName, ScopeKind.Component)); + } + + public void OpenTemplateScope(CodeRenderingContext context, string variableName) + { + var currentScope = new ScopeEntry("__template", ScopeKind.Template); + _stack.Push(currentScope); + + // Templates always get a lambda scope, because they are defined as a lambda. + OffsetBuilderVarNumber(1); + currentScope.LambdaScope = context.CodeWriter.BuildLambda(BuilderVarName, variableName); + } public void CloseScope(CodeRenderingContext context) @@ -34,8 +50,13 @@ namespace Microsoft.AspNetCore.Blazor.Razor if (currentScope.LambdaScope != null) { currentScope.LambdaScope.Dispose(); - context.CodeWriter.Write(")"); - context.CodeWriter.WriteEndMethodInvocation(); + + if (currentScope.Kind == ScopeKind.Component) + { + context.CodeWriter.Write(")"); + context.CodeWriter.WriteEndMethodInvocation(); + } + OffsetBuilderVarNumber(-1); } } @@ -46,7 +67,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor { var currentScope = _stack.Peek(); - if (currentScope.IsComponent && currentScope.ChildCount == 0) + if (currentScope.Kind == ScopeKind.Component && currentScope.ChildCount == 0) { // When we're about to insert the first child into a component, // it's time to open a new lambda @@ -72,16 +93,25 @@ namespace Microsoft.AspNetCore.Blazor.Razor private class ScopeEntry { public readonly string TagName; - public readonly bool IsComponent; + public ScopeKind Kind; public int ChildCount; public IDisposable LambdaScope; - public ScopeEntry(string tagName, bool isComponent) + public ScopeEntry(string tagName, ScopeKind kind) { TagName = tagName; - IsComponent = isComponent; + Kind = kind; ChildCount = 0; } + + public override string ToString() => $"<{TagName}> ({Kind})"; + } + + private enum ScopeKind + { + Element, + Component, + Template, } } } diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TemplateDiagnosticPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TemplateDiagnosticPass.cs new file mode 100644 index 0000000000..b5c2f0da19 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/TemplateDiagnosticPass.cs @@ -0,0 +1,60 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Blazor.Razor +{ + internal class TemplateDiagnosticPass : IntermediateNodePassBase, IRazorOptimizationPass + { + // Runs after components/eventhandlers/ref/bind. We need to check for templates in all of those + // places. + public override int Order => 150; + + protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) + { + var visitor = new Visitor(); + visitor.Visit(documentNode); + + for (var i = 0; i < visitor.Candidates.Count; i++) + { + var candidate = visitor.Candidates[i]; + candidate.Parent.Diagnostics.Add(BlazorDiagnosticFactory.CreateTemplate_InvalidLocation(candidate.Node.Source)); + + // Remove the offending node since we don't know how to render it. This means that the user won't get C# + // completion at this location, which is fine because it's inside an HTML attribute. + candidate.Remove(); + } + } + + private class Visitor : IntermediateNodeWalker, IExtensionIntermediateNodeVisitor + { + public List Candidates { get; } = new List(); + + public void VisitExtension(TemplateIntermediateNode node) + { + // We found a template, let's check where it's located. + for (var i = 0; i < Ancestors.Count; i++) + { + var ancestor = Ancestors[i]; + + if ( + // Inside markup attribute + ancestor is HtmlAttributeIntermediateNode || + + // Inside component attribute + ancestor is ComponentAttributeExtensionNode || + + // Inside malformed ref attribute + ancestor is TagHelperPropertyIntermediateNode) + { + Candidates.Add(new IntermediateNodeReference(Parent, node)); + } + } + } + } + } +} diff --git a/src/Microsoft.AspNetCore.Blazor/RenderFragment.cs b/src/Microsoft.AspNetCore.Blazor/RenderFragment.cs index 529c4c753f..a8526956b6 100644 --- a/src/Microsoft.AspNetCore.Blazor/RenderFragment.cs +++ b/src/Microsoft.AspNetCore.Blazor/RenderFragment.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Blazor.RenderTree; @@ -11,4 +11,13 @@ namespace Microsoft.AspNetCore.Blazor /// /// The to which the content should be written. public delegate void RenderFragment(RenderTreeBuilder builder); + + /// + /// Represents a segment of UI content for an object of type , implemented + /// as a delegate that writes the content to a . + /// + /// The type of object. + /// The to which the content should be written. + /// The value used to build the content. + public delegate void RenderFragment(RenderTreeBuilder builder, T value); } diff --git a/src/Microsoft.AspNetCore.Blazor/RenderFragmentExtensions.cs b/src/Microsoft.AspNetCore.Blazor/RenderFragmentExtensions.cs new file mode 100644 index 0000000000..44471c02a1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Blazor/RenderFragmentExtensions.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.Blazor +{ + /// + /// Contains extension methods for and . + /// + public static class RenderFragmentExtensions + { + /// + /// Binds a and a value of type to a + /// so that it can be used by the rendering system from Razor code. + /// + /// The type of the value used by the . + /// A , usually produced by a Razor template. + /// The value of type . + /// A . + public static RenderFragment WithValue(this RenderFragment fragment, T value) + { + return (b) => fragment(b, value); + } + } +} diff --git a/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeBuilder.cs b/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeBuilder.cs index 89dad2fd3a..0b152cfe8e 100644 --- a/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeBuilder.cs +++ b/src/Microsoft.AspNetCore.Blazor/RenderTree/RenderTreeBuilder.cs @@ -102,6 +102,26 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree } } + /// + /// Appends frames representing an arbitrary fragment of content. + /// + /// An integer that represents the position of the instruction in the source code. + /// Content to append. + /// The value used by . + public void AddContent(int sequence, RenderFragment fragment, T value) + { + if (fragment != null) + { + // We surround the fragment with a region delimiter to indicate that the + // sequence numbers inside the fragment are unrelated to the sequence numbers + // outside it. If we didn't do this, the diffing logic might produce inefficient + // diffs depending on how the sequence numbers compared. + OpenRegion(sequence); + fragment(this, value); + CloseRegion(); + } + } + /// /// Appends a frame representing markup content. /// diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/ComponentRenderingRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/ComponentRenderingRazorIntegrationTest.cs index 3350ba57bd..aa318bd98e 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/ComponentRenderingRazorIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/ComponentRenderingRazorIntegrationTest.cs @@ -554,5 +554,58 @@ namespace Test frame => AssertFrame.Text(frame, "hi", 14), frame => AssertFrame.Markup(frame, "\n
\n ", 15)); } + + [Fact] + public void RazorTemplate_CanBeUsedFromComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; +using Microsoft.AspNetCore.Blazor.RenderTree; + +namespace Test +{ + public class Repeater : BlazorComponent + { + [Parameter] int Count { get; set; } + [Parameter] RenderFragment Template { get; set; } + [Parameter] string Value { get; set; } + + protected override void BuildRenderTree(RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + for (var i = 0; i < Count; i++) + { + builder.AddContent(i, Template, Value); + } + } + } +} +")); + + var component = CompileToComponent(@" +@addTagHelper ""*, TestAssembly"" +@{ RenderFragment template = @
@context.ToLower()
; } + +"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Component(frame, "Test.Repeater", 4, 2), + frame => AssertFrame.Attribute(frame, "Count", typeof(int), 3), + frame => AssertFrame.Attribute(frame, "Value", typeof(string), 4), + frame => AssertFrame.Attribute(frame, "Template", typeof(RenderFragment), 5), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1)); + } } } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs index 2abdec363d..82249842ca 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/DesignTimeCodeGenerationTest.cs @@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test internal override bool DesignTime => true; internal override bool UseTwoPhaseCompilation => true; - + [Fact] public void ChildComponent_WithParameters() { @@ -1030,5 +1030,221 @@ namespace Test AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); } + + [Fact] + public void RazorTemplate_InCodeBlock() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@{ + RenderFragment p = @
@context.Name
; +} +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + + [Fact] + public void RazorTemplate_InExplicitExpression() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@(RenderPerson(@
@context.Name
)) +@functions { + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_InImplicitExpression() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@RenderPerson(@
@context.Name
) +@functions { + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_ContainsComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ + RenderFragment p = @
; +} +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + // Targeted at the logic that assigns 'builder' names + [Fact] + public void RazorTemplate_FollowedByComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ + RenderFragment p = @
; +} + +@(""hello, world!"") + + +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_AsComponentParameter() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] RenderFragment PersonTemplate { get; set; } + } + + public class Person + { + public string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ RenderFragment template = @
@context.Name
; } + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_AsComponentParameter_MixedContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] RenderFragment Template { get; set; } + } + + public class Context + { + public int Index { get; set; } + public string Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ RenderFragment template = @
  • #@context.Index - @context.Item.ToLower()
  • ; } + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } } } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs index 09312b0cb7..a51499c39c 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs @@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test frame => AssertFrame.Markup(frame, "Hello", 0)); } - [Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")] + [Fact] public void CreatesSeparateMarkupFrameForEachTopLevelStaticElement() { // The JavaScript-side rendering code does not rely on this behavior. It supports @@ -106,14 +106,14 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test "@(\"Hi\") a b "); // Assert - Assert.Collection(GetRenderTree(component), - frame => AssertFrame.Element(frame, "root", 7, 0), + var frames = GetRenderTree(component); + Assert.Collection( + frames, + frame => AssertFrame.Element(frame, "root", 5, 0), frame => AssertFrame.Text(frame, "Hi", 1), frame => AssertFrame.Text(frame, " ", 2), - frame => AssertFrame.Markup(frame, "a", 3), - frame => AssertFrame.Text(frame, " ", 4), - frame => AssertFrame.Markup(frame, "b", 5), - frame => AssertFrame.Text(frame, " ", 6)); + frame => AssertFrame.Markup(frame, "a ", 3), + frame => AssertFrame.Markup(frame, "b ", 4)); } [Fact] @@ -598,5 +598,69 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test } public enum MyEnum { FirstValue, SecondValue } + + [Fact] + public void RazorTemplate_CanBeUsedFromRazorCode() + { + // Arrange + var component = CompileToComponent(@" +@{ RenderFragment template = @
    @context.ToLower()
    ; } +@for (var i = 0; i < 3; i++) +{ + @template.WithValue(""Hello, World!""); +} +"); + + // Act + var frames = GetRenderTree(component); + + // Assert + Assert.Collection( + frames, + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1), + frame => AssertFrame.Element(frame, "div", 2, 0), + frame => AssertFrame.Text(frame, "hello, world!", 1)); + } + + [Fact] + public void RazorTemplate_CanBeUsedFromMethod() + { + // Arrange + var component = CompileToComponent(@" +@(Repeat(@
    @context.ToLower()
    , ""Hello, World!"", 3)) + +@functions { + RenderFragment Repeat(RenderFragment template, T value, int count) + { + return (b) => + { + for (var i = 0; i < count; i++) + { + template(b, value); + } + }; + } +}"); + + // Act + var frames = GetRenderTree(component); + + // Assert + // + // The sequence numbers start at 1 here because there is an AddContent(0, Repeat(....) call + // that precedes the definition of the lambda. Sequence numbers for the lambda are allocated + // from the same logical sequence as the surrounding code. + Assert.Collection( + frames, + frame => AssertFrame.Element(frame, "div", 2, 1), + frame => AssertFrame.Text(frame, "hello, world!", 2), + frame => AssertFrame.Element(frame, "div", 2, 1), + frame => AssertFrame.Text(frame, "hello, world!", 2), + frame => AssertFrame.Element(frame, "div", 2, 1), + frame => AssertFrame.Text(frame, "hello, world!", 2)); + } } } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs index 0afc2a7aca..5e48e4bf6b 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RuntimeCodeGenerationTest.cs @@ -1269,5 +1269,221 @@ namespace Test AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); CompileToAssembly(generated); } + + [Fact] + public void RazorTemplate_InCodeBlock() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@{ + RenderFragment p = @
    @context.Name
    ; +} +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + + [Fact] + public void RazorTemplate_InExplicitExpression() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@(RenderPerson(@
    @context.Name
    )) +@functions { + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_InImplicitExpression() + { + // Arrange + + // Act + var generated = CompileToCSharp(@" +@RenderPerson(@
    @context.Name
    ) +@functions { + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_ContainsComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ + RenderFragment p = @
    ; +} +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + // Targeted at the logic that assigns 'builder' names + [Fact] + public void RazorTemplate_FollowedByComponent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ + RenderFragment p = @
    ; +} + +@(""hello, world!"") + + +@functions { + class Person + { + public string Name { get; set; } + } +}"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_AsComponentParameter() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] RenderFragment PersonTemplate { get; set; } + } + + public class Person + { + public string Name { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ RenderFragment template = @
    @context.Name
    ; } + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void RazorTemplate_AsComponentParameter_MixedContent() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + [Parameter] RenderFragment Template { get; set; } + } + + public class Context + { + public int Index { get; set; } + public string Item { get; set; } + } +} +")); + + // Act + var generated = CompileToCSharp(@" +@addTagHelper ""*, TestAssembly"" +@{ RenderFragment template = @
  • #@context.Index - @context.Item.ToLower()
  • ; } + +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } } } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TemplateRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TemplateRazorIntegrationTest.cs new file mode 100644 index 0000000000..fdc02afd37 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TemplateRazorIntegrationTest.cs @@ -0,0 +1,127 @@ +// 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 Xunit; + +namespace Microsoft.AspNetCore.Blazor.Build.Test +{ + public class TemplateRazorIntegrationTest : RazorBaselineIntegrationTestBase + { + // Razor doesn't parse this as a template, we don't need much special handling for + // it because it will just be invalid in general. + [Fact] + public void Template_ImplicitExpressionInMarkupAttribute_CreatesDiagnostic() + { + // Arrange + + // Act + var generated = CompileToCSharp(@"
    "" />"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Equal("RZ1005", diagnostic.Id); + } + + [Fact] + public void Template_ExplicitExpressionInMarkupAttribute_CreatesDiagnostic() + { + // Arrange + + // Act + var generated = CompileToCSharp(@"
    )"" />"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Equal("BL9994", diagnostic.Id); + } + + // Razor doesn't parse this as a template, we don't need much special handling for + // it because it will just be invalid in general. + [Fact] + public void Template_ImplicitExpressionInComponentAttribute_CreatesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + } +} +")); + + // Act + var generated = CompileToCSharp(@""" />"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Equal("RZ1005", diagnostic.Id); + } + + [Fact] + public void Template_ExplicitExpressionInComponentAttribute_CreatesDiagnostic() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(@" +using Microsoft.AspNetCore.Blazor; +using Microsoft.AspNetCore.Blazor.Components; + +namespace Test +{ + public class MyComponent : BlazorComponent + { + } +} +")); + // Act + var generated = CompileToCSharp(@")"" />"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Equal("BL9994", diagnostic.Id); + } + + [Fact] + public void Template_ExplicitExpressionInRef_CreatesDiagnostic() + { + // Arrange + + // Act + var generated = CompileToCSharp(@"
    )"" />"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Equal("BL9994", diagnostic.Id); + } + + + [Fact] + public void Template_ExplicitExpressionInBind_CreatesDiagnostic() + { + // Arrange + + // Act + var generated = CompileToCSharp(@")"" />"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Equal("BL9994", diagnostic.Id); + } + + [Fact] + public void Template_ExplicitExpressionInEventHandler_CreatesDiagnostic() + { + // Arrange + + // Act + var generated = CompileToCSharp(@")"" />"); + + // Assert + var diagnostic = Assert.Single(generated.Diagnostics); + Assert.Equal("BL9994", diagnostic.Id); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs new file mode 100644 index 0000000000..8e50513756 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs @@ -0,0 +1,60 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment template = + +#line default +#line hidden + (builder2, context) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.Name; + +#line default +#line hidden + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + __o = new Microsoft.AspNetCore.Blazor.RenderFragment( +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + template + +#line default +#line hidden + ); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.ir.txt new file mode 100644 index 0000000000..39c162e351 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.ir.txt @@ -0,0 +1,38 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) - "*, TestAssembly" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (35:1,2 [35] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [35] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = + Template - (71:1,38 [23] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (71:1,38 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (77:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (77:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + CSharpCode - (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (100:2,0 [41] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (129:2,29 [9] x:\dir\subdir\Test\TestComponent.cshtml) - PersonTemplate - PersonTemplate + CSharpExpression - (130:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (130:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template + HtmlContent - (141:2,41 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (141:2,41 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt new file mode 100644 index 0000000000..4f631de376 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt @@ -0,0 +1,25 @@ +Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|"*, TestAssembly"| +Generated Location: (558:16,37 [17] ) +|"*, TestAssembly"| + +Source Location: (35:1,2 [35] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = | +Generated Location: (1039:29,2 [35] ) +| RenderFragment template = | + +Source Location: (77:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) +|context.Name| +Generated Location: (1240:35,44 [12] ) +|context.Name| + +Source Location: (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1414:41,62 [2] ) +|; | + +Source Location: (130:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|template| +Generated Location: (1610:47,30 [8] ) +|template| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..d21e72efaf --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs @@ -0,0 +1,65 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment template = + +#line default +#line hidden + (builder2, context) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.Index; + +#line default +#line hidden +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.Item.ToLower(); + +#line default +#line hidden + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + __o = new Microsoft.AspNetCore.Blazor.RenderFragment( +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + template + +#line default +#line hidden + ); + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + } + )); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt new file mode 100644 index 0000000000..3541c5d421 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt @@ -0,0 +1,44 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + DirectiveToken - (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) - "*, TestAssembly" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = + Template - (77:1,44 [48] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (77:1,44 [50] x:\dir\subdir\Test\TestComponent.cshtml) - li + HtmlContent - (81:1,48 [1] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (81:1,48 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Html - # + CSharpExpression - (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Index + HtmlContent - (96:1,63 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (96:1,63 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \- + CSharpExpression - (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Item.ToLower() + CSharpCode - (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (132:2,0 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (155:2,23 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Template - Template + CSharpExpression - (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template + HtmlContent - (167:2,35 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (167:2,35 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..38cefa4950 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt @@ -0,0 +1,30 @@ +Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|"*, TestAssembly"| +Generated Location: (558:16,37 [17] ) +|"*, TestAssembly"| + +Source Location: (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = | +Generated Location: (1039:29,2 [41] ) +| RenderFragment template = | + +Source Location: (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) +|context.Index| +Generated Location: (1252:35,50 [13] ) +|context.Index| + +Source Location: (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) +|context.Item.ToLower()| +Generated Location: (1417:40,67 [22] ) +|context.Item.ToLower()| + +Source Location: (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1633:46,94 [2] ) +|; | + +Source Location: (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|template| +Generated Location: (1824:52,24 [8] ) +|template| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs new file mode 100644 index 0000000000..4082d38712 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs @@ -0,0 +1,65 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + RenderFragment p = + +#line default +#line hidden + (builder2, context) => { + __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + context.Name + +#line default +#line hidden + ); + builder2.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder3) => { + } + )); + } +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 5 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt new file mode 100644 index 0000000000..fce1ae8629 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/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 [17] x:\dir\subdir\Test\TestComponent.cshtml) - "*, TestAssembly" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = + Template - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - div + ComponentExtensionNode - (74:2,37 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (93:2,56 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name + CSharpExpression - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + CSharpCode - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt new file mode 100644 index 0000000000..84665112d5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt @@ -0,0 +1,39 @@ +Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|"*, TestAssembly"| +Generated Location: (558:16,37 [17] ) +|"*, TestAssembly"| + +Source Location: (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +| + RenderFragment p = | +Generated Location: (1039:29,2 [33] ) +| + RenderFragment p = | + +Source Location: (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) +|context.Name| +Generated Location: (1354:37,57 [12] ) +|context.Name| + +Source Location: (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|; +| +Generated Location: (1723:47,78 [3] ) +|; +| + +Source Location: (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (1869:54,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs new file mode 100644 index 0000000000..30475cf8a9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs @@ -0,0 +1,73 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((System.Action)(() => { +global::System.Object __typeHelper = "*, TestAssembly"; + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + RenderFragment p = + +#line default +#line hidden + (builder2, context) => { + __o = Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck( +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + context.Name + +#line default +#line hidden + ); + builder2.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder3) => { + } + )); + } +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + builder.AddAttribute(-1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { +#line 6 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = "hello, world!"; + +#line default +#line hidden + } + )); + } + #pragma warning restore 1998 +#line 9 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt new file mode 100644 index 0000000000..7d07d0fb6c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/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 [17] x:\dir\subdir\Test\TestComponent.cshtml) - "*, TestAssembly" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlContent - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (31:0,31 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = + Template - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - div + ComponentExtensionNode - (74:2,37 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (93:2,56 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name + CSharpExpression - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + CSharpCode - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + ComponentExtensionNode - (121:4,0 [49] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + HtmlContent - (134:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (134:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpExpression - (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hello, world!" + HtmlContent - (154:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (154:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + HtmlContent - (170:6,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (170:6,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + CSharpCode - (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt new file mode 100644 index 0000000000..a185a62885 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt @@ -0,0 +1,44 @@ +Source Location: (14:0,14 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|"*, TestAssembly"| +Generated Location: (558:16,37 [17] ) +|"*, TestAssembly"| + +Source Location: (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +| + RenderFragment p = | +Generated Location: (1039:29,2 [33] ) +| + RenderFragment p = | + +Source Location: (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) +|context.Name| +Generated Location: (1354:37,57 [12] ) +|context.Name| + +Source Location: (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|; +| +Generated Location: (1723:47,78 [3] ) +|; +| + +Source Location: (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|"hello, world!"| +Generated Location: (1929:53,6 [15] ) +|"hello, world!"| + +Source Location: (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (2122:62,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.codegen.cs new file mode 100644 index 0000000000..da003dcfc5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/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 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = ; + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.diagnostics.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.diagnostics.txt new file mode 100644 index 0000000000..18b722ba58 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,15): Error BL9994: Razor templates cannot be used in markup-attribute, bind attributes, ref attributes, or event handler attributes. diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.ir.txt new file mode 100644 index 0000000000..540f596fe7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.ir.txt @@ -0,0 +1,29 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + HtmlElement - (0:0,0 [44] x:\dir\subdir\Test\TestComponent.cshtml) - div + HtmlAttribute - (4:0,4 [33] x:\dir\subdir\Test\TestComponent.cshtml) - attr=" - " + CSharpExpressionAttributeValue - (11:0,11 [25] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (35:0,35 [0] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - + HtmlContent - (44:0,44 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (44:0,44 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (58:1,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (58:1,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.mappings.txt new file mode 100644 index 0000000000..84beff5b97 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InAttribute/TestComponent.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (35:0,35 [0] x:\dir\subdir\Test\TestComponent.cshtml) +|| +Generated Location: (955:25,35 [0] ) +|| + +Source Location: (58:1,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (1101:32,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs new file mode 100644 index 0000000000..968f7ca5b8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + + RenderFragment p = + +#line default +#line hidden + (builder2, context) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.Name; + +#line default +#line hidden + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt new file mode 100644 index 0000000000..28e58777c7 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = + Template - (36:1,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (36:1,32 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + CSharpCode - (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt new file mode 100644 index 0000000000..54db326ba9 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt @@ -0,0 +1,34 @@ +Source Location: (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +| + RenderFragment p = | +Generated Location: (922:25,2 [33] ) +| + RenderFragment p = | + +Source Location: (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) +|context.Name| +Generated Location: (1115:32,38 [12] ) +|context.Name| + +Source Location: (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|; +| +Generated Location: (1283:38,56 [3] ) +|; +| + +Source Location: (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (1429:45,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.codegen.cs new file mode 100644 index 0000000000..213f906869 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.codegen.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + + RenderFragment p = + +#line default +#line hidden + (builder2, item) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = item.Name; + +#line default +#line hidden + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.ir.txt new file mode 100644 index 0000000000..1209aa6555 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (2:0,2 [34] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [34] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = + Template - (37:1,33 [20] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (37:1,33 [21] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (43:1,39 [9] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (43:1,39 [9] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - item.Name + CSharpCode - (58:1,54 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (58:1,54 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (76:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (76:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.mappings.txt new file mode 100644 index 0000000000..201a81cbfe --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InCodeBlock_Dynamic/TestComponent.mappings.txt @@ -0,0 +1,34 @@ +Source Location: (2:0,2 [34] x:\dir\subdir\Test\TestComponent.cshtml) +| + RenderFragment p = | +Generated Location: (922:25,2 [34] ) +| + RenderFragment p = | + +Source Location: (43:1,39 [9] x:\dir\subdir\Test\TestComponent.cshtml) +|item.Name| +Generated Location: (1114:32,39 [9] ) +|item.Name| + +Source Location: (58:1,54 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|; +| +Generated Location: (1277:38,54 [3] ) +|; +| + +Source Location: (76:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (1423:45,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..7de4a55463 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs @@ -0,0 +1,52 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = RenderPerson((builder2, context) => { +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.Name; + +#line default +#line hidden +} +); + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..6f2bc6c9ad --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt @@ -0,0 +1,32 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (2:0,2 [37] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson( + Template - (16:0,16 [23] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (16:0,16 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + IntermediateToken - (40:0,40 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + HtmlContent - (42:0,42 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (42:0,42 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..31784c6e77 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt @@ -0,0 +1,34 @@ +Source Location: (2:0,2 [13] x:\dir\subdir\Test\TestComponent.cshtml) +|RenderPerson(| +Generated Location: (926:25,6 [13] ) +|RenderPerson(| + +Source Location: (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) +|context.Name| +Generated Location: (1038:27,22 [12] ) +|context.Name| + +Source Location: (40:0,40 [1] x:\dir\subdir\Test\TestComponent.cshtml) +|)| +Generated Location: (1087:32,0 [1] ) +|)| + +Source Location: (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| +Generated Location: (1234:39,12 [138] ) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..b58d53d9d5 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs @@ -0,0 +1,52 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = RenderPerson((builder2, context) => { +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = context.Name; + +#line default +#line hidden +} +); + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..aa8c3866a8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.ir.txt @@ -0,0 +1,32 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (1:0,1 [37] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (1:0,1 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson( + Template - (15:0,15 [23] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (15:0,15 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (21:0,21 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (21:0,21 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + IntermediateToken - (39:0,39 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + HtmlContent - (40:0,40 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (40:0,40 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..02adc91104 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt @@ -0,0 +1,34 @@ +Source Location: (1:0,1 [13] x:\dir\subdir\Test\TestComponent.cshtml) +|RenderPerson(| +Generated Location: (926:25,6 [13] ) +|RenderPerson(| + +Source Location: (21:0,21 [12] x:\dir\subdir\Test\TestComponent.cshtml) +|context.Name| +Generated Location: (1037:27,21 [12] ) +|context.Name| + +Source Location: (39:0,39 [1] x:\dir\subdir\Test\TestComponent.cshtml) +|)| +Generated Location: (1086:32,0 [1] ) +|)| + +Source Location: (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| +Generated Location: (1233:39,12 [138] ) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.codegen.cs new file mode 100644 index 0000000000..7a1232d37b --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.codegen.cs @@ -0,0 +1,56 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + + RenderFragment p = + +#line default +#line hidden + (builder2, item) => { +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + __o = item.Name; + +#line default +#line hidden + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" +
    another
    ; + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.ir.txt new file mode 100644 index 0000000000..539a261b28 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [33] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [44] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + DesignTimeDirective - + DirectiveToken - (14:0,14 [32] ) - "*, Microsoft.AspNetCore.Blazor" + DirectiveToken - (14:0,14 [9] ) - "*, Test" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = + Template - (36:1,32 [20] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (36:1,32 [21] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (42:1,38 [9] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (42:1,38 [9] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - item.Name + CSharpCode - (57:1,53 [21] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (57:1,53 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp -
    another
    ;\n + CSharpCode - (93:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (93:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.mappings.txt new file mode 100644 index 0000000000..3d8fcdb0c6 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/DesignTimeCodeGenerationTest/RazorTemplate_MultipleRoots/TestComponent.mappings.txt @@ -0,0 +1,34 @@ +Source Location: (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +| + RenderFragment p = | +Generated Location: (922:25,2 [33] ) +| + RenderFragment p = | + +Source Location: (42:1,38 [9] x:\dir\subdir\Test\TestComponent.cshtml) +|item.Name| +Generated Location: (1112:32,38 [9] ) +|item.Name| + +Source Location: (57:1,53 [21] x:\dir\subdir\Test\TestComponent.cshtml) +|
    another
    ; +| +Generated Location: (1274:38,53 [21] ) +|
    another
    ; +| + +Source Location: (93:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (1438:45,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs new file mode 100644 index 0000000000..bc44e0278f --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.codegen.cs @@ -0,0 +1,40 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment template = + +#line default +#line hidden + (builder2, context) => { + builder2.OpenElement(0, "div"); + builder2.AddContent(1, context.Name); + builder2.CloseElement(); + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + builder.OpenComponent(2); + builder.AddAttribute(3, "PersonTemplate", new Microsoft.AspNetCore.Blazor.RenderFragment(template)); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.ir.txt new file mode 100644 index 0000000000..123e499afe --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.ir.txt @@ -0,0 +1,24 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (35:1,2 [35] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [35] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = + Template - (71:1,38 [23] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (71:1,38 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (77:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (77:1,44 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + CSharpCode - (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (100:2,0 [41] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (129:2,29 [9] x:\dir\subdir\Test\TestComponent.cshtml) - PersonTemplate - PersonTemplate + CSharpExpression - (130:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (130:2,30 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt new file mode 100644 index 0000000000..38cba423b0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (35:1,2 [35] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = | +Generated Location: (654:18,2 [35] ) +| RenderFragment template = | + +Source Location: (95:1,62 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1034:28,62 [2] ) +|; | + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.codegen.cs new file mode 100644 index 0000000000..48625f2519 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/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); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + RenderFragment template = + +#line default +#line hidden + (builder2, context) => { + builder2.OpenElement(0, "li"); + builder2.AddContent(1, "#"); + builder2.AddContent(2, context.Index); + builder2.AddContent(3, " - "); + builder2.AddContent(4, context.Item.ToLower()); + builder2.CloseElement(); + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + builder.OpenComponent(5); + builder.AddAttribute(6, "Template", new Microsoft.AspNetCore.Blazor.RenderFragment(template)); + builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt new file mode 100644 index 0000000000..67d104b4c4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.ir.txt @@ -0,0 +1,30 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderFragment template = + Template - (77:1,44 [48] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (77:1,44 [50] x:\dir\subdir\Test\TestComponent.cshtml) - li + HtmlContent - (81:1,48 [1] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (81:1,48 [1] x:\dir\subdir\Test\TestComponent.cshtml) - Html - # + CSharpExpression - (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (83:1,50 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Index + HtmlContent - (96:1,63 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (96:1,63 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \- + CSharpExpression - (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (100:1,67 [22] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Item.ToLower() + CSharpCode - (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ; + ComponentExtensionNode - (132:2,0 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (155:2,23 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Template - Template + CSharpExpression - (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (156:2,24 [8] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - template diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt new file mode 100644 index 0000000000..957f6b1cfc --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_AsComponentParameter_MixedContent/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (35:1,2 [41] x:\dir\subdir\Test\TestComponent.cshtml) +| RenderFragment template = | +Generated Location: (654:18,2 [41] ) +| RenderFragment template = | + +Source Location: (127:1,94 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|; | +Generated Location: (1231:31,94 [2] ) +|; | + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.codegen.cs new file mode 100644 index 0000000000..6048c7ea24 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/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); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + RenderFragment p = + +#line default +#line hidden + (builder2, context) => { + builder2.OpenElement(0, "div"); + builder2.OpenComponent(1); + builder2.AddAttribute(2, "Name", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(context.Name)); + builder2.CloseComponent(); + builder2.CloseElement(); + } +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 5 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt new file mode 100644 index 0000000000..e4f216fe5b --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.ir.txt @@ -0,0 +1,24 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = + Template - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - div + ComponentExtensionNode - (74:2,37 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (93:2,56 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name + CSharpExpression - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + CSharpCode - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt new file mode 100644 index 0000000000..58511127b8 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_ContainsComponent/TestComponent.mappings.txt @@ -0,0 +1,29 @@ +Source Location: (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +| + RenderFragment p = | +Generated Location: (654:18,2 [33] ) +| + RenderFragment p = | + +Source Location: (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|; +| +Generated Location: (1244:31,78 [3] ) +|; +| + +Source Location: (133:4,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (1390:38,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.codegen.cs new file mode 100644 index 0000000000..674bd7003d --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/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 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + RenderFragment p = + +#line default +#line hidden + (builder2, context) => { + builder2.OpenElement(0, "div"); + builder2.OpenComponent(1); + builder2.AddAttribute(2, "Name", Microsoft.AspNetCore.Blazor.Components.RuntimeHelpers.TypeCheck(context.Name)); + builder2.CloseComponent(); + builder2.CloseElement(); + } +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + builder.OpenComponent(3); + builder.AddAttribute(4, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => { + builder2.AddContent(5, "\n"); + builder2.AddContent(6, "hello, world!"); + builder2.AddContent(7, "\n"); + } + )); + builder.CloseComponent(); + } + #pragma warning restore 1998 +#line 9 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt new file mode 100644 index 0000000000..a5a184e80e --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.ir.txt @@ -0,0 +1,31 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = + Template - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (69:2,32 [46] x:\dir\subdir\Test\TestComponent.cshtml) - div + ComponentExtensionNode - (74:2,37 [35] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + ComponentAttributeExtensionNode - (93:2,56 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Name - Name + CSharpExpression - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (94:2,57 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + CSharpCode - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + ComponentExtensionNode - (121:4,0 [49] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent + HtmlContent - (134:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (134:4,13 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpExpression - (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (138:5,2 [15] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "hello, world!" + HtmlContent - (154:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (154:5,18 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt new file mode 100644 index 0000000000..a70f88f50a --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_FollowedByComponent/TestComponent.mappings.txt @@ -0,0 +1,29 @@ +Source Location: (35:1,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +| + RenderFragment p = | +Generated Location: (654:18,2 [33] ) +| + RenderFragment p = | + +Source Location: (115:2,78 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|; +| +Generated Location: (1244:31,78 [3] ) +|; +| + +Source Location: (186:8,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (1784:46,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs new file mode 100644 index 0000000000..ee583ec422 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.codegen.cs @@ -0,0 +1,47 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + + RenderFragment p = + +#line default +#line hidden + (builder2, context) => { + builder2.OpenElement(0, "div"); + builder2.AddContent(1, context.Name); + builder2.CloseElement(); + } +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + ; + +#line default +#line hidden + } + #pragma warning restore 1998 +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt new file mode 100644 index 0000000000..a9cb531cf4 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.ir.txt @@ -0,0 +1,22 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpCode - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n RenderFragment p = + Template - (36:1,32 [23] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (36:1,32 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (42:1,38 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + CSharpCode - (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ;\n + CSharpCode - (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt new file mode 100644 index 0000000000..69bfe294e0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InCodeBlock/TestComponent.mappings.txt @@ -0,0 +1,29 @@ +Source Location: (2:0,2 [33] x:\dir\subdir\Test\TestComponent.cshtml) +| + RenderFragment p = | +Generated Location: (654:18,2 [33] ) +| + RenderFragment p = | + +Source Location: (60:1,56 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|; +| +Generated Location: (1026:29,56 [3] ) +|; +| + +Source Location: (78:3,12 [76] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } +| +Generated Location: (1172:36,12 [76] ) +| + class Person + { + public string Name { get; set; } + } +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..579dae9c2d --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.codegen.cs @@ -0,0 +1,39 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddContent(0, RenderPerson((builder2, context) => { + builder2.OpenElement(1, "div"); + builder2.AddContent(2, context.Name); + builder2.CloseElement(); + } + )); + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..23100c99b0 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.ir.txt @@ -0,0 +1,21 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (2:0,2 [37] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (2:0,2 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson( + Template - (16:0,16 [23] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (16:0,16 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (22:0,22 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + IntermediateToken - (40:0,40 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + CSharpCode - (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..7984dc9042 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InExplicitExpression/TestComponent.mappings.txt @@ -0,0 +1,19 @@ +Source Location: (56:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| +Generated Location: (964:26,12 [138] ) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs new file mode 100644 index 0000000000..579dae9c2d --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.codegen.cs @@ -0,0 +1,39 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Blazor; + using Microsoft.AspNetCore.Blazor.Components; + public class TestComponent : Microsoft.AspNetCore.Blazor.Components.BlazorComponent + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder) + { + base.BuildRenderTree(builder); + builder.AddContent(0, RenderPerson((builder2, context) => { + builder2.OpenElement(1, "div"); + builder2.AddContent(2, context.Name); + builder2.CloseElement(); + } + )); + } + #pragma warning restore 1998 +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" + + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; + +#line default +#line hidden + } +} +#pragma warning restore 1591 diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.ir.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.ir.txt new file mode 100644 index 0000000000..ecdfd5958c --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.ir.txt @@ -0,0 +1,21 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [35] ) - Microsoft.AspNetCore.Blazor + UsingDirective - (140:6,1 [46] ) - Microsoft.AspNetCore.Blazor.Components + ClassDeclaration - - public - TestComponent - Microsoft.AspNetCore.Blazor.Components.BlazorComponent - + MethodDeclaration - - protected override - void - BuildRenderTree + CSharpCode - + IntermediateToken - - CSharp - base.BuildRenderTree(builder); + CSharpExpression - (1:0,1 [37] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (1:0,1 [13] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - RenderPerson( + Template - (15:0,15 [23] x:\dir\subdir\Test\TestComponent.cshtml) + HtmlElement - (15:0,15 [24] x:\dir\subdir\Test\TestComponent.cshtml) - div + CSharpExpression - (21:0,21 [12] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (21:0,21 [12] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - context.Name + IntermediateToken - (39:0,39 [1] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - ) + CSharpCode - (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n class Person\n {\n public string Name { get; set; }\n }\n\n object RenderPerson(RenderFragment p) => null;\n diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt new file mode 100644 index 0000000000..e80f72f7bc --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/TestFiles/RuntimeCodeGenerationTest/RazorTemplate_InImplicitExpression/TestComponent.mappings.txt @@ -0,0 +1,19 @@ +Source Location: (54:1,12 [138] x:\dir\subdir\Test\TestComponent.cshtml) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| +Generated Location: (964:26,12 [138] ) +| + class Person + { + public string Name { get; set; } + } + + object RenderPerson(RenderFragment p) => null; +| + diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs index c9ee86fb55..e5a87975bb 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/ComponentRenderingTest.cs @@ -493,6 +493,20 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests appElement.FindElement(By.CssSelector("#dynamic-markup-block span em")).Text); } + [Fact] + public void CanRenderRazorTemplates() + { + var appElement = MountTestComponent(); + + // code block template (component parameter) + var element = appElement.FindElement(By.CssSelector("div#codeblocktemplate ol")); + Assert.Collection( + element.FindElements(By.TagName("li")), + e => Assert.Equal("#1 - a", e.Text), + e => Assert.Equal("#2 - b", e.Text), + e => Assert.Equal("#3 - c", e.Text)); + } + static IAlert SwitchToAlert(IWebDriver driver) { try diff --git a/test/testapps/BasicTestApp/Index.cshtml b/test/testapps/BasicTestApp/Index.cshtml index 9086b21fd0..88108c5d48 100644 --- a/test/testapps/BasicTestApp/Index.cshtml +++ b/test/testapps/BasicTestApp/Index.cshtml @@ -1,45 +1,46 @@ @using Microsoft.AspNetCore.Blazor.RenderTree
    Select test: - + @if (SelectedComponentType != null) { diff --git a/test/testapps/BasicTestApp/OrderedList.cshtml b/test/testapps/BasicTestApp/OrderedList.cshtml new file mode 100644 index 0000000000..a410635a73 --- /dev/null +++ b/test/testapps/BasicTestApp/OrderedList.cshtml @@ -0,0 +1,22 @@ +
      + @{ + var index = 1; + } + @foreach (var item in Items) + { + @Template.WithValue(new Context() { Index = index++, Item = item, }); + } +
    + +@functions{ + [Parameter] IEnumerable Items { get; set; } + + [Parameter] RenderFragment Template { get; set; } + + public class Context + { + public int Index { get; set; } + + public string Item { get; set; } + } +} \ No newline at end of file diff --git a/test/testapps/BasicTestApp/RazorTemplates.cshtml b/test/testapps/BasicTestApp/RazorTemplates.cshtml new file mode 100644 index 0000000000..e2ef8cc7ff --- /dev/null +++ b/test/testapps/BasicTestApp/RazorTemplates.cshtml @@ -0,0 +1,10 @@ +@{ + var items = new string[] { "A", "B", "c", }; +} + +
    + @{ + RenderFragment template = @
  • #@context.Index - @context.Item.ToLower()
  • ; + } + +