From b320dc7652ab9a4e20a32b1405faffb05475a039 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 27 Feb 2023 14:53:54 +0100 Subject: [PATCH 1/5] Add a test --- .../ComponentCodeGenerationTestBase.cs | 31 +++++++++ .../TestComponent.codegen.cs | 64 +++++++++++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 29 +++++++++ .../TestComponent.mappings.txt | 19 ++++++ .../TestComponent.codegen.cs | 40 ++++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 20 ++++++ .../TestComponent.mappings.txt | 9 +++ 9 files changed, 214 insertions(+) create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index c9a6ddabcec..36ff82328e0 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -1044,6 +1044,37 @@ public class ComponentWithEditorRequiredParameters : ComponentBase Assert.Empty(generated.Diagnostics); } + [Fact] // https://github.com/dotnet/razor/issues/7395 + public void Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind() + { + AdditionalSyntaxTrees.Add(Parse(""" + using System; + using Microsoft.AspNetCore.Components; + + namespace Test; + + public class ComponentWithEditorRequiredParameters : ComponentBase + { + [Parameter] + [EditorRequired] + public string Property1 { get; set; } + } + """)); + + var generated = CompileToCSharp(""" + + + @code { + private string myField = "Some Value"; + } + """); + + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + Assert.Empty(generated.Diagnostics); + } + [Fact] public void Component_WithEditorRequiredChildContent_NoValueSpecified() { diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs new file mode 100644 index 00000000000..627a1966181 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs @@ -0,0 +1,64 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Components; + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + { + #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(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + myField + +#line default +#line hidden +#nullable disable + ); + __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => myField = __value, myField); + __builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => { + } + )); + __o = ((global::Test.ComponentWithEditorRequiredParameters)default). +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + Property1 + +#line default +#line hidden +#nullable disable + ; +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = typeof(global::Test.ComponentWithEditorRequiredParameters); + +#line default +#line hidden +#nullable disable + } + #pragma warning restore 1998 +#nullable restore +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + private string myField = "Some Value"; + +#line default +#line hidden +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..c693614cc93 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,1): Warning RZ2012: Component 'ComponentWithEditorRequiredParameters' expects a value for the parameter 'Property1', but a value may not have been provided. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt new file mode 100644 index 00000000000..ded89ed16f3 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/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 [37] ) - Microsoft.AspNetCore.Components + ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + DesignTimeDirective - + 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 + Component - (0:0,0 [67] x:\dir\subdir\Test\TestComponent.cshtml) - ComponentWithEditorRequiredParameters + ComponentAttribute - (56:0,56 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Property1 - Property1 - AttributeStructure.DoubleQuotes + CSharpExpression - + LazyIntermediateToken - (56:0,56 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - myField + ComponentAttribute - (56:0,56 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Property1Changed - - AttributeStructure.DoubleQuotes + CSharpExpression - + IntermediateToken - - CSharp - global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, + IntermediateToken - - CSharp - __value => myField = __value + IntermediateToken - - CSharp - , myField) + HtmlContent - (67:0,67 [4] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (67:0,67 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + CSharpCode - (78:2,7 [46] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (78:2,7 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private string myField = "Some Value";\n diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt new file mode 100644 index 00000000000..7e2a3c7da85 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt @@ -0,0 +1,19 @@ +Source Location: (56:0,56 [7] x:\dir\subdir\Test\TestComponent.cshtml) +|myField| +Generated Location: (1049:25,56 [7] ) +|myField| + +Source Location: (45:0,45 [9] x:\dir\subdir\Test\TestComponent.cshtml) +|Property1| +Generated Location: (1649:38,45 [9] ) +|Property1| + +Source Location: (78:2,7 [46] x:\dir\subdir\Test\TestComponent.cshtml) +| + private string myField = "Some Value"; +| +Generated Location: (2038:55,7 [46] ) +| + private string myField = "Some Value"; +| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs new file mode 100644 index 00000000000..429084f6b5a --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/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.Components; + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __builder.OpenComponent(0); + __builder.AddAttribute(1, "Property1", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + myField + +#line default +#line hidden +#nullable disable + )); + __builder.AddAttribute(2, "Property1Changed", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => myField = __value, myField)); + __builder.CloseComponent(); + } + #pragma warning restore 1998 +#nullable restore +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + private string myField = "Some Value"; + +#line default +#line hidden +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..c693614cc93 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,1): Warning RZ2012: Component 'ComponentWithEditorRequiredParameters' expects a value for the parameter 'Property1', but a value may not have been provided. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt new file mode 100644 index 00000000000..a3ad8db8424 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt @@ -0,0 +1,20 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components + ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree + Component - (0:0,0 [67] x:\dir\subdir\Test\TestComponent.cshtml) - ComponentWithEditorRequiredParameters + ComponentAttribute - (56:0,56 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Property1 - Property1 - AttributeStructure.DoubleQuotes + CSharpExpression - + LazyIntermediateToken - (56:0,56 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - myField + ComponentAttribute - (56:0,56 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Property1Changed - - AttributeStructure.DoubleQuotes + CSharpExpression - + IntermediateToken - - CSharp - global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, + IntermediateToken - - CSharp - __value => myField = __value + IntermediateToken - - CSharp - , myField) + CSharpCode - (78:2,7 [46] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (78:2,7 [46] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private string myField = "Some Value";\n diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt new file mode 100644 index 00000000000..ba98a72acc9 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt @@ -0,0 +1,9 @@ +Source Location: (78:2,7 [46] x:\dir\subdir\Test\TestComponent.cshtml) +| + private string myField = "Some Value"; +| +Generated Location: (1356:31,7 [46] ) +| + private string myField = "Some Value"; +| + From 254a4aac7a29f3f00b4483278fb826985bc8ed2d Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 27 Feb 2023 15:12:00 +0100 Subject: [PATCH 2/5] Consider `@bind` for `EditorRequired` parameters --- .../src/Components/ComponentLoweringPass.cs | 9 ++++++++- .../TestComponent.diagnostics.txt | 1 - .../TestComponent.diagnostics.txt | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) delete mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt delete mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentLoweringPass.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentLoweringPass.cs index 70eea35c5f0..2c640306473 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentLoweringPass.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentLoweringPass.cs @@ -196,7 +196,14 @@ static bool IsPresentAsAttribute(string attributeName, ComponentIntermediateNode { return true; } - else if (child is ComponentChildContentIntermediateNode childContent && attributeName == childContent.AttributeName) + if (child is ComponentChildContentIntermediateNode childContent && attributeName == childContent.AttributeName) + { + return true; + } + const string bindPrefix = "@bind-"; + if (child is TagHelperDirectiveAttributeIntermediateNode { OriginalAttributeName: { } originalAttributeName } && + originalAttributeName.StartsWith(bindPrefix, StringComparison.Ordinal) && + originalAttributeName.AsSpan()[bindPrefix.Length..].Equals(attributeName.AsSpan(), StringComparison.Ordinal)) { return true; } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt deleted file mode 100644 index c693614cc93..00000000000 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt +++ /dev/null @@ -1 +0,0 @@ -x:\dir\subdir\Test\TestComponent.cshtml(1,1): Warning RZ2012: Component 'ComponentWithEditorRequiredParameters' expects a value for the parameter 'Property1', but a value may not have been provided. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt deleted file mode 100644 index c693614cc93..00000000000 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.diagnostics.txt +++ /dev/null @@ -1 +0,0 @@ -x:\dir\subdir\Test\TestComponent.cshtml(1,1): Warning RZ2012: Component 'ComponentWithEditorRequiredParameters' expects a value for the parameter 'Property1', but a value may not have been provided. From 9ced03b5ee50f6975062d946bc45c350753a1c73 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Tue, 9 May 2023 12:40:45 +0200 Subject: [PATCH 3/5] Update baselines --- .../TestComponent.codegen.cs | 18 ++++++++++-------- .../TestComponent.ir.txt | 12 ++++++------ .../TestComponent.mappings.txt | 6 +++--- .../TestComponent.codegen.cs | 14 +++++++------- .../TestComponent.ir.txt | 10 +++++----- .../TestComponent.mappings.txt | 2 +- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs index 627a1966181..b56d4da8bd9 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs @@ -3,11 +3,11 @@ namespace Test { #line hidden - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using Microsoft.AspNetCore.Components; + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase { #pragma warning disable 219 @@ -15,7 +15,7 @@ private void __RazorDirectiveTokenHelpers__() { } #pragma warning restore 219 #pragma warning disable 0414 - private static System.Object __o = null; + private static object __o = null; #pragma warning restore 0414 #pragma warning disable 1998 protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) @@ -33,7 +33,8 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components. __builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => { } )); - __o = ((global::Test.ComponentWithEditorRequiredParameters)default). + #pragma warning disable BL0005 + ((global::Test.ComponentWithEditorRequiredParameters)default). #nullable restore #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" Property1 @@ -41,7 +42,8 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components. #line default #line hidden #nullable disable - ; + = default; + #pragma warning restore BL0005 #nullable restore #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" __o = typeof(global::Test.ComponentWithEditorRequiredParameters); diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt index ded89ed16f3..333067126b5 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt @@ -1,16 +1,16 @@ 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 [37] ) - Microsoft.AspNetCore.Components + UsingDirective - (3:1,1 [20] ) - global::System + UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic + UsingDirective - (69:3,1 [25] ) - global::System.Linq + UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase - DesignTimeDirective - CSharpCode - IntermediateToken - - CSharp - #pragma warning disable 0414 CSharpCode - - IntermediateToken - - CSharp - private static System.Object __o = null; + IntermediateToken - - CSharp - private static object __o = null; CSharpCode - IntermediateToken - - CSharp - #pragma warning restore 0414 MethodDeclaration - - protected override - void - BuildRenderTree diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt index 7e2a3c7da85..eb1a5a7fa7f 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt @@ -1,18 +1,18 @@ Source Location: (56:0,56 [7] x:\dir\subdir\Test\TestComponent.cshtml) |myField| -Generated Location: (1049:25,56 [7] ) +Generated Location: (1082:25,56 [7] ) |myField| Source Location: (45:0,45 [9] x:\dir\subdir\Test\TestComponent.cshtml) |Property1| -Generated Location: (1649:38,45 [9] ) +Generated Location: (1720:39,45 [9] ) |Property1| Source Location: (78:2,7 [46] x:\dir\subdir\Test\TestComponent.cshtml) | private string myField = "Some Value"; | -Generated Location: (2038:55,7 [46] ) +Generated Location: (2163:57,7 [46] ) | private string myField = "Some Value"; | diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs index 429084f6b5a..01f6c48c4f5 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.codegen.cs @@ -3,18 +3,18 @@ namespace Test { #line hidden - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using Microsoft.AspNetCore.Components; + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase { #pragma warning disable 1998 protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) { __builder.OpenComponent(0); - __builder.AddAttribute(1, "Property1", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( + __builder.AddComponentParameter(1, "Property1", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck( #nullable restore #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" myField @@ -23,7 +23,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components. #line hidden #nullable disable )); - __builder.AddAttribute(2, "Property1Changed", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => myField = __value, myField)); + __builder.AddComponentParameter(2, "Property1Changed", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => myField = __value, myField)); __builder.CloseComponent(); } #pragma warning restore 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt index a3ad8db8424..a389b36bcd2 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.ir.txt @@ -1,10 +1,10 @@ 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 [39] ) - Microsoft.AspNetCore.Components + UsingDirective - (3:1,1 [22] ) - global::System + UsingDirective - (26:2,1 [42] ) - global::System.Collections.Generic + UsingDirective - (69:3,1 [27] ) - global::System.Linq + UsingDirective - (97:4,1 [38] ) - global::System.Threading.Tasks + UsingDirective - (136:5,1 [47] ) - global::Microsoft.AspNetCore.Components ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase - MethodDeclaration - - protected override - void - BuildRenderTree Component - (0:0,0 [67] x:\dir\subdir\Test\TestComponent.cshtml) - ComponentWithEditorRequiredParameters diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt index ba98a72acc9..0bcfe791241 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind/TestComponent.mappings.txt @@ -2,7 +2,7 @@ | private string myField = "Some Value"; | -Generated Location: (1356:31,7 [46] ) +Generated Location: (1414:31,7 [46] ) | private string myField = "Some Value"; | From be663b81e49bcfb5915206d0efeb4dc85f66877f Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Tue, 9 May 2023 12:41:33 +0200 Subject: [PATCH 4/5] Use `WorkItem` attribute --- .../test/IntegrationTests/ComponentCodeGenerationTestBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index 68eae80e616..d9cd21bfefa 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -1138,7 +1138,7 @@ public class ComponentWithEditorRequiredParameters : ComponentBase Assert.Empty(generated.Diagnostics); } - [Fact] // https://github.com/dotnet/razor/issues/7395 + [Fact, WorkItem("https://github.com/dotnet/razor/issues/7395")] public void Component_WithEditorRequiredParameter_ValueSpecifiedUsingBind() { AdditionalSyntaxTrees.Add(Parse(""" @@ -6754,7 +6754,7 @@ public class Child : ComponentBase CompileToAssembly(generated); } - [Fact] // https://github.com/dotnet/razor/issues/7103 + [Fact, WorkItem("https://github.com/dotnet/razor/issues/7103")] public void CascadingGenericInference_ParameterInNamespace() { // Arrange From daf3c36055fd83669ccf0d2a2e078db219b7a1bd Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Tue, 9 May 2023 20:57:14 +0200 Subject: [PATCH 5/5] Update baselines --- .../RazorSourceGeneratorTests.cs | 12 +++++++++--- .../CustomTagHelper/Views_Home_Index_cshtml.g.cs | 10 ++++++++-- .../ViewComponent/Views_Home_Index_cshtml.g.cs | 5 ++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs index 778f993bcd7..34911d6081c 100644 --- a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorTests.cs @@ -1255,7 +1255,7 @@ internal sealed class Views_Shared__Layout : global::Microsoft.AspNetCore.Mvc.Ra ); } - [Fact] // https://github.com/dotnet/razor/issues/7049 + [Fact, WorkItem("https://github.com/dotnet/razor/issues/7049")] public async Task SourceGenerator_CshtmlFiles_TagHelperInFunction() { // Arrange @@ -2005,7 +2005,10 @@ internal sealed class Pages_Index : global::Microsoft.AspNetCore.Mvc.Razor.Razor public async override global::System.Threading.Tasks.Task ExecuteAsync() { WriteLiteral(""\r\n""); - __tagHelperExecutionContext = __tagHelperScopeManager.Begin(""h2"", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, ""5d59ecd7b7cf7355d7f60234988be34b81a8b6142529"", async() => { + __tagHelperExecutionContext = __tagHelperScopeManager.Begin(""h2"", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, ""5d59ecd7b7cf7355d7f60234988be34b81a8b6142529"", + #pragma warning disable 1998 + async() => { + #pragma warning restore 1998 WriteLiteral(""Hello world""); } ); @@ -2504,7 +2507,10 @@ internal sealed class Views_Home_Index : global::Microsoft.AspNetCore.Mvc.Razor. #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() { - __tagHelperExecutionContext = __tagHelperScopeManager.Begin(""vc:test"", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, ""209ff2a910aa467bb7942ed3e6cb586652327a442587"", async() => { + __tagHelperExecutionContext = __tagHelperScopeManager.Begin(""vc:test"", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, ""209ff2a910aa467bb7942ed3e6cb586652327a442587"", + #pragma warning disable 1998 + async() => { + #pragma warning restore 1998 } ); __TestViewComponentTagHelper = CreateTagHelper(); diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorTagHelperTests/CustomTagHelper/Views_Home_Index_cshtml.g.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorTagHelperTests/CustomTagHelper/Views_Home_Index_cshtml.g.cs index d98277783e1..f24f1b89174 100644 --- a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorTagHelperTests/CustomTagHelper/Views_Home_Index_cshtml.g.cs +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorTagHelperTests/CustomTagHelper/Views_Home_Index_cshtml.g.cs @@ -43,9 +43,15 @@ internal sealed class Views_Home_Index : global::Microsoft.AspNetCore.Mvc.Razor. public async override global::System.Threading.Tasks.Task ExecuteAsync() { WriteLiteral("\r\n"); - __tagHelperExecutionContext = __tagHelperScopeManager.Begin("email", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "c7a5bfe3b24fca2a512de60cbc0070e782f08b7a2540", async() => { + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("email", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "c7a5bfe3b24fca2a512de60cbc0070e782f08b7a2540", + #pragma warning disable 1998 + async() => { + #pragma warning restore 1998 WriteLiteral("\r\n custom tag helper\r\n "); - __tagHelperExecutionContext = __tagHelperScopeManager.Begin("email", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "c7a5bfe3b24fca2a512de60cbc0070e782f08b7a2828", async() => { + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("email", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "c7a5bfe3b24fca2a512de60cbc0070e782f08b7a2930", + #pragma warning disable 1998 + async() => { + #pragma warning restore 1998 WriteLiteral("nested tag helper"); } ); diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorTagHelperTests/ViewComponent/Views_Home_Index_cshtml.g.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorTagHelperTests/ViewComponent/Views_Home_Index_cshtml.g.cs index 5a01674c526..fcefe8ddf4f 100644 --- a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorTagHelperTests/ViewComponent/Views_Home_Index_cshtml.g.cs +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorTagHelperTests/ViewComponent/Views_Home_Index_cshtml.g.cs @@ -51,7 +51,10 @@ internal sealed class Views_Home_Index : global::Microsoft.AspNetCore.Mvc.Razor. #line hidden #nullable disable WriteLiteral("\r\n"); - __tagHelperExecutionContext = __tagHelperScopeManager.Begin("vc:test", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "ae625dc7ef6db4af156601325d79196402a512422749", async() => { + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("vc:test", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "ae625dc7ef6db4af156601325d79196402a512422749", + #pragma warning disable 1998 + async() => { + #pragma warning restore 1998 } ); __TestViewComponentTagHelper = CreateTagHelper();