From ef07102e653c3336ec40231b136ba7e11e5df1da Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Thu, 22 Jan 2026 16:55:05 -0800 Subject: [PATCH 1/5] Make class name a token and required --- .../test/MvcViewDocumentClassifierPassTest.cs | 10 ++-- .../AssemblyAttributeInjectionPassTest.cs | 42 +++------------- .../test/MvcViewDocumentClassifierPassTest.cs | 10 ++-- .../test/NamespaceDirectiveTest.cs | 24 ++++----- .../RazorPageDocumentClassifierPassTest.cs | 10 ++-- ...idatedMvcViewDocumentClassifierPassTest.cs | 6 +-- .../test/MvcViewDocumentClassifierPassTest.cs | 10 ++-- .../RazorPageDocumentClassifierPassTest.cs | 10 ++-- .../CodeGeneration/CSharpCodeWriterTest.cs | 5 +- .../ComponentDocumentClassifierPassTest.cs | 6 +-- .../DefaultRazorCSharpLoweringPhaseTest.cs | 6 +-- .../test/DocumentClassifierPassBaseTest.cs | 8 ++- .../Extensions/MetadataAttributePassTest.cs | 50 +++---------------- .../DocumentIntermediateNodeExtensionsTest.cs | 3 +- .../CodeGeneration/CodeWriterExtensions.cs | 4 +- .../ComponentDocumentClassifierPass.cs | 32 +++++++----- .../Components/ComponentGenericTypePass.cs | 6 +-- .../ComponentRenderModeDirectivePass.cs | 4 +- .../Language/DefaultDocumentClassifierPass.cs | 2 + .../Language/DocumentClassifierPassBase.cs | 5 +- .../Extensions/MetadataAttributePass.cs | 6 +-- .../ClassDeclarationIntermediateNode.cs | 6 +-- .../src/Language/RazorProjectEngine.cs | 2 +- .../MvcViewDocumentClassifierPass.cs | 25 ++++++---- .../AssemblyAttributeInjectionPass.cs | 6 +-- .../MvcViewDocumentClassifierPass.cs | 25 ++++++---- .../RazorPageDocumentClassifierPass.cs | 29 ++++++----- .../src/Mvc/ModelDirective.cs | 2 +- .../src/Mvc/MvcViewDocumentClassifierPass.cs | 27 ++++++---- .../Mvc/RazorPageDocumentClassifierPass.cs | 27 +++++----- .../src/Mvc/ViewComponentTagHelperPass.cs | 4 +- ...ewComponentTagHelperTargetExtensionBase.cs | 2 +- .../IntermediateNodeWriter.cs | 2 +- .../RazorProjectEngineBuilderExtensions.cs | 2 +- 34 files changed, 193 insertions(+), 225 deletions(-) diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/MvcViewDocumentClassifierPassTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/MvcViewDocumentClassifierPassTest.cs index e503c1a0ed7..1113bcce6a6 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/MvcViewDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/MvcViewDocumentClassifierPassTest.cs @@ -86,7 +86,7 @@ public void MvcViewDocumentClassifierPass_SetsClass() Assert.NotNull(baseNode.ModelType); Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("Test", classNode.Name); + Assert.Equal("Test", classNode.Name.Content); } [Fact] @@ -109,7 +109,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() Assert.NotNull(baseNode.ModelType); Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", classNode.Name); + Assert.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", classNode.Name.Content); } [Theory] @@ -129,7 +129,7 @@ public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(str var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal(expected, classNode.Name); + Assert.Equal(expected, classNode.Name.Content); } [Fact] @@ -147,7 +147,7 @@ public void MvcViewDocumentClassifierPass_UsesAbsolutePath_IfRelativePathIsNotSe var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("x___application_Views_Home_Index", classNode.Name); + Assert.Equal("x___application_Views_Home_Index", classNode.Name.Content); } [Fact] @@ -165,7 +165,7 @@ public void MvcViewDocumentClassifierPass_SanitizesClassName() var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("path_with_invalid_chars", classNode.Name); + Assert.Equal("path_with_invalid_chars", classNode.Name.Content); } [Fact] diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/AssemblyAttributeInjectionPassTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/AssemblyAttributeInjectionPassTest.cs index e5bd6901667..40e04699893 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/AssemblyAttributeInjectionPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/AssemblyAttributeInjectionPassTest.cs @@ -68,36 +68,6 @@ public void Execute_NoOps_IfClassNameNodeIsMissing() Assert.Same(@namespace, node); } - [Fact] - public void Execute_NoOps_IfClassNameIsEmpty() - { - // Arrange - var codeDocument = ProjectEngine.CreateEmptyCodeDocument(); - var documentNode = new DocumentIntermediateNode() { Options = codeDocument.CodeGenerationOptions }; - - var builder = IntermediateNodeBuilder.Create(documentNode); - - var @namespace = new NamespaceDeclarationIntermediateNode() - { - Name = "SomeNamespace", - IsPrimaryNamespace = true, - }; - - builder.Push(@namespace); - - builder.Add(new ClassDeclarationIntermediateNode - { - IsPrimaryClass = true, - }); - - // Act - ProjectEngine.ExecutePass(codeDocument, documentNode); - - // Assert - var node = Assert.Single(documentNode.Children); - Assert.Same(@namespace, node); - } - [Fact] public void Execute_NoOps_IfDocumentIsNotViewOrPage() { @@ -115,7 +85,7 @@ public void Execute_NoOps_IfDocumentIsNotViewOrPage() var @class = new ClassDeclarationIntermediateNode { - Name = "SomeName", + Name = IntermediateNodeFactory.CSharpToken("SomeName"), IsPrimaryClass = true, }; @@ -153,7 +123,7 @@ public void Execute_NoOps_ForDesignTime() var @class = new ClassDeclarationIntermediateNode { - Name = "SomeName", + Name = IntermediateNodeFactory.CSharpToken("SomeName"), IsPrimaryClass = true, }; @@ -193,7 +163,7 @@ public void Execute_AddsRazorViewAttribute_ToViews() builder.Push(@namespace); var @class = new ClassDeclarationIntermediateNode { - Name = "SomeName", + Name = IntermediateNodeFactory.CSharpToken("SomeName"), IsPrimaryClass = true, }; @@ -240,7 +210,7 @@ public void Execute_EscapesViewPathWhenAddingAttributeToViews() var @class = new ClassDeclarationIntermediateNode { - Name = "SomeName", + Name = IntermediateNodeFactory.CSharpToken("SomeName"), IsPrimaryClass = true, }; @@ -294,7 +264,7 @@ public void Execute_AddsRazorPagettribute_ToPage() var @class = new ClassDeclarationIntermediateNode { - Name = "SomeName", + Name = IntermediateNodeFactory.CSharpToken("SomeName"), IsPrimaryClass = true, }; @@ -341,7 +311,7 @@ public void Execute_EscapesViewPathAndRouteWhenAddingAttributeToPage() var @class = new ClassDeclarationIntermediateNode { - Name = "SomeName", + Name = IntermediateNodeFactory.CSharpToken("SomeName"), IsPrimaryClass = true, }; diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/MvcViewDocumentClassifierPassTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/MvcViewDocumentClassifierPassTest.cs index 5812a7fca61..f41190ecb45 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/MvcViewDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/MvcViewDocumentClassifierPassTest.cs @@ -86,7 +86,7 @@ public void MvcViewDocumentClassifierPass_SetsClass() Assert.NotNull(baseNode.ModelType); Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("Test", classNode.Name); + Assert.Equal("Test", classNode.Name.Content); } [Fact] @@ -109,7 +109,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() Assert.NotNull(baseNode.ModelType); Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", classNode.Name); + Assert.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", classNode.Name.Content); } [Theory] @@ -129,7 +129,7 @@ public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(str var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal(expected, classNode.Name); + Assert.Equal(expected, classNode.Name.Content); } [Fact] @@ -147,7 +147,7 @@ public void MvcViewDocumentClassifierPass_UsesAbsolutePath_IfRelativePathIsNotSe var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("x___application_Views_Home_Index", classNode.Name); + Assert.Equal("x___application_Views_Home_Index", classNode.Name.Content); } [Fact] @@ -165,7 +165,7 @@ public void MvcViewDocumentClassifierPass_SanitizesClassName() var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("path_with_invalid_chars", classNode.Name); + Assert.Equal("path_with_invalid_chars", classNode.Name.Content); } [Fact] diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/NamespaceDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/NamespaceDirectiveTest.cs index 20444b08aac..3a1525ea506 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/NamespaceDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/NamespaceDirectiveTest.cs @@ -133,7 +133,7 @@ public void Pass_SetsNamespace_ComputedFromImports() var @namespace = new NamespaceDeclarationIntermediateNode() { Name = "default" }; builder.Push(@namespace); - var @class = new ClassDeclarationIntermediateNode() { Name = "default" }; + var @class = new ClassDeclarationIntermediateNode() { Name = IntermediateNodeFactory.CSharpToken("default") }; builder.Add(@class); documentNode.DocumentKind = RazorPageDocumentClassifierPass.RazorPageDocumentKind; @@ -143,7 +143,7 @@ public void Pass_SetsNamespace_ComputedFromImports() // Assert Assert.Equal("WebApplication.Account.Manage", @namespace.Name); - Assert.Equal("default", @class.Name); + Assert.Equal("default", @class.Name.Content); } // This is the case where the source file sets the namespace. @@ -180,7 +180,7 @@ public void Pass_SetsNamespace_ComputedFromSource() var @namespace = new NamespaceDeclarationIntermediateNode() { Name = "default" }; builder.Push(@namespace); - var @class = new ClassDeclarationIntermediateNode() { Name = "default" }; + var @class = new ClassDeclarationIntermediateNode() { Name = IntermediateNodeFactory.CSharpToken("default") }; builder.Add(@class); documentNode.DocumentKind = RazorPageDocumentClassifierPass.RazorPageDocumentKind; @@ -190,7 +190,7 @@ public void Pass_SetsNamespace_ComputedFromSource() // Assert Assert.Equal("WebApplication.Account.Manage", @namespace.Name); - Assert.Equal("default", @class.Name); + Assert.Equal("default", @class.Name.Content); } // Handles cases where invalid characters appears in FileNames. Note that we don't sanitize the part of @@ -217,7 +217,7 @@ public void Pass_SetsNamespace_SanitizesClassAndNamespace() var @namespace = new NamespaceDeclarationIntermediateNode() { Name = "default" }; builder.Push(@namespace); - var @class = new ClassDeclarationIntermediateNode() { Name = "default" }; + var @class = new ClassDeclarationIntermediateNode() { Name = IntermediateNodeFactory.CSharpToken("default") }; builder.Add(@class); documentNode.DocumentKind = RazorPageDocumentClassifierPass.RazorPageDocumentKind; @@ -227,7 +227,7 @@ public void Pass_SetsNamespace_SanitizesClassAndNamespace() // Assert Assert.Equal("WebApplication.Account.Manage_Info", @namespace.Name); - Assert.Equal("default", @class.Name); + Assert.Equal("default", @class.Name.Content); } // This is the case where the source file sets the namespace. @@ -264,7 +264,7 @@ public void Pass_SetsNamespace_ComputedFromSource_ForView() var @namespace = new NamespaceDeclarationIntermediateNode() { Name = "default" }; builder.Push(@namespace); - var @class = new ClassDeclarationIntermediateNode() { Name = "default" }; + var @class = new ClassDeclarationIntermediateNode() { Name = IntermediateNodeFactory.CSharpToken("default") }; builder.Add(@class); documentNode.DocumentKind = MvcViewDocumentClassifierPass.MvcViewDocumentKind; @@ -274,7 +274,7 @@ public void Pass_SetsNamespace_ComputedFromSource_ForView() // Assert Assert.Equal("WebApplication.Account.Manage", @namespace.Name); - Assert.Equal("default", @class.Name); + Assert.Equal("default", @class.Name.Content); } // This handles an error case where we can't determine the relationship between the @@ -301,7 +301,7 @@ public void Pass_SetsNamespace_VerbatimFromImports() var @namespace = new NamespaceDeclarationIntermediateNode() { Name = "default" }; builder.Push(@namespace); - var @class = new ClassDeclarationIntermediateNode() { Name = "default" }; + var @class = new ClassDeclarationIntermediateNode() { Name = IntermediateNodeFactory.CSharpToken("default") }; builder.Add(@class); documentNode.DocumentKind = RazorPageDocumentClassifierPass.RazorPageDocumentKind; @@ -311,7 +311,7 @@ public void Pass_SetsNamespace_VerbatimFromImports() // Assert Assert.Equal("WebApplication.Account", @namespace.Name); - Assert.Equal("default", @class.Name); + Assert.Equal("default", @class.Name.Content); } [Fact] @@ -336,7 +336,7 @@ public void Pass_DoesNothing_ForUnknownDocumentKind() var @namespace = new NamespaceDeclarationIntermediateNode() { Name = "default" }; builder.Push(@namespace); - var @class = new ClassDeclarationIntermediateNode() { Name = "default" }; + var @class = new ClassDeclarationIntermediateNode() { Name = IntermediateNodeFactory.CSharpToken("default") }; builder.Add(@class); documentNode.DocumentKind = null; @@ -346,6 +346,6 @@ public void Pass_DoesNothing_ForUnknownDocumentKind() // Assert Assert.Equal("default", @namespace.Name); - Assert.Equal("default", @class.Name); + Assert.Equal("default", @class.Name.Content); } } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/RazorPageDocumentClassifierPassTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/RazorPageDocumentClassifierPassTest.cs index 2f9dd0b0045..1cb37747198 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/RazorPageDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/RazorPageDocumentClassifierPassTest.cs @@ -199,7 +199,7 @@ public void RazorPageDocumentClassifierPass_SetsClass() Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", classNode.BaseType?.BaseType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("Test", classNode.Name); + Assert.Equal("Test", classNode.Name.Content); } [Fact] @@ -219,7 +219,7 @@ public void RazorPageDocumentClassifierPass_NullFilePath_SetsClass() Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", classNode.BaseType?.BaseType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("AspNetCore_c3b458108610c1a2aa6eede0a5685ede853e036732db515609b2a23ca15359e1", classNode.Name); + Assert.Equal("AspNetCore_c3b458108610c1a2aa6eede0a5685ede853e036732db515609b2a23ca15359e1", classNode.Name.Content); } [Theory] @@ -239,7 +239,7 @@ public void RazorPageDocumentClassifierPass_UsesRelativePathToGenerateTypeName(s var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal(expected, classNode.Name); + Assert.Equal(expected, classNode.Name.Content); } [Fact] @@ -257,7 +257,7 @@ public void RazorPageDocumentClassifierPass_UsesAbsolutePath_IfRelativePathIsNot var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("x___application_Views_Home_Index", classNode.Name); + Assert.Equal("x___application_Views_Home_Index", classNode.Name.Content); } [Fact] @@ -275,7 +275,7 @@ public void RazorPageDocumentClassifierPass_SanitizesClassName() var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("path_with_invalid_chars", classNode.Name); + Assert.Equal("path_with_invalid_chars", classNode.Name!.Content); } [Fact] diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs index 0636149efd4..2c21c9ec24e 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs @@ -54,7 +54,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsClass() Assert.NotNull(baseNode.ModelType); Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(["internal", "sealed"], classNode.Modifiers); - Assert.Equal("Test", classNode.Name); + Assert.Equal("Test", classNode.Name.Content); } [Fact] @@ -77,7 +77,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() Assert.NotNull(baseNode.ModelType); Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(["internal", "sealed"], classNode.Modifiers); - AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", classNode.Name); + AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", classNode.Name.Content); } [Theory] @@ -97,7 +97,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_UsesRelativePathToGenerate var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal(expected, classNode.Name); + Assert.Equal(expected, classNode.Name.Content); Assert.Equal(["internal", "sealed"], classNode.Modifiers); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcViewDocumentClassifierPassTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcViewDocumentClassifierPassTest.cs index 27ce64a166a..ff66cfdb4a5 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcViewDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcViewDocumentClassifierPassTest.cs @@ -86,7 +86,7 @@ public void MvcViewDocumentClassifierPass_SetsClass() Assert.NotNull(baseNode.ModelType); Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("Test", classNode.Name); + Assert.Equal("Test", classNode.Name.Content); } [Fact] @@ -109,7 +109,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() Assert.NotNull(baseNode.ModelType); Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", classNode.Name); + Assert.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", classNode.Name.Content); } [Theory] @@ -129,7 +129,7 @@ public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(str var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal(expected, classNode.Name); + Assert.Equal(expected, classNode.Name.Content); } [Fact] @@ -147,7 +147,7 @@ public void MvcViewDocumentClassifierPass_UsesAbsolutePath_IfRelativePathIsNotSe var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("x___application_Views_Home_Index", classNode.Name); + Assert.Equal("x___application_Views_Home_Index", classNode.Name.Content); } [Fact] @@ -165,7 +165,7 @@ public void MvcViewDocumentClassifierPass_SanitizesClassName() var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("path_with_invalid_chars", classNode.Name); + Assert.Equal("path_with_invalid_chars", classNode.Name.Content); } [Fact] diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/RazorPageDocumentClassifierPassTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/RazorPageDocumentClassifierPassTest.cs index 9fb27d501e6..bb5328e93e0 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/RazorPageDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/RazorPageDocumentClassifierPassTest.cs @@ -199,7 +199,7 @@ public void RazorPageDocumentClassifierPass_SetsClass() Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", classNode.BaseType?.BaseType.Content); Assert.Equal(["public"], classNode.Modifiers); - Assert.Equal("Test", classNode.Name); + Assert.Equal("Test", classNode.Name.Content); } [Fact] @@ -219,7 +219,7 @@ public void RazorPageDocumentClassifierPass_NullFilePath_SetsClass() Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", classNode.BaseType?.BaseType.Content); Assert.Equal(["public"], classNode.Modifiers); - AssertEx.Equal("AspNetCore_c3b458108610c1a2aa6eede0a5685ede853e036732db515609b2a23ca15359e1", classNode.Name); + AssertEx.Equal("AspNetCore_c3b458108610c1a2aa6eede0a5685ede853e036732db515609b2a23ca15359e1", classNode.Name.Content); } [Theory] @@ -239,7 +239,7 @@ public void RazorPageDocumentClassifierPass_UsesRelativePathToGenerateTypeName(s var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal(expected, classNode.Name); + Assert.Equal(expected, classNode.Name.Content); } [Fact] @@ -257,7 +257,7 @@ public void RazorPageDocumentClassifierPass_UsesAbsolutePath_IfRelativePathIsNot var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("x___application_Views_Home_Index", classNode.Name); + Assert.Equal("x___application_Views_Home_Index", classNode.Name.Content); } [Fact] @@ -275,7 +275,7 @@ public void RazorPageDocumentClassifierPass_SanitizesClassName() var documentNode = processor.GetDocumentNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("path_with_invalid_chars", classNode.Name); + Assert.Equal("path_with_invalid_chars", classNode.Name.Content); } [Fact] diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/CSharpCodeWriterTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/CSharpCodeWriterTest.cs index 2e31ca0ecc2..e6eb67c9084 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/CSharpCodeWriterTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/CSharpCodeWriterTest.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using Microsoft.AspNetCore.Razor.Language.Intermediate; using Roslyn.Test.Utilities; using Xunit; @@ -410,7 +411,7 @@ public void CSharpCodeWriter_RespectTabSetting() using var writer = new CodeWriter(options); // Act - writer.BuildClassDeclaration(modifiers: [], name: "C", baseType: null, interfaces: [], typeParameters: [], context: null); + writer.BuildClassDeclaration(modifiers: [], name: IntermediateNodeFactory.CSharpToken("C"), baseType: null, interfaces: [], typeParameters: [], context: null); writer.WriteField(suppressWarnings: [], modifiers: [], type: "int", name: "f"); // Assert @@ -434,7 +435,7 @@ public void CSharpCodeWriter_RespectSpaceSetting() using var writer = new CodeWriter(options); // Act - writer.BuildClassDeclaration(modifiers: [], name: "C", baseType: null, interfaces: [], typeParameters: [], context: null); + writer.BuildClassDeclaration(modifiers: [], name: IntermediateNodeFactory.CSharpToken("C"), baseType: null, interfaces: [], typeParameters: [], context: null); writer.WriteField(suppressWarnings: [], modifiers: [], type: "int", name: "f"); // Assert diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Components/ComponentDocumentClassifierPassTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Components/ComponentDocumentClassifierPassTest.cs index eb7fc612f6b..fd3aec13519 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Components/ComponentDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Components/ComponentDocumentClassifierPassTest.cs @@ -77,7 +77,7 @@ public void ComponentDocumentClassifierPass_SetsClass() Assert.Equal($"global::{ComponentsApi.ComponentBase.FullTypeName}", classNode.BaseType?.BaseType.Content); Assert.Equal(["public", "partial"], classNode.Modifiers); - Assert.Equal("Test", classNode.Name); + Assert.Equal("Test", classNode.Name.Content); } [Fact] @@ -102,7 +102,7 @@ public void ComponentDocumentClassifierPass_UsesRelativePathToGenerateTypeNameAn var namespaceNode = documentNode.GetNamespaceNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("Banner", classNode.Name); + Assert.Equal("Banner", classNode.Name.Content); Assert.Equal("MyApp.Pages.Announcements", namespaceNode.Name); } @@ -127,7 +127,7 @@ public void ComponentDocumentClassifierPass_SanitizesClassName() var namespaceNode = documentNode.GetNamespaceNode(); var classNode = documentNode.GetClassNode(); - Assert.Equal("path_with_invalid_chars", classNode.Name); + Assert.Equal("path_with_invalid_chars", classNode.Name.Content); Assert.Equal("My._App", namespaceNode.Name); } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorCSharpLoweringPhaseTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorCSharpLoweringPhaseTest.cs index 02cfcca205f..3d488f049c9 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorCSharpLoweringPhaseTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DefaultRazorCSharpLoweringPhaseTest.cs @@ -276,7 +276,7 @@ public void Execute_WritesClass() new("TKey"), new("TValue") ], - Name = "TestClass" + Name = IntermediateNodeFactory.CSharpToken("TestClass") }); // Act @@ -322,7 +322,7 @@ public void Execute_WithNullableContext_WritesClass() new("TKey"), new("TValue") ], - Name = "TestClass", + Name = IntermediateNodeFactory.CSharpToken("TestClass"), NullableContext = true }); @@ -371,7 +371,7 @@ public void Execute_WritesClass_ConstrainedGenericTypeParameters() new("TKey", "where TKey : class"), new("TValue", "where TValue : class") ], - Name = "TestClass" + Name = IntermediateNodeFactory.CSharpToken("TestClass") }); // Act diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DocumentClassifierPassBaseTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DocumentClassifierPassBaseTest.cs index 3bd8fc4d3c4..6b52dc48468 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DocumentClassifierPassBaseTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/DocumentClassifierPassBaseTest.cs @@ -200,7 +200,7 @@ public void Execute_CanInitializeDefaults() Assert.Equal("TestNamespace", @namespace.Name); var @class = SingleChild(@namespace); - Assert.Equal("TestClass", @class.Name); + Assert.Equal("TestClass", @class.Name.Content); var method = SingleChild(@class); Assert.Equal("TestMethod", method.Name); @@ -262,6 +262,11 @@ protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermed return ShouldMatch; } + protected override string GetClassName(RazorCodeDocument codeDocument) + { + return Class ?? ""; + } + protected override void OnDocumentStructureCreated( RazorCodeDocument codeDocument, NamespaceDeclarationIntermediateNode @namespace, @@ -269,7 +274,6 @@ protected override void OnDocumentStructureCreated( MethodDeclarationIntermediateNode method) { @namespace.Name = Namespace; - @class.Name = Class; @method.Name = Method; } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/MetadataAttributePassTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/MetadataAttributePassTest.cs index 6d5381f429e..d3526405f82 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/MetadataAttributePassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/MetadataAttributePassTest.cs @@ -111,7 +111,7 @@ public void Execute_NoNamespaceSet_Noops() var @class = new ClassDeclarationIntermediateNode { IsPrimaryClass = true, - Name = "Test" + Name = IntermediateNodeFactory.CSharpToken("Test") }; builder.Add(@class); @@ -133,43 +133,7 @@ public void Execute_NoNamespaceSet_Noops() Assert.Equal("/test.cshtml", checksum.Identifier); var foundClass = Assert.IsType(@namespace.Children[1]); - Assert.Equal("Test", foundClass.Name); - } - - [Fact] - public void Execute_NoClassNameSet_Noops() - { - // Arrange - var source = TestRazorSourceDocument.Create(); - var codeDocument = ProjectEngine.CreateCodeDocument(source); - - var documentNode = new DocumentIntermediateNode() - { - DocumentKind = "test", - Options = codeDocument.CodeGenerationOptions - }; - - var builder = IntermediateNodeBuilder.Create(documentNode); - var @namespace = new NamespaceDeclarationIntermediateNode - { - IsPrimaryNamespace = true, - Name = "Some.Namespace" - }; - - builder.Push(@namespace); - - var @class = new ClassDeclarationIntermediateNode - { - IsPrimaryClass = true, - }; - - builder.Add(@class); - - // Act - ProjectEngine.ExecutePass(codeDocument, documentNode); - - // Assert - SingleChild(documentNode); + Assert.Equal("Test", foundClass.Name.Content); } [Fact] @@ -193,7 +157,7 @@ public void Execute_NoDocumentKind_Noops() var @class = new ClassDeclarationIntermediateNode { IsPrimaryClass = true, - Name = "Test" + Name = IntermediateNodeFactory.CSharpToken("Test") }; builder.Add(@class); @@ -230,7 +194,7 @@ public void Execute_NoIdentifier_Noops() var @class = new ClassDeclarationIntermediateNode { IsPrimaryClass = true, - Name = "Test" + Name = IntermediateNodeFactory.CSharpToken("Test") }; builder.Add(@class); @@ -267,7 +231,7 @@ public void Execute_HasRequiredInfo_AddsItemAndSourceChecksum() var @class = new ClassDeclarationIntermediateNode { IsPrimaryClass = true, - Name = "Test", + Name = IntermediateNodeFactory.CSharpToken("Test"), }; builder.Add(@class); @@ -315,7 +279,7 @@ public void Execute_HasRequiredInfo_AndImport_AddsItemAndSourceChecksum() var @class = new ClassDeclarationIntermediateNode { IsPrimaryClass = true, - Name = "Test", + Name = IntermediateNodeFactory.CSharpToken("Test"), }; builder.Add(@class); @@ -375,7 +339,7 @@ public void Execute_SuppressMetadataSourceChecksumAttributes_DoesNotGenerateSour var @class = new ClassDeclarationIntermediateNode { IsPrimaryClass = true, - Name = "Test" + Name = IntermediateNodeFactory.CSharpToken("Test") }; builder.Add(@class); diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Intermediate/DocumentIntermediateNodeExtensionsTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Intermediate/DocumentIntermediateNodeExtensionsTest.cs index b9f05bb6701..d644e452958 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Intermediate/DocumentIntermediateNodeExtensionsTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Intermediate/DocumentIntermediateNodeExtensionsTest.cs @@ -16,7 +16,8 @@ public void FindPrimaryClass_FindsClassWithAnnotation() var document = new DocumentIntermediateNode(); var @class = new ClassDeclarationIntermediateNode { - IsPrimaryClass = true + IsPrimaryClass = true, + Name = IntermediateNodeFactory.CSharpToken("") }; var builder = IntermediateNodeBuilder.Create(document); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs index 6741b8799e5..268c59f6b34 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/CodeGeneration/CodeWriterExtensions.cs @@ -682,7 +682,7 @@ public static CSharpCodeWritingScope BuildNamespace(this CodeWriter writer, stri public static CSharpCodeWritingScope BuildClassDeclaration( this CodeWriter writer, ImmutableArray modifiers, - string name, + IntermediateToken name, BaseTypeWithModel baseType, ImmutableArray interfaces, ImmutableArray typeParameters, @@ -699,7 +699,7 @@ public static CSharpCodeWritingScope BuildClassDeclaration( writer.WriteModifierList(modifiers); writer.Write("class "); - writer.Write(name); + WriteToken(name); if (!typeParameters.IsDefaultOrEmpty) { diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs index f572e7741be..8a39c186077 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs @@ -46,19 +46,9 @@ protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermed protected override CodeTarget CreateTarget(RazorCodeDocument codeDocument) => new ComponentCodeTarget(codeDocument, TargetExtensions); - /// - protected override void OnDocumentStructureCreated( - RazorCodeDocument codeDocument, - NamespaceDeclarationIntermediateNode @namespace, - ClassDeclarationIntermediateNode @class, - MethodDeclarationIntermediateNode method) + protected override string GetClassName(RazorCodeDocument codeDocument) { - if (!codeDocument.TryGetNamespace(fallbackToRootNamespace: true, out var computedNamespace, out var computedNamespaceSpan)) - { - computedNamespace = FallbackRootNamespace; - } - - if (!TryComputeClassName(codeDocument, out var computedClass)) + if(!TryComputeClassName(codeDocument, out var computedClass)) { var checksum = ChecksumUtilities.BytesToString(codeDocument.Source.Text.GetChecksum()); computedClass = $"AspNetCore_{checksum}"; @@ -77,11 +67,25 @@ protected override void OnDocumentStructureCreated( computedClass = ComponentHelpers.MangleClassName(computedClass); } + return computedClass; + } + + /// + protected override void OnDocumentStructureCreated( + RazorCodeDocument codeDocument, + NamespaceDeclarationIntermediateNode @namespace, + ClassDeclarationIntermediateNode @class, + MethodDeclarationIntermediateNode method) + { + if (!codeDocument.TryGetNamespace(fallbackToRootNamespace: true, out var computedNamespace, out var computedNamespaceSpan)) + { + computedNamespace = FallbackRootNamespace; + } + @class.NullableContext = true; @namespace.Name = computedNamespace; @namespace.Source = computedNamespaceSpan; - @class.Name = computedClass; @class.Modifiers = CommonModifiers.PublicPartial; if (codeDocument.FileKind.IsComponentImport()) @@ -105,6 +109,8 @@ protected override void OnDocumentStructureCreated( ? ComponentConstrainedTypeParamDirective.Directive : ComponentTypeParamDirective.Directive; + var documentNode = codeDocument.GetRequiredDocumentNode(); + using var typeParameters = new PooledArrayBuilder(); foreach (var typeParamReference in documentNode.FindDirectiveReferences(directiveType)) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentGenericTypePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentGenericTypePass.cs index 05e53ea3fa8..a0486795e00 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentGenericTypePass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentGenericTypePass.cs @@ -416,7 +416,7 @@ private void CreateTypeInferenceMethod(DocumentIntermediateNode documentNode, Co { var @namespace = documentNode.FindPrimaryNamespace().AssumeNotNull().Name; @namespace = string.IsNullOrEmpty(@namespace) ? "__Blazor" : "__Blazor." + @namespace; - @namespace += "." + documentNode.FindPrimaryClass().AssumeNotNull().Name; + @namespace += "." + documentNode.FindPrimaryClass().AssumeNotNull().Name.Content; using var genericTypeConstraints = new PooledArrayBuilder(); @@ -460,12 +460,12 @@ private void CreateTypeInferenceMethod(DocumentIntermediateNode documentNode, Co var classNode = namespaceNode.Children .OfType() - .FirstOrDefault(n => n.Name == "TypeInference"); + .FirstOrDefault(n => n.Name.Content == "TypeInference"); if (classNode == null) { classNode = new ClassDeclarationIntermediateNode() { - Name = "TypeInference", + Name = IntermediateNodeFactory.CSharpToken("TypeInference"), Modifiers = CommonModifiers.InternalStatic }; namespaceNode.Children.Add(classNode); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentRenderModeDirectivePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentRenderModeDirectivePass.cs index 10b3c9ee316..e029ef34983 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentRenderModeDirectivePass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentRenderModeDirectivePass.cs @@ -48,7 +48,7 @@ protected override void ExecuteCore( // generate the inner attribute class var classDecl = new ClassDeclarationIntermediateNode { - Name = GeneratedRenderModeAttributeName, + Name = IntermediateNodeFactory.CSharpToken(GeneratedRenderModeAttributeName), BaseType = new BaseTypeWithModel($"global::{ComponentsApi.RenderModeAttribute.FullTypeName}"), Modifiers = useFileScopedClass ? CommonModifiers.FileSealed @@ -101,7 +101,7 @@ child is not DirectiveTokenIntermediateNode directiveToken var namespaceSeparator = string.IsNullOrEmpty(@namespace.Name) ? string.Empty : "."; var attributeContents = useFileScopedClass ? GeneratedRenderModeAttributeName - : $"global::{@namespace.Name}{namespaceSeparator}{@class.Name}.{GeneratedRenderModeAttributeName}"; + : $"global::{@namespace.Name}{namespaceSeparator}{@class.Name.Content}.{GeneratedRenderModeAttributeName}"; attributeNode.Children.Add( IntermediateNodeFactory.CSharpToken($"[{attributeContents}]")); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultDocumentClassifierPass.cs index 46fbc635551..af7075ee0e5 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DefaultDocumentClassifierPass.cs @@ -16,6 +16,8 @@ protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermed return true; } + protected override string GetClassName(RazorCodeDocument codeDocument) => "DefaultDocument"; + protected override void OnDocumentStructureCreated( RazorCodeDocument codeDocument, NamespaceDeclarationIntermediateNode @namespace, diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DocumentClassifierPassBase.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DocumentClassifierPassBase.cs index 567bab51936..f9f81a32910 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DocumentClassifierPassBase.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/DocumentClassifierPassBase.cs @@ -51,6 +51,8 @@ protected sealed override void ExecuteCore( Rewrite(codeDocument, documentNode); } + protected abstract string GetClassName(RazorCodeDocument codeDocument); + private void Rewrite(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) { // Rewrite the document from a flat structure to use a sensible default structure, @@ -65,7 +67,8 @@ private void Rewrite(RazorCodeDocument codeDocument, DocumentIntermediateNode do var @class = new ClassDeclarationIntermediateNode { - IsPrimaryClass = true + IsPrimaryClass = true, + Name = IntermediateNodeFactory.CSharpToken(GetClassName(codeDocument)) }; var method = new MethodDeclarationIntermediateNode diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/MetadataAttributePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/MetadataAttributePass.cs index c5a5d4eb7aa..a49e49fbbd8 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/MetadataAttributePass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/MetadataAttributePass.cs @@ -50,7 +50,7 @@ protected override void ExecuteCore( } var @class = documentNode.FindPrimaryClass(); - if (@class == null || string.IsNullOrEmpty(@class.Name)) + if (@class == null || string.IsNullOrEmpty(@class.Name.Content)) { // No class node or it's incomplete. Skip. return; @@ -73,8 +73,8 @@ protected override void ExecuteCore( documentNode.Children.Insert(0, new RazorCompiledItemAttributeIntermediateNode() { TypeName = string.IsNullOrEmpty(@namespace.Name) - ? @class.Name - : @namespace.Name + "." + @class.Name, + ? @class.Name.Content + : @namespace.Name + "." + @class.Name.Content, Kind = documentNode.DocumentKind, Identifier = identifier, }); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/ClassDeclarationIntermediateNode.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/ClassDeclarationIntermediateNode.cs index c5e01ef0e66..434290c5b32 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/ClassDeclarationIntermediateNode.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/ClassDeclarationIntermediateNode.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate; public sealed class ClassDeclarationIntermediateNode : MemberDeclarationIntermediateNode { - public string? Name { get; set; } + public required IntermediateToken Name { get; set; } public BaseTypeWithModel? BaseType { get; set; } public ImmutableArray Modifiers { get; set => field = value.NullToEmpty(); } = []; public ImmutableArray Interfaces { get; set => field = value.NullToEmpty(); } = []; @@ -24,8 +24,8 @@ public override void Accept(IntermediateNodeVisitor visitor) public override void FormatNode(IntermediateNodeFormatter formatter) { - formatter.WriteContent(Name); - formatter.WriteProperty(nameof(Name), Name); + formatter.WriteContent(Name?.Content); + formatter.WriteProperty(nameof(Name), Name?.Content); formatter.WriteProperty(nameof(Interfaces), string.Join(", ", Interfaces.Select(i => i.Content))); formatter.WriteProperty(nameof(Modifiers), string.Join(", ", Modifiers)); formatter.WriteProperty(nameof(TypeParameters), string.Join(", ", TypeParameters.Select(t => t.Name.Content))); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs index 3427898e1a1..14a65dd724a 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs @@ -378,7 +378,7 @@ private static void AddDefaultFeatures(ImmutableArray.Builder fea features.Add(configurationFeature); configurationFeature.ConfigureClass.Add((document, @class) => { - @class.Name = "Template"; + @class.Name = IntermediateNodeFactory.CSharpToken("Template"); @class.Modifiers = CommonModifiers.Public; }); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/MvcViewDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/MvcViewDocumentClassifierPass.cs index e21ca2c6eaf..fef64d2032a 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/MvcViewDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/MvcViewDocumentClassifierPass.cs @@ -14,28 +14,31 @@ public sealed class MvcViewDocumentClassifierPass : DocumentClassifierPassBase protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true; - protected override void OnDocumentStructureCreated( - RazorCodeDocument codeDocument, - NamespaceDeclarationIntermediateNode @namespace, - ClassDeclarationIntermediateNode @class, - MethodDeclarationIntermediateNode method) + protected override string GetClassName(RazorCodeDocument codeDocument) { - base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); - - @namespace.Name = "AspNetCore"; - var filePath = codeDocument.Source.RelativePath ?? codeDocument.Source.FilePath; if (string.IsNullOrEmpty(filePath)) { // It's possible for a Razor document to not have a file path. // Eg. When we try to generate code for an in memory document like default imports. var checksum = ChecksumUtilities.BytesToString(codeDocument.Source.Text.GetChecksum()); - @class.Name = $"AspNetCore_{checksum}"; + return $"AspNetCore_{checksum}"; } else { - @class.Name = CSharpIdentifier.GetClassNameFromPath(filePath); + return CSharpIdentifier.GetClassNameFromPath(filePath); } + } + + protected override void OnDocumentStructureCreated( + RazorCodeDocument codeDocument, + NamespaceDeclarationIntermediateNode @namespace, + ClassDeclarationIntermediateNode @class, + MethodDeclarationIntermediateNode method) + { + base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); + + @namespace.Name = "AspNetCore"; @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", location: null); @class.Modifiers = CommonModifiers.Public; diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/AssemblyAttributeInjectionPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/AssemblyAttributeInjectionPass.cs index 7caf0ade170..3d2a9707bc2 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/AssemblyAttributeInjectionPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/AssemblyAttributeInjectionPass.cs @@ -33,15 +33,15 @@ protected override void ExecuteCore( } var @class = documentNode.FindPrimaryClass(); - if (@class == null || string.IsNullOrEmpty(@class.Name)) + if (@class == null || string.IsNullOrEmpty(@class.Name.Content)) { // No class node or it's incomplete. Skip. return; } var generatedTypeName = string.IsNullOrEmpty(@namespace.Name) - ? @class.Name - : $"{@namespace.Name}.{@class.Name}"; + ? @class.Name.Content + : $"{@namespace.Name}.{@class.Name.Content}"; // The MVC attributes require a relative path to be specified so that we can make a view engine path. // We can't use a rooted path because we don't know what the project root is. diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/MvcViewDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/MvcViewDocumentClassifierPass.cs index 1cb94c2f8a4..2f9dab8237c 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/MvcViewDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/MvcViewDocumentClassifierPass.cs @@ -14,28 +14,31 @@ public sealed class MvcViewDocumentClassifierPass : DocumentClassifierPassBase protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true; - protected override void OnDocumentStructureCreated( - RazorCodeDocument codeDocument, - NamespaceDeclarationIntermediateNode @namespace, - ClassDeclarationIntermediateNode @class, - MethodDeclarationIntermediateNode method) + protected override string GetClassName(RazorCodeDocument codeDocument) { - base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); - - @namespace.Name = "AspNetCore"; - var filePath = codeDocument.Source.RelativePath ?? codeDocument.Source.FilePath; if (string.IsNullOrEmpty(filePath)) { // It's possible for a Razor document to not have a file path. // Eg. When we try to generate code for an in memory document like default imports. var checksum = ChecksumUtilities.BytesToString(codeDocument.Source.Text.GetChecksum()); - @class.Name = $"AspNetCore_{checksum}"; + return $"AspNetCore_{checksum}"; } else { - @class.Name = CSharpIdentifier.GetClassNameFromPath(filePath); + return CSharpIdentifier.GetClassNameFromPath(filePath); } + } + + protected override void OnDocumentStructureCreated( + RazorCodeDocument codeDocument, + NamespaceDeclarationIntermediateNode @namespace, + ClassDeclarationIntermediateNode @class, + MethodDeclarationIntermediateNode method) + { + base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); + + @namespace.Name = "AspNetCore"; @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", location: null); @class.Modifiers = CommonModifiers.Public; diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs index 24567288362..4b92e1554e3 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/RazorPageDocumentClassifierPass.cs @@ -44,30 +44,33 @@ protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermed return PageDirective.TryGetPageDirective(documentNode, out _); } - protected override void OnDocumentStructureCreated( - RazorCodeDocument codeDocument, - NamespaceDeclarationIntermediateNode @namespace, - ClassDeclarationIntermediateNode @class, - MethodDeclarationIntermediateNode method) + protected override string GetClassName(RazorCodeDocument codeDocument) { - base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); - - @namespace.Name = "AspNetCore"; - - @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); - var filePath = codeDocument.Source.RelativePath ?? codeDocument.Source.FilePath; if (string.IsNullOrEmpty(filePath)) { // It's possible for a Razor document to not have a file path. // Eg. When we try to generate code for an in memory document like default imports. var checksum = ChecksumUtilities.BytesToString(codeDocument.Source.Text.GetChecksum()); - @class.Name = $"AspNetCore_{checksum}"; + return $"AspNetCore_{checksum}"; } else { - @class.Name = CSharpIdentifier.GetClassNameFromPath(filePath); + return CSharpIdentifier.GetClassNameFromPath(filePath); } + } + + protected override void OnDocumentStructureCreated( + RazorCodeDocument codeDocument, + NamespaceDeclarationIntermediateNode @namespace, + ClassDeclarationIntermediateNode @class, + MethodDeclarationIntermediateNode method) + { + base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); + + @namespace.Name = "AspNetCore"; + + @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); @class.Modifiers = CommonModifiers.Public; diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ModelDirective.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ModelDirective.cs index 068ce8cdad8..8e9ba52e304 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ModelDirective.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ModelDirective.cs @@ -62,7 +62,7 @@ private static IntermediateToken GetModelType(DocumentIntermediateNode document, if (document.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind) { - return IntermediateNodeFactory.CSharpToken(visitor.Class!.Name!); + return visitor.Class!.Name!; } else { diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/MvcViewDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/MvcViewDocumentClassifierPass.cs index 4dfe886fb50..28860d92c60 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/MvcViewDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/MvcViewDocumentClassifierPass.cs @@ -23,6 +23,22 @@ public MvcViewDocumentClassifierPass(bool useConsolidatedMvcViews) _useConsolidatedMvcViews = useConsolidatedMvcViews; } + protected override string GetClassName(RazorCodeDocument codeDocument) + { + var filePath = codeDocument.Source.RelativePath ?? codeDocument.Source.FilePath; + if (string.IsNullOrEmpty(filePath)) + { + // It's possible for a Razor document to not have a file path. + // Eg. When we try to generate code for an in memory document like default imports. + var checksum = ChecksumUtilities.BytesToString(codeDocument.Source.Text.GetChecksum()); + return $"AspNetCore_{checksum}"; + } + else + { + return CSharpIdentifier.GetClassNameFromPath(filePath); + } + } + protected override void OnDocumentStructureCreated( RazorCodeDocument codeDocument, NamespaceDeclarationIntermediateNode @namespace, @@ -40,17 +56,6 @@ protected override void OnDocumentStructureCreated( @namespace.Name = namespaceName; } - if (!codeDocument.TryComputeClassName(out var className)) - { - // It's possible for a Razor document to not have a file path. - // Eg. When we try to generate code for an in memory document like default imports. - var checksum = ChecksumUtilities.BytesToString(codeDocument.Source.Text.GetChecksum()); - @class.Name = "AspNetCore_" + checksum; - } - else - { - @class.Name = className; - } @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", location: null); @class.Modifiers = _useConsolidatedMvcViews diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs index 2bb98f87518..e9c5509afca 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs @@ -53,6 +53,21 @@ protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermed return PageDirective.TryGetPageDirective(documentNode, out _); } + protected override string GetClassName(RazorCodeDocument codeDocument) + { + if (!codeDocument.TryComputeClassName(out var className)) + { + // It's possible for a Razor document to not have a file path. + // Eg. When we try to generate code for an in memory document like default imports. + var checksum = ChecksumUtilities.BytesToString(codeDocument.Source.Text.GetChecksum()); + return $"AspNetCore_{checksum}"; + } + else + { + return className; + } + } + protected override void OnDocumentStructureCreated( RazorCodeDocument codeDocument, NamespaceDeclarationIntermediateNode @namespace, @@ -70,18 +85,6 @@ protected override void OnDocumentStructureCreated( @namespace.Name = namespaceName; } - if (!codeDocument.TryComputeClassName(out var className)) - { - // It's possible for a Razor document to not have a file path. - // Eg. When we try to generate code for an in memory document like default imports. - var checksum = ChecksumUtilities.BytesToString(codeDocument.Source.Text.GetChecksum()); - @class.Name = $"AspNetCore_{checksum}"; - } - else - { - @class.Name = className; - } - @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); @class.Modifiers = _useConsolidatedMvcViews diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperPass.cs index 572e3121da3..bf01d704cc8 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperPass.cs @@ -163,8 +163,8 @@ public bool Add(TagHelperDescriptor tagHelper) var className = $"__Generated__{viewComponentName}ViewComponentTagHelper"; var fullyQualifiedName = !Namespace.Name.IsNullOrEmpty() - ? $"{Namespace.Name}.{Class.Name}.{className}" - : $"{Namespace.Name}{Class.Name}.{className}"; + ? $"{Namespace.Name}.{Class.Name.Content}.{className}" + : $"{Namespace.Name}{Class.Name.Content}.{className}"; var fieldName = $"__{viewComponentName}ViewComponentTagHelper"; _tagHelpers.Add(tagHelper, (className, fullyQualifiedName, fieldName)); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtensionBase.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtensionBase.cs index 40bad3364c6..b060bcc1eef 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtensionBase.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtensionBase.cs @@ -53,7 +53,7 @@ public void WriteViewComponentTagHelper(CodeRenderingContext context, ViewCompon // Initialize declaration. using (context.CodeWriter.BuildClassDeclaration( CommonModifiers.Public, - node.ClassName, + IntermediateNodeFactory.CSharpToken(node.ClassName), new BaseTypeWithModel(ViewComponentsApi.TagHelper.FullTypeName), interfaces: default, typeParameters: default, diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeWriter.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeWriter.cs index b4684586b47..8d2de8be9c2 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeWriter.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntermediateNodeWriter.cs @@ -41,7 +41,7 @@ public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node var entries = new List() { string.Join(" ", node.Modifiers), - node.Name, + node.Name.Content, node.BaseType is { } baseType ? $"{baseType.BaseType.Content}{baseType.GreaterThan?.Content}{baseType.ModelType?.Content}{baseType.LessThan?.Content}" : "", string.Join(", ", node.Interfaces.Select(i => i.Content)) }; diff --git a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineBuilderExtensions.cs b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineBuilderExtensions.cs index 10761e45eb8..c6d491ec32f 100644 --- a/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineBuilderExtensions.cs +++ b/src/Shared/Microsoft.AspNetCore.Razor.Test.Common/Language/RazorProjectEngineBuilderExtensions.cs @@ -63,7 +63,7 @@ public static RazorProjectEngineBuilder ConfigureDocumentClassifier(this RazorPr feature.ConfigureClass.Add((RazorCodeDocument codeDocument, ClassDeclarationIntermediateNode node) => { - node.Name = testFileName.Replace('/', '_'); + node.Name = IntermediateNodeFactory.CSharpToken(testFileName.Replace('/', '_')); node.Modifiers = ["public"]; }); From 98d7a6c1fbe297b0607c7730382e14d0f1d91e7d Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Thu, 22 Jan 2026 17:30:03 -0800 Subject: [PATCH 2/5] Add a component class name directive that allows for naming the generated component --- .../ComponentDirectiveIntegrationTest.cs | 80 ++++++++++++++++++- .../src/Language/ComponentResources.resx | 11 ++- .../Components/ComponentClassNameDirective.cs | 32 ++++++++ .../ComponentClassNameDirectivePass.cs | 37 +++++++++ .../src/Language/RazorProjectEngine.cs | 5 ++ 5 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentClassNameDirective.cs create mode 100644 src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentClassNameDirectivePass.cs diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDirectiveIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDirectiveIntegrationTest.cs index 9ec30ba0ba9..caaeb02873c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDirectiveIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentDirectiveIntegrationTest.cs @@ -97,7 +97,85 @@ public void SupportsInjectDirective() .Where(p => p.GetAttributes().Any(a => a.AttributeClass.Name == "InjectAttribute")); Assert.Collection(injectableProperties.OrderBy(p => p.Name), s => AssertEx.Equal("private TestNamespace.IMyService1 Test.TestComponent.MyService1 { get; set; }", s.ToTestDisplayString()), - s => AssertEx.Equal("private TestNamespace.IMyService2 Test.TestComponent.MyService2 { get; set; }", s.ToTestDisplayString())); + s => AssertEx.Equal("private TestNamespace.IMyService2 Test.TestComponent.MyService2 { get; set; }", s.ToTestDisplayString())); +} + + [Fact] + public void SupportsClassNameDirective() + { + // Arrange/Act + var assemblyResult = CompileToAssembly("TestComponent.razor", + "@classname MyCustomComponent\n" + + "Hello"); + + // Assert + var component = assemblyResult.Compilation.GetTypeByMetadataName("Test.MyCustomComponent"); + Assert.NotNull(component); + AssertEx.Equal("Test.MyCustomComponent", component.ToTestDisplayString()); + } + + [Fact] + public void MultipleClassNameDirectives_ProducesError() + { + // Arrange/Act + var cSharpResult = CompileToCSharp( + cshtmlRelativePath: "TestComponent.razor", + cshtmlContent: "@classname FirstName\n" + + "@classname SecondName\n" + + "Hello"); + + // Assert - should have an error for duplicate directive + var diagnostic = cSharpResult.RazorDiagnostics.Single(); + Assert.Equal("RZ2001", diagnostic.Id); + Assert.Contains("classname", diagnostic.GetMessage()); + } + + [Fact] + public void ClassNameDirective_NotAvailableInNonPreviewLanguageVersion() + { + // Arrange - Use an earlier language version + var configuration = RazorConfiguration.Default with { LanguageVersion = RazorLanguageVersion.Version_10_0 }; + + // Act + var cSharpResult = CompileToCSharp( + cshtmlRelativePath: "TestComponent.razor", + cshtmlContent: "@classname MyCustomComponent\nHello", + configuration: configuration); + + // Assert - the directive is not recognized, so it's treated as a C# expression + // which results in generated code that references an undefined 'classname' identifier. + // The component class is still generated with the original file name. + Assert.Contains("classname", cSharpResult.Code); + } + + [Fact] + public void ClassNameDirective_WithTypeParam() + { + // Arrange/Act + var assemblyResult = CompileToAssembly("TestComponent.razor", + """ + @classname MyGenericComponent + @typeparam TItem + +
@typeof(TItem).Name
+ + @code { + [Parameter] public TItem Item { get; set; } + } + """); + + // Assert - component should have custom name and be generic + var component = assemblyResult.Compilation.GetTypeByMetadataName("Test.MyGenericComponent`1"); + Assert.NotNull(component); + AssertEx.Equal("Test.MyGenericComponent", component.ToTestDisplayString()); + + // Verify type parameter + var typeParam = Assert.Single(component.TypeParameters); + AssertEx.Equal("TItem", typeParam.Name); + + // Verify the Item property exists with the correct type + var itemProperty = component.GetMembers().OfType().Single(p => p.Name == "Item"); + AssertEx.Equal("TItem", itemProperty.Type.ToTestDisplayString()); } [Fact] diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/ComponentResources.resx b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/ComponentResources.resx index 900c52162b9..6c77cbf04a5 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/ComponentResources.resx +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/ComponentResources.resx @@ -126,6 +126,15 @@ Specifies the C# attribute that will be applied to the current class. + + Specifies the class name for the generated component class. + + + The name of the generated component class. + + + ClassName + Binds the provided expression to the '{0}' property and a change event delegate to the '{1}' property of the component. @@ -255,4 +264,4 @@ type parameter - \ No newline at end of file + diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentClassNameDirective.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentClassNameDirective.cs new file mode 100644 index 00000000000..a401e31c8af --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentClassNameDirective.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using System; + +namespace Microsoft.AspNetCore.Razor.Language.Components; + +internal static class ComponentClassNameDirective +{ + public static readonly DirectiveDescriptor Directive = DirectiveDescriptor.CreateDirective( + "classname", + DirectiveKind.SingleLine, + builder => + { + builder.AddMemberToken(ComponentResources.ClassNameDirective_Token_Name, ComponentResources.ClassNameDirective_Token_Description); + builder.Usage = DirectiveUsage.FileScopedSinglyOccurring; + builder.Description = ComponentResources.ClassNameDirective_Description; + }); + + public static void Register(RazorProjectEngineBuilder builder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + builder.AddDirective(Directive, RazorFileKind.Component); + builder.Features.Add(new ComponentClassNameDirectivePass()); + } +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentClassNameDirectivePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentClassNameDirectivePass.cs new file mode 100644 index 00000000000..a9dc0e771ed --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentClassNameDirectivePass.cs @@ -0,0 +1,37 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Linq; +using System.Threading; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Razor.Language.Components; + +internal sealed class ComponentClassNameDirectivePass : IntermediateNodePassBase, IRazorDirectiveClassifierPass +{ + protected override void ExecuteCore( + RazorCodeDocument codeDocument, + DocumentIntermediateNode documentNode, + CancellationToken cancellationToken) + { + var @class = documentNode.FindPrimaryClass(); + if (@class == null) + { + return; + } + + var directives = documentNode.FindDirectiveReferences(ComponentClassNameDirective.Directive); + if (directives.Length == 0) + { + return; + } + + var token = directives[0].Node.Tokens.FirstOrDefault(); + if (token == null) + { + return; + } + + @class.Name = IntermediateNodeFactory.CSharpToken(token.Content, token.Source); + } +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs index 14a65dd724a..6dcc7776f6b 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs @@ -406,6 +406,11 @@ private static void AddComponentFeatures(RazorProjectEngineBuilder builder, Razo ComponentLayoutDirective.Register(builder); ComponentPageDirective.Register(builder); + if (razorLanguageVersion >= RazorLanguageVersion.Preview) + { + ComponentClassNameDirective.Register(builder); + } + if (razorLanguageVersion >= RazorLanguageVersion.Version_6_0) { ComponentConstrainedTypeParamDirective.Register(builder); From 7b2853f7069bc6f9d4931cadd9786870d620a903 Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Thu, 22 Jan 2026 17:54:13 -0800 Subject: [PATCH 3/5] Add integration tests for classname --- .../ComponentCodeGenerationTestBase.cs | 133 ++++++++++++++++++ .../TestComponent.codegen.cs | 59 ++++++++ .../TestComponent.ir.txt | 20 +++ .../TestComponent.mappings.txt | 10 ++ .../TestComponent.codegen.cs | 41 ++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 24 ++++ .../TestComponent.mappings.txt | 5 + .../TestComponent.codegen.cs | 31 ++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 22 +++ .../TestComponent.codegen.cs | 31 ++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 22 +++ .../TestComponent.codegen.cs | 79 +++++++++++ .../TestComponent.ir.txt | 24 ++++ .../TestComponent.mappings.txt | 15 ++ .../TestComponent.codegen.cs | 75 ++++++++++ .../TestComponent.ir.txt | 22 +++ .../TestComponent.mappings.txt | 20 +++ .../TestComponent.codegen.cs | 88 ++++++++++++ .../TestComponent.ir.txt | 27 ++++ .../TestComponent.mappings.txt | 31 ++++ .../TestComponent.codegen.cs | 41 ++++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 24 ++++ .../TestComponent.mappings.txt | 5 + .../TestComponent.codegen.cs | 34 +++++ .../TestComponent.ir.txt | 10 ++ .../TestComponent.mappings.txt | 10 ++ .../TestComponent.codegen.cs | 25 ++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 12 ++ .../TestComponent.codegen.cs | 26 ++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 13 ++ .../TestComponent.codegen.cs | 26 ++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 13 ++ .../TestComponent.codegen.cs | 44 ++++++ .../TestComponent.ir.txt | 13 ++ .../TestComponent.mappings.txt | 20 +++ .../TestComponent.codegen.cs | 49 +++++++ .../TestComponent.ir.txt | 11 ++ .../TestComponent.mappings.txt | 20 +++ .../TestComponent.codegen.cs | 60 ++++++++ .../TestComponent.ir.txt | 14 ++ .../TestComponent.mappings.txt | 31 ++++ .../TestComponent.codegen.cs | 26 ++++ .../TestComponent.diagnostics.txt | 1 + .../TestComponent.ir.txt | 14 ++ 51 files changed, 1328 insertions(+) create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.diagnostics.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_With_Periods/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 cb969d332a5..a8a9ff1dbea 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -13018,5 +13018,138 @@ @inject float Value5 CompileToAssembly(generated); } + #endregion + + #region ClassName + + [IntegrationTestFact] + public void ClassName_Directive_Basic() + { + var generated = CompileToCSharp(""" + @classname MyCustomComponent + + + """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [IntegrationTestFact] + public void ClassName_Directive_Empty() + { + var generated = CompileToCSharp(""" + @classname +

Hello World

+ """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + + [IntegrationTestFact] + public void ClassName_Directive_InvalidClassName() + { + var generated = CompileToCSharp(""" + @classname 123class +

Hello World

+ """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [IntegrationTestFact] + public void ClassName_Directive_InvalidClassName2() + { + var generated = CompileToCSharp(""" + @classname class +

Hello World

+ """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [IntegrationTestFact] + public void ClassName_Directive_With_Periods() + { + var generated = CompileToCSharp(""" + @classname My.Custom.Component +

Hello World

+ """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [IntegrationTestFact] + public void ClassName_Directive_WithTypeParam() + { + var generated = CompileToCSharp(""" + @classname MyGenericComponent + @typeparam TItem + + + + @code { + [Parameter] + public TItem Item { get; set; } + } + """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [IntegrationTestFact] + public void ClassName_Directive_WithNamespace() + { + var generated = CompileToCSharp(""" + @classname MyCustomComponent + @namespace Custom.Namespace + + + + """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [IntegrationTestFact] + public void ClassName_Directive_WithOtherDirectives() + { + var generated = CompileToCSharp(""" + @page "/my-page" + @classname MyPageComponent + @using System.Collections.Generic + + + """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + + #endregion } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.codegen.cs new file mode 100644 index 00000000000..5c178012290 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.codegen.cs @@ -0,0 +1,59 @@ +// +#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 +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +MyCustomComponent + +#line default +#line hidden +#nullable disable + : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +global::System.Object MyCustomComponent = null!; + +#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) + { + __builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => { + } + )); +#nullable restore +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = typeof(global::Test.MyCustomComponent); + +#line default +#line hidden +#nullable disable + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.ir.txt new file mode 100644 index 00000000000..aecaf6dbc2a --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.ir.txt @@ -0,0 +1,20 @@ +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 - MyCustomComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + DesignTimeDirective - + DirectiveToken - (11:0,11 [17] x:\dir\subdir\Test\TestComponent.cshtml) - MyCustomComponent + 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 + HtmlContent - (30:1,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (30:1,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + Component - (32:2,0 [21] x:\dir\subdir\Test\TestComponent.cshtml) - MyCustomComponent diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.mappings.txt new file mode 100644 index 00000000000..2ae67aaf2ee --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (11:0,11 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|MyCustomComponent| +Generated Location: (448:16,0 [17] ) +|MyCustomComponent| + +Source Location: (11:0,11 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|MyCustomComponent| +Generated Location: (837:29,22 [17] ) +|MyCustomComponent| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.codegen.cs new file mode 100644 index 00000000000..47931c37eec --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.codegen.cs @@ -0,0 +1,41 @@ +// +#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)(() => { +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + + +#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/ClassName_Directive_Empty/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..383a8c067a3 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,12): Error RZ1015: The 'classname' directive expects an identifier. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.ir.txt new file mode 100644 index 00000000000..435f5023278 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.ir.txt @@ -0,0 +1,24 @@ +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 - (11:0,11 [0] x:\dir\subdir\Test\TestComponent.cshtml) - + 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 [11] x:\dir\subdir\Test\TestComponent.cshtml) - classname + DirectiveToken - (11:0,11 [0] x:\dir\subdir\Test\TestComponent.cshtml) - + HtmlContent - (11:0,11 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (11:0,11 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + MarkupElement - (13:1,0 [20] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (17:1,4 [11] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (17:1,4 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello World diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.mappings.txt new file mode 100644 index 00000000000..ee23eb6085c --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (11:0,11 [0] x:\dir\subdir\Test\TestComponent.cshtml) +|| +Generated Location: (683:21,0 [0] ) +|| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.codegen.cs new file mode 100644 index 00000000000..02c715203ff --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/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/ClassName_Directive_InvalidClassName/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..383a8c067a3 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,12): Error RZ1015: The 'classname' directive expects an identifier. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.ir.txt new file mode 100644 index 00000000000..4ed92fb4278 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.ir.txt @@ -0,0 +1,22 @@ +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 [11] x:\dir\subdir\Test\TestComponent.cshtml) - classname + HtmlContent - (11:0,11 [10] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (11:0,11 [10] x:\dir\subdir\Test\TestComponent.cshtml) - Html - 123class\n + MarkupElement - (21:1,0 [20] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (25:1,4 [11] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (25:1,4 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello World diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.codegen.cs new file mode 100644 index 00000000000..02c715203ff --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/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/ClassName_Directive_InvalidClassName2/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..383a8c067a3 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,12): Error RZ1015: The 'classname' directive expects an identifier. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.ir.txt new file mode 100644 index 00000000000..6be70e14914 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.ir.txt @@ -0,0 +1,22 @@ +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 [11] x:\dir\subdir\Test\TestComponent.cshtml) - classname + HtmlContent - (11:0,11 [7] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (11:0,11 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - class\n + MarkupElement - (18:1,0 [20] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (22:1,4 [11] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (22:1,4 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello World diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.codegen.cs new file mode 100644 index 00000000000..a0c9496cefe --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.codegen.cs @@ -0,0 +1,79 @@ +// +#pragma warning disable 1591 +namespace Custom.Namespace +{ + #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 +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +MyCustomComponent + +#line default +#line hidden +#nullable disable + : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +global::System.Object MyCustomComponent = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" +global::System.Object __typeHelper = nameof(Custom.Namespace); + +#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) + { + __builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => { + } + )); +#nullable restore +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = typeof(global::Custom.Namespace.MyCustomComponent); + +#line default +#line hidden +#nullable disable + __builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => { + } + )); +#nullable restore +#line 5 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = typeof(global::Custom.Namespace.MyCustomComponent); + +#line default +#line hidden +#nullable disable + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.ir.txt new file mode 100644 index 00000000000..51a82394261 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.ir.txt @@ -0,0 +1,24 @@ +Document - + NamespaceDeclaration - (41:1,11 [16] x:\dir\subdir\Test\TestComponent.cshtml) - Custom.Namespace + 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 - MyCustomComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + DesignTimeDirective - + DirectiveToken - (11:0,11 [17] x:\dir\subdir\Test\TestComponent.cshtml) - MyCustomComponent + DirectiveToken - (41:1,11 [16] x:\dir\subdir\Test\TestComponent.cshtml) - Custom.Namespace + 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 + HtmlContent - (59:2,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (59:2,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + Component - (61:3,0 [21] x:\dir\subdir\Test\TestComponent.cshtml) - MyCustomComponent + HtmlContent - (82:3,21 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (82:3,21 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + Component - (84:4,0 [38] x:\dir\subdir\Test\TestComponent.cshtml) - Custom.Namespace.MyCustomComponent diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.mappings.txt new file mode 100644 index 00000000000..52fc988101d --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.mappings.txt @@ -0,0 +1,15 @@ +Source Location: (11:0,11 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|MyCustomComponent| +Generated Location: (460:16,0 [17] ) +|MyCustomComponent| + +Source Location: (11:0,11 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|MyCustomComponent| +Generated Location: (849:29,22 [17] ) +|MyCustomComponent| + +Source Location: (41:1,11 [16] x:\dir\subdir\Test\TestComponent.cshtml) +|Custom.Namespace| +Generated Location: (1109:39,44 [16] ) +|Custom.Namespace| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.codegen.cs new file mode 100644 index 00000000000..ea75c2cd594 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.codegen.cs @@ -0,0 +1,75 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; +#nullable restore +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" +using System.Collections.Generic; + +#line default +#line hidden +#nullable disable + [global::Microsoft.AspNetCore.Components.RouteAttribute("/my-page")] + #nullable restore + public partial class +#nullable restore +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" +MyPageComponent + +#line default +#line hidden +#nullable disable + : 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 = "/my-page"; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" +global::System.Object MyPageComponent = null!; + +#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) + { + __builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => { + } + )); +#nullable restore +#line 5 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = typeof(global::Test.MyPageComponent); + +#line default +#line hidden +#nullable disable + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.ir.txt new file mode 100644 index 00000000000..fd593519b1f --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.ir.txt @@ -0,0 +1,22 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [20] ) - global::System + 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 + UsingDirective - (47:2,1 [32] x:\dir\subdir\Test\TestComponent.cshtml) - System.Collections.Generic + RouteAttributeExtensionNode - (6:0,6 [10] x:\dir\subdir\Test\TestComponent.cshtml) - "/my-page" + ClassDeclaration - - public partial - MyPageComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + DesignTimeDirective - + DirectiveToken - (6:0,6 [10] x:\dir\subdir\Test\TestComponent.cshtml) - "/my-page" + DirectiveToken - (29:1,11 [15] x:\dir\subdir\Test\TestComponent.cshtml) - MyPageComponent + 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 + HtmlContent - (79:2,33 [4] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (79:2,33 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + Component - (83:4,0 [19] x:\dir\subdir\Test\TestComponent.cshtml) - MyPageComponent diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.mappings.txt new file mode 100644 index 00000000000..4e51abb1df2 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (47:2,1 [32] x:\dir\subdir\Test\TestComponent.cshtml) +|using System.Collections.Generic| +Generated Location: (314:11,0 [32] ) +|using System.Collections.Generic| + +Source Location: (29:1,11 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|MyPageComponent| +Generated Location: (593:21,0 [15] ) +|MyPageComponent| + +Source Location: (6:0,6 [10] x:\dir\subdir\Test\TestComponent.cshtml) +|"/my-page"| +Generated Location: (1024:35,37 [10] ) +|"/my-page"| + +Source Location: (29:1,11 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|MyPageComponent| +Generated Location: (1247:45,22 [15] ) +|MyPageComponent| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.codegen.cs new file mode 100644 index 00000000000..66560be3cf5 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.codegen.cs @@ -0,0 +1,88 @@ +// +#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 +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +MyGenericComponent + +#line default +#line hidden +#nullable disable + < +#nullable restore +#line 2 "x:\dir\subdir\Test\TestComponent.cshtml" +TItem + +#line default +#line hidden +#nullable disable + > : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +global::System.Object MyGenericComponent = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { + } + ))(); + } + #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) + { + __o = typeof( +#nullable restore +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" + string + +#line default +#line hidden +#nullable disable + ); + __builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => { + } + )); +#nullable restore +#line 4 "x:\dir\subdir\Test\TestComponent.cshtml" +__o = typeof(global::Test.MyGenericComponent<>); + +#line default +#line hidden +#nullable disable + } + #pragma warning restore 1998 +#nullable restore +#line 6 "x:\dir\subdir\Test\TestComponent.cshtml" + + [Parameter] + public TItem Item { get; set; } + +#line default +#line hidden +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.ir.txt new file mode 100644 index 00000000000..58aeb55d566 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.ir.txt @@ -0,0 +1,27 @@ +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 - MyGenericComponent - global::Microsoft.AspNetCore.Components.ComponentBase - - TItem + DesignTimeDirective - + DirectiveToken - (11:0,11 [18] x:\dir\subdir\Test\TestComponent.cshtml) - MyGenericComponent + DirectiveToken - (42:1,11 [5] x:\dir\subdir\Test\TestComponent.cshtml) - TItem + 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 + HtmlContent - (49:2,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (49:2,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + Component - (51:3,0 [37] x:\dir\subdir\Test\TestComponent.cshtml) - MyGenericComponent + ComponentTypeArgument - (78:3,27 [6] x:\dir\subdir\Test\TestComponent.cshtml) - TItem + LazyIntermediateToken - (78:3,27 [6] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - string + HtmlContent - (88:3,37 [4] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (88:3,37 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + CSharpCode - (99:5,7 [56] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (99:5,7 [56] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n [Parameter]\n public TItem Item { get; set; }\n diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.mappings.txt new file mode 100644 index 00000000000..6940352abbb --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.mappings.txt @@ -0,0 +1,31 @@ +Source Location: (11:0,11 [18] x:\dir\subdir\Test\TestComponent.cshtml) +|MyGenericComponent| +Generated Location: (448:16,0 [18] ) +|MyGenericComponent| + +Source Location: (42:1,11 [5] x:\dir\subdir\Test\TestComponent.cshtml) +|TItem| +Generated Location: (595:24,0 [5] ) +|TItem| + +Source Location: (11:0,11 [18] x:\dir\subdir\Test\TestComponent.cshtml) +|MyGenericComponent| +Generated Location: (973:37,22 [18] ) +|MyGenericComponent| + +Source Location: (78:3,27 [6] x:\dir\subdir\Test\TestComponent.cshtml) +|string| +Generated Location: (1614:58,27 [6] ) +|string| + +Source Location: (99:5,7 [56] x:\dir\subdir\Test\TestComponent.cshtml) +| + [Parameter] + public TItem Item { get; set; } +| +Generated Location: (2147:78,7 [56] ) +| + [Parameter] + public TItem Item { get; set; } +| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.codegen.cs new file mode 100644 index 00000000000..e8e8d1ffe96 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.codegen.cs @@ -0,0 +1,41 @@ +// +#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)(() => { +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +global::System.Object My = null!; + +#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/ClassName_Directive_With_Periods/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..65f527607dc --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,14): Error RZ1017: Unexpected literal following the 'classname' directive. Expected 'line break'. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.ir.txt new file mode 100644 index 00000000000..6862ef426b1 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.ir.txt @@ -0,0 +1,24 @@ +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 - (11:0,11 [2] x:\dir\subdir\Test\TestComponent.cshtml) - My + 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 [13] x:\dir\subdir\Test\TestComponent.cshtml) - classname + DirectiveToken - (11:0,11 [2] x:\dir\subdir\Test\TestComponent.cshtml) - My + HtmlContent - (13:0,13 [19] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (13:0,13 [19] x:\dir\subdir\Test\TestComponent.cshtml) - Html - .Custom.Component\n + MarkupElement - (32:1,0 [20] x:\dir\subdir\Test\TestComponent.cshtml) - h1 + HtmlContent - (36:1,4 [11] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (36:1,4 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello World diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.mappings.txt new file mode 100644 index 00000000000..0f3daf42ea5 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ClassName_Directive_With_Periods/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (11:0,11 [2] x:\dir\subdir\Test\TestComponent.cshtml) +|My| +Generated Location: (705:21,22 [2] ) +|My| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.codegen.cs new file mode 100644 index 00000000000..c975b2365f0 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/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 + #nullable restore + public partial class +#nullable restore +#line (1,12)-(1,29) "x:\dir\subdir\Test\TestComponent.cshtml" +MyCustomComponent + +#line default +#line hidden +#nullable disable + : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __builder.OpenComponent(0); + __builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.ir.txt new file mode 100644 index 00000000000..94979daadbd --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.ir.txt @@ -0,0 +1,10 @@ +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 - MyCustomComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree + Component - (32:2,0 [21] x:\dir\subdir\Test\TestComponent.cshtml) - MyCustomComponent diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.mappings.txt new file mode 100644 index 00000000000..ecf4c76524a --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Basic/TestComponent.mappings.txt @@ -0,0 +1,10 @@ +Source Location: (11:0,11 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|MyCustomComponent| +Generated Location: (460:16,0 [17] ) +|MyCustomComponent| + +Source Location: (33:2,1 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|MyCustomComponent| +Generated Location: (847:27,49 [17] ) +|MyCustomComponent| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.codegen.cs new file mode 100644 index 00000000000..e82c3e54db7 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.codegen.cs @@ -0,0 +1,25 @@ +// +#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) + { + __builder.AddMarkupContent(0, "

Hello World

"); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..383a8c067a3 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,12): Error RZ1015: The 'classname' directive expects an identifier. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.ir.txt new file mode 100644 index 00000000000..e86f4106ee4 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_Empty/TestComponent.ir.txt @@ -0,0 +1,12 @@ +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 - + MethodDeclaration - - protected override - void - BuildRenderTree + MalformedDirective - (0:0,0 [11] x:\dir\subdir\Test\TestComponent.cshtml) - classname + DirectiveToken - (11:0,11 [0] x:\dir\subdir\Test\TestComponent.cshtml) - + MarkupBlock - -

Hello World

diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.codegen.cs new file mode 100644 index 00000000000..e761e044562 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.codegen.cs @@ -0,0 +1,26 @@ +// +#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) + { + __builder.AddMarkupContent(0, "123class\r\n"); + __builder.AddMarkupContent(1, "

Hello World

"); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..383a8c067a3 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,12): Error RZ1015: The 'classname' directive expects an identifier. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.ir.txt new file mode 100644 index 00000000000..a5950e3e012 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName/TestComponent.ir.txt @@ -0,0 +1,13 @@ +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 - + MethodDeclaration - - protected override - void - BuildRenderTree + MalformedDirective - (0:0,0 [11] x:\dir\subdir\Test\TestComponent.cshtml) - classname + HtmlContent - (11:0,11 [10] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (11:0,11 [10] x:\dir\subdir\Test\TestComponent.cshtml) - Html - 123class\n + MarkupBlock - -

Hello World

diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.codegen.cs new file mode 100644 index 00000000000..c6eb69b5e86 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.codegen.cs @@ -0,0 +1,26 @@ +// +#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) + { + __builder.AddMarkupContent(0, "class\r\n"); + __builder.AddMarkupContent(1, "

Hello World

"); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.diagnostics.txt new file mode 100644 index 00000000000..383a8c067a3 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.diagnostics.txt @@ -0,0 +1 @@ +x:\dir\subdir\Test\TestComponent.cshtml(1,12): Error RZ1015: The 'classname' directive expects an identifier. diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.ir.txt new file mode 100644 index 00000000000..6f7577fd635 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_InvalidClassName2/TestComponent.ir.txt @@ -0,0 +1,13 @@ +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 - + MethodDeclaration - - protected override - void - BuildRenderTree + MalformedDirective - (0:0,0 [11] x:\dir\subdir\Test\TestComponent.cshtml) - classname + HtmlContent - (11:0,11 [7] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (11:0,11 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - class\n + MarkupBlock - -

Hello World

diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.codegen.cs new file mode 100644 index 00000000000..859a128fa39 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.codegen.cs @@ -0,0 +1,44 @@ +// +#pragma warning disable 1591 +namespace +#nullable restore +#line (2,12)-(2,28) "x:\dir\subdir\Test\TestComponent.cshtml" +Custom.Namespace + +#line default +#line hidden +#nullable disable +{ + #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 +#nullable restore +#line (1,12)-(1,29) "x:\dir\subdir\Test\TestComponent.cshtml" +MyCustomComponent + +#line default +#line hidden +#nullable disable + : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __builder.OpenComponent(0); + __builder.CloseComponent(); + __builder.AddMarkupContent(1, "\r\n"); + __builder.OpenComponent(2); + __builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.ir.txt new file mode 100644 index 00000000000..2f957fb568b --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.ir.txt @@ -0,0 +1,13 @@ +Document - + NamespaceDeclaration - (41:1,11 [16] x:\dir\subdir\Test\TestComponent.cshtml) - Custom.Namespace + 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 - MyCustomComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree + Component - (61:3,0 [21] x:\dir\subdir\Test\TestComponent.cshtml) - MyCustomComponent + HtmlContent - (82:3,21 [2] x:\dir\subdir\Test\TestComponent.cshtml) + LazyIntermediateToken - (82:3,21 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + Component - (84:4,0 [38] x:\dir\subdir\Test\TestComponent.cshtml) - Custom.Namespace.MyCustomComponent diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.mappings.txt new file mode 100644 index 00000000000..255b8cb3e3c --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithNamespace/TestComponent.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (41:1,11 [16] x:\dir\subdir\Test\TestComponent.cshtml) +|Custom.Namespace| +Generated Location: (146:5,0 [16] ) +|Custom.Namespace| + +Source Location: (11:0,11 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|MyCustomComponent| +Generated Location: (606:23,0 [17] ) +|MyCustomComponent| + +Source Location: (62:3,1 [17] x:\dir\subdir\Test\TestComponent.cshtml) +|MyCustomComponent| +Generated Location: (1005:34,61 [17] ) +|MyCustomComponent| + +Source Location: (85:4,1 [34] x:\dir\subdir\Test\TestComponent.cshtml) +|Custom.Namespace.MyCustomComponent| +Generated Location: (1166:37,44 [34] ) +|Custom.Namespace.MyCustomComponent| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.codegen.cs new file mode 100644 index 00000000000..d85c1b3c62c --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.codegen.cs @@ -0,0 +1,49 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; +#nullable restore +#line (3,2)-(3,34) "x:\dir\subdir\Test\TestComponent.cshtml" +using System.Collections.Generic + +#nullable disable + ; + #line default + #line hidden + [global::Microsoft.AspNetCore.Components.RouteAttribute( + // language=Route,Component +#nullable restore +#line (1,7)-(1,17) "x:\dir\subdir\Test\TestComponent.cshtml" +"/my-page" + +#line default +#line hidden +#nullable disable + )] + #nullable restore + public partial class +#nullable restore +#line (2,12)-(2,27) "x:\dir\subdir\Test\TestComponent.cshtml" +MyPageComponent + +#line default +#line hidden +#nullable disable + : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __builder.OpenComponent(0); + __builder.CloseComponent(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.ir.txt new file mode 100644 index 00000000000..46ef8fbf11d --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.ir.txt @@ -0,0 +1,11 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [20] ) - global::System + 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 + UsingDirective - (47:2,1 [32] x:\dir\subdir\Test\TestComponent.cshtml) - System.Collections.Generic + RouteAttributeExtensionNode - (6:0,6 [10] x:\dir\subdir\Test\TestComponent.cshtml) - "/my-page" + ClassDeclaration - - public partial - MyPageComponent - global::Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree + Component - (83:4,0 [19] x:\dir\subdir\Test\TestComponent.cshtml) - MyPageComponent diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.mappings.txt new file mode 100644 index 00000000000..adb2b33dc2b --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithOtherDirectives/TestComponent.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (47:2,1 [32] x:\dir\subdir\Test\TestComponent.cshtml) +|using System.Collections.Generic| +Generated Location: (325:11,0 [32] ) +|using System.Collections.Generic| + +Source Location: (6:0,6 [10] x:\dir\subdir\Test\TestComponent.cshtml) +|"/my-page"| +Generated Location: (600:21,0 [10] ) +|"/my-page"| + +Source Location: (29:1,11 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|MyPageComponent| +Generated Location: (802:31,0 [15] ) +|MyPageComponent| + +Source Location: (84:4,1 [15] x:\dir\subdir\Test\TestComponent.cshtml) +|MyPageComponent| +Generated Location: (1187:42,49 [15] ) +|MyPageComponent| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.codegen.cs new file mode 100644 index 00000000000..ed3417803c5 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ClassName_Directive_WithTypeParam/TestComponent.codegen.cs @@ -0,0 +1,60 @@ +// +#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 +#nullable restore +#line (1,12)-(1,30) "x:\dir\subdir\Test\TestComponent.cshtml" +MyGenericComponent + +#line default +#line hidden +#nullable disable + < +#nullable restore +#line (2,12)-(2,17) "x:\dir\subdir\Test\TestComponent.cshtml" +TItem + +#line default +#line hidden +#nullable disable + > : global::Microsoft.AspNetCore.Components.ComponentBase + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __builder.OpenComponent