From 9932e603f805dde7020a9b7835b08ce69b87017f Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Thu, 19 Sep 2024 13:15:04 -0700 Subject: [PATCH 1/5] Add tests --- .../ComponentCodeGenerationTestBase.cs | 31 ++++++++++++++ .../TestComponent.codegen.cs | 32 ++++++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 21 ++++++++++ .../TestComponent.mappings.txt | 5 +++ .../TestComponent.codegen.cs | 42 +++++++++++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 17 ++++++++ .../TestComponent.mappings.txt | 5 +++ .../TestComponent.codegen.cs | 24 +++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 12 ++++++ .../TestComponent.codegen.cs | 24 +++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 9 ++++ 15 files changed, 226 insertions(+) create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.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 02461edf28f..10082cc449a 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -5550,6 +5550,37 @@ @inherits BaseComponent ]); } + [IntegrationTestFact] + public void PageDirective_NoForwardSlash() + { + // Act + var generated = CompileToCSharp(@" +@page ""MyPage"" +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [IntegrationTestFact] + public void PageDirective_MissingRoute() + { + // Act + var generated = CompileToCSharp(@" +@page +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + + // Design time writer doesn't correctly emit pragmas for missing tokens, so don't validate them in design time + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument, verifyLinePragmas: !DesignTime); + CompileToAssembly(generated); + } + + #endregion #region EventCallback diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.codegen.cs new file mode 100644 index 00000000000..80e6877d1d7 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.codegen.cs @@ -0,0 +1,32 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + #nullable restore + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..2419e9d10d0 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,6): Error RZ1016: The 'page' directive expects a string surrounded by double quotes. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.ir.txt new file mode 100644 index 00000000000..d83e2a8a601 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.ir.txt @@ -0,0 +1,21 @@ +Document - + NamespaceDeclaration - - Test + 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 object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + MalformedDirective - (0:0,0 [5] x:\dir\subdir\Test\TestComponent.cshtml) - page + CSharpCode - (5:0,5 [0] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (5:0,5 [0] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - + HtmlContent - (5:0,5 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (5:0,5 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.mappings.txt new file mode 100644 index 00000000000..a6b073f91d2 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (5:0,5 [0] x:\dir\subdir\Test\TestComponent.cshtml) +|| +Generated Location: (920:26,5 [0] ) +|| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs new file mode 100644 index 00000000000..a2998bfb5c0 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs @@ -0,0 +1,42 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + #nullable restore + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +// language=Route,Component +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +global::System.Object __typeHelper = "MyPage"; + +#line default +#line hidden +#nullable disable + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..15714a08e34 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,1): Error RZ9988: The @page directive must specify a route template. The route template must be enclosed in quotes and begin with the '/' character. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt new file mode 100644 index 00000000000..2ff1dd75a2e --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt @@ -0,0 +1,17 @@ +Document - + NamespaceDeclaration - - Test + 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 - + DirectiveToken - (6:0,6 [8] x:\dir\subdir\Test\TestComponent.cshtml) - "MyPage" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + 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/PageDirective_NoForwardSlash/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.mappings.txt new file mode 100644 index 00000000000..ff1fe6dcd78 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (6:0,6 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|"MyPage"| +Generated Location: (749:22,37 [8] ) +|"MyPage"| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.codegen.cs new file mode 100644 index 00000000000..9dfa26c2a18 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.codegen.cs @@ -0,0 +1,24 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + #nullable restore + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..2419e9d10d0 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,6): Error RZ1016: The 'page' directive expects a string surrounded by double quotes. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.ir.txt new file mode 100644 index 00000000000..67b17c77744 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute/TestComponent.ir.txt @@ -0,0 +1,12 @@ +Document - + NamespaceDeclaration - - Test + 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 + MalformedDirective - (0:0,0 [5] x:\dir\subdir\Test\TestComponent.cshtml) - page + CSharpCode - (5:0,5 [0] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (5:0,5 [0] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs new file mode 100644 index 00000000000..9dfa26c2a18 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs @@ -0,0 +1,24 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + #nullable restore + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..15714a08e34 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,1): Error RZ9988: The @page directive must specify a route template. The route template must be enclosed in quotes and begin with the '/' character. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt new file mode 100644 index 00000000000..53f6b5d7a27 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt @@ -0,0 +1,9 @@ +Document - + NamespaceDeclaration - - Test + 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 From 2a5d9a8593d78864689c5bf4b95beddf93d8b1de Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Thu, 19 Sep 2024 17:47:23 -0700 Subject: [PATCH 2/5] Emit the attribute in runtime code, even if it has errors --- .../Language/Components/ComponentPageDirectivePass.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentPageDirectivePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentPageDirectivePass.cs index 44b4131cb5a..5c0a2cd5a47 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentPageDirectivePass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentPageDirectivePass.cs @@ -59,15 +59,16 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte var pageDirective = (DirectiveIntermediateNode)directives[i].Node; // The parser also adds errors for invalid syntax, we just need to not crash. - var routeToken = pageDirective.Tokens.FirstOrDefault(); + var routeToken = pageDirective.Tokens.First(); - if (routeToken is { Content: ['"', '/', .., '"'] content }) + if (routeToken is not { Content: ['"', '/', .., '"'] }) { - @namespace.Children.Insert(index++, new RouteAttributeExtensionNode(content) { Source = routeToken.Source }); + pageDirective.Diagnostics.Add(ComponentDiagnosticFactory.CreatePageDirective_MustSpecifyRoute(pageDirective.Source)); } - else + + if (!codeDocument.GetCodeGenerationOptions().DesignTime || pageDirective.Diagnostics.Count == 0) { - pageDirective.Diagnostics.Add(ComponentDiagnosticFactory.CreatePageDirective_MustSpecifyRoute(pageDirective.Source)); + @namespace.Children.Insert(index++, new RouteAttributeExtensionNode(routeToken.Content) { Source = routeToken.Source }); } } } From 5e5e62d76831c872388dd5620ef8ca84f63b1799 Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Thu, 19 Sep 2024 17:47:36 -0700 Subject: [PATCH 3/5] Update test baseline --- .../TestComponent.codegen.cs | 10 ++++++++++ .../PageDirective_NoForwardSlash/TestComponent.ir.txt | 1 + .../TestComponent.mappings.txt | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.mappings.txt diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs index 9dfa26c2a18..1b1772ca682 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.codegen.cs @@ -10,6 +10,16 @@ namespace Test using global::Microsoft.AspNetCore.Components; #line default #line hidden + [global::Microsoft.AspNetCore.Components.RouteAttribute( + // language=Route,Component +#nullable restore +#line (1,7)-(1,15) "x:\dir\subdir\Test\TestComponent.cshtml" +"MyPage" + +#line default +#line hidden +#nullable disable + )] #nullable restore public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase #nullable disable diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt index 53f6b5d7a27..c2bb7e7b978 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.ir.txt @@ -5,5 +5,6 @@ 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 + RouteAttributeExtensionNode - (6:0,6 [8] x:\dir\subdir\Test\TestComponent.cshtml) - "MyPage" ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase - MethodDeclaration - - protected override - void - BuildRenderTree diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.mappings.txt new file mode 100644 index 00000000000..08ea8558467 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (6:0,6 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|"MyPage"| +Generated Location: (504:16,0 [8] ) +|"MyPage"| + From b3454499cc1ae8ed5257433ceecb4435dcdb01db Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Fri, 20 Sep 2024 10:01:18 -0700 Subject: [PATCH 4/5] PR feedback --- .../ComponentCodeGenerationTestBase.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 10082cc449a..d13dd71356d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -5550,13 +5550,13 @@ @inherits BaseComponent ]); } - [IntegrationTestFact] + [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/10863")] public void PageDirective_NoForwardSlash() { // Act - var generated = CompileToCSharp(@" -@page ""MyPage"" -"); + var generated = CompileToCSharp(""" + @page "MyPage" + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); @@ -5564,13 +5564,13 @@ public void PageDirective_NoForwardSlash() CompileToAssembly(generated); } - [IntegrationTestFact] + [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/10863")] public void PageDirective_MissingRoute() { // Act - var generated = CompileToCSharp(@" -@page -"); + var generated = CompileToCSharp(""" + @page + """); // Assert AssertDocumentNodeMatchesBaseline(generated.CodeDocument); From 38e7f8be78773adc191c4cb0bf43cfda18afa79d Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Fri, 20 Sep 2024 10:28:43 -0700 Subject: [PATCH 5/5] Add extra tests --- .../ComponentCodeGenerationTestBase.cs | 34 +++++++++++++++ .../TestComponent.codegen.cs | 31 ++++++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 19 +++++++++ .../TestComponent.codegen.cs | 42 +++++++++++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 17 ++++++++ .../TestComponent.mappings.txt | 5 +++ .../TestComponent.codegen.cs | 24 +++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 10 +++++ .../TestComponent.codegen.cs | 34 +++++++++++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 10 +++++ .../TestComponent.mappings.txt | 5 +++ 15 files changed, 235 insertions(+) create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/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 d13dd71356d..e44e9a3f64e 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -5556,6 +5556,22 @@ public void PageDirective_NoForwardSlash() // Act var generated = CompileToCSharp(""" @page "MyPage" + + """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/10863")] + public void PageDirective_NoForwardSlash_WithComment() + { + // Act + var generated = CompileToCSharp(""" + @page /* comment */ "MyPage" + """); // Assert @@ -5570,6 +5586,24 @@ public void PageDirective_MissingRoute() // Act var generated = CompileToCSharp(""" @page + + """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + + // Design time writer doesn't correctly emit pragmas for missing tokens, so don't validate them in design time + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument, verifyLinePragmas: !DesignTime); + CompileToAssembly(generated); + } + + [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/10863")] + public void PageDirective_MissingRoute_WithComment() + { + // Act + var generated = CompileToCSharp(""" + @page /* comment */ + """); // Assert diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.codegen.cs new file mode 100644 index 00000000000..02c715203ff --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.codegen.cs @@ -0,0 +1,31 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + #nullable restore + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..e3425fa2dbc --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,20): Error RZ1016: The 'page' directive expects a string surrounded by double quotes. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.ir.txt new file mode 100644 index 00000000000..233c25c9448 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.ir.txt @@ -0,0 +1,19 @@ +Document - + NamespaceDeclaration - - Test + 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 object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + MalformedDirective - (0:0,0 [19] x:\dir\subdir\Test\TestComponent.cshtml) - page + HtmlContent - (19:0,19 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (19:0,19 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.codegen.cs new file mode 100644 index 00000000000..a2998bfb5c0 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.codegen.cs @@ -0,0 +1,42 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + #nullable restore + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +// language=Route,Component +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +global::System.Object __typeHelper = "MyPage"; + +#line default +#line hidden +#nullable disable + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..15714a08e34 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,1): Error RZ9988: The @page directive must specify a route template. The route template must be enclosed in quotes and begin with the '/' character. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.ir.txt new file mode 100644 index 00000000000..9b05a0bfecd --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.ir.txt @@ -0,0 +1,17 @@ +Document - + NamespaceDeclaration - - Test + 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 - + DirectiveToken - (20:0,20 [8] x:\dir\subdir\Test\TestComponent.cshtml) - "MyPage" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + 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/PageDirective_NoForwardSlash_WithComment/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.mappings.txt new file mode 100644 index 00000000000..b4b60abd1ea --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (20:0,20 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|"MyPage"| +Generated Location: (749:22,37 [8] ) +|"MyPage"| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.codegen.cs new file mode 100644 index 00000000000..9dfa26c2a18 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.codegen.cs @@ -0,0 +1,24 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + #nullable restore + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..e3425fa2dbc --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,20): Error RZ1016: The 'page' directive expects a string surrounded by double quotes. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.ir.txt new file mode 100644 index 00000000000..b6abec93a06 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_MissingRoute_WithComment/TestComponent.ir.txt @@ -0,0 +1,10 @@ +Document - + NamespaceDeclaration - - Test + 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 + MalformedDirective - (0:0,0 [19] x:\dir\subdir\Test\TestComponent.cshtml) - page diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.codegen.cs new file mode 100644 index 00000000000..b4122cfef0f --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.codegen.cs @@ -0,0 +1,34 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + [global::Microsoft.AspNetCore.Components.RouteAttribute( + // language=Route,Component +#nullable restore +#line (1,21)-(1,29) "x:\dir\subdir\Test\TestComponent.cshtml" +"MyPage" + +#line default +#line hidden +#nullable disable + )] + #nullable restore + public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..15714a08e34 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,1): Error RZ9988: The @page directive must specify a route template. The route template must be enclosed in quotes and begin with the '/' character. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.ir.txt new file mode 100644 index 00000000000..f134f1b55de --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.ir.txt @@ -0,0 +1,10 @@ +Document - + NamespaceDeclaration - - Test + 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 + RouteAttributeExtensionNode - (20:0,20 [8] x:\dir\subdir\Test\TestComponent.cshtml) - "MyPage" + ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.mappings.txt new file mode 100644 index 00000000000..ca9912367af --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/PageDirective_NoForwardSlash_WithComment/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (20:0,20 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|"MyPage"| +Generated Location: (505:16,0 [8] ) +|"MyPage"| +