From 0a67f7dabd3302ab0e09fe223d6f107cc47ee37e Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Wed, 9 Oct 2024 16:50:17 -0700 Subject: [PATCH 1/5] Fix @inherits mapping for fuse (#10985) * Make base type a token rather than a string * Track inherits source location and emit it when present * Add simple inherits test for components * Add razor page inherits test --- .../test/ModelDirectiveTest.cs | 12 ++-- .../test/MvcViewDocumentClassifierPassTest.cs | 4 +- .../test/ModelDirectiveTest.cs | 12 ++-- .../test/MvcViewDocumentClassifierPassTest.cs | 4 +- .../RazorPageDocumentClassifierPassTest.cs | 4 +- .../InheritsViewModel_Runtime.codegen.cs | 8 ++- ...InheritsWithViewImports_Runtime.codegen.cs | 8 ++- ...idatedMvcViewDocumentClassifierPassTest.cs | 4 +- .../CodeGenerationIntegrationTest.cs | 49 +++++++++++++ .../test/ModelDirectiveTest.cs | 12 ++-- .../test/MvcViewDocumentClassifierPassTest.cs | 4 +- .../RazorPageDocumentClassifierPassTest.cs | 4 +- ...Directive_RazorPages_DesignTime.codegen.cs | 72 +++++++++++++++++++ ...ritsDirective_RazorPages_DesignTime.ir.txt | 44 ++++++++++++ ...itsDirective_RazorPages_Runtime.codegen.cs | 65 +++++++++++++++++ ...nheritsDirective_RazorPages_Runtime.ir.txt | 24 +++++++ .../InheritsViewModel_Runtime.codegen.cs | 10 ++- ...InheritsWithViewImports_Runtime.codegen.cs | 10 ++- ...eBaseType_NullableContexEnabled.codegen.cs | 10 ++- .../CodeGeneration/CSharpCodeWriterTest.cs | 4 +- .../DefaultDocumentWriterTest.cs | 6 +- .../ComponentDocumentClassifierPassTest.cs | 2 +- .../Extensions/InheritsDirectivePassTest.cs | 2 +- .../ComponentCodeGenerationTestBase.cs | 33 +++++++-- .../Inherits_Runtime.codegen.cs | 10 ++- .../Inherits_Runtime.cs-diagnostics.txt | 28 ++++---- .../TestComponent.codegen.cs | 41 +++++++++++ .../InheritsDirective/TestComponent.ir.txt | 17 +++++ .../TestComponent.mappings.txt | 5 ++ .../TestComponent.codegen.cs | 32 +++++++++ .../InheritsDirective/TestComponent.ir.txt | 9 +++ .../TestComponent.mappings.txt | 5 ++ .../TestComponent.codegen.cs | 10 ++- .../TestComponent.mappings.txt | 9 ++- .../TestComponent.codegen.cs | 10 ++- .../TestComponent.mappings.txt | 9 ++- .../CodeGeneration/CodeWriterExtensions.cs | 13 +++- .../ComponentDocumentClassifierPass.cs | 4 +- .../ComponentRenderModeDirectivePass.cs | 2 +- .../Extensions/InheritsDirectivePass.cs | 3 +- .../ClassDeclarationIntermediateNode.cs | 4 +- .../Intermediate/IntermediateToken.cs | 2 + .../RazorProjectEngineBuilderExtensions.cs | 2 +- .../MvcViewDocumentClassifierPass.cs | 2 +- .../ViewComponentTagHelperTargetExtension.cs | 3 +- .../MvcViewDocumentClassifierPass.cs | 2 +- .../RazorPageDocumentClassifierPass.cs | 2 +- .../ViewComponentTagHelperTargetExtension.cs | 3 +- .../src/Mvc/ModelDirective.cs | 7 +- .../src/Mvc/MvcViewDocumentClassifierPass.cs | 2 +- .../Mvc/RazorPageDocumentClassifierPass.cs | 2 +- .../ViewComponentTagHelperTargetExtension.cs | 3 +- .../IntermediateNodeWriter.cs | 2 +- 53 files changed, 561 insertions(+), 89 deletions(-) create mode 100644 src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_DesignTime.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_DesignTime.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_Runtime.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_Runtime.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.mappings.txt diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/ModelDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/ModelDirectiveTest.cs index a25aa7a61c3..fe062041e81 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/ModelDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/ModelDirectiveTest.cs @@ -76,7 +76,7 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -103,7 +103,7 @@ @model Type2 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -129,7 +129,7 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -154,7 +154,7 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -179,7 +179,7 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); @@ -209,7 +209,7 @@ @model SomeType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); 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 fbdccbce41e..da4f186211c 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 @@ -97,7 +97,7 @@ public void MvcViewDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -122,7 +122,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ModelDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ModelDirectiveTest.cs index 2072edc3f10..cfae203b07a 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ModelDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ModelDirectiveTest.cs @@ -76,7 +76,7 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -103,7 +103,7 @@ @model Type2 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -129,7 +129,7 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -154,7 +154,7 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -179,7 +179,7 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); @@ -209,7 +209,7 @@ @model SomeType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); 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 b4b98958ad3..e4a07f5c8b2 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 @@ -97,7 +97,7 @@ public void MvcViewDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -122,7 +122,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", visitor.Class.ClassName); } 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 ba5dde0985b..a1ec9547c43 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 @@ -224,7 +224,7 @@ public void RazorPageDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -249,7 +249,7 @@ public void RazorPageDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_c3b458108610c1a2aa6eede0a5685ede853e036732db515609b2a23ca15359e1", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs index 684aa264c92..c8bba27fb80 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs @@ -16,7 +16,13 @@ namespace AspNetCore #line default #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"1ca5ae8e569aefa6575a68e8d8b2d375ed79deec6565fb893b72b89423f55abd", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel : MyBasePageForViews + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel : +#line (1,11)-(1,37) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +MyBasePageForViews + +#line default +#line hidden + { #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs index bb74a25addf..f0f494f719f 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs @@ -17,7 +17,13 @@ namespace AspNetCore #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"a652fac42d6a27ace9b45de079bd1bd21d47f29255b96899785aaa55a4a8e354", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml")] [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"0fd3e40bc660f76f39c803bba3ce5cbaf8ca19f7a8c1563212571e769673e06a", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports : MyPageModel + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports : +#line (1,11)-(1,30) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" +MyPageModel + +#line default +#line hidden + { #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() 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 e4312e20cd0..ed4cafd4388 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs @@ -56,7 +56,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); Assert.Equal(new[] { "internal", "sealed" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -81,7 +81,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); Assert.Equal(new[] { "internal", "sealed" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 49dbbb3f985..3d1660d9f80 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -879,6 +879,31 @@ @inherits MyBasePage AssertCSharpDocumentMatchesBaseline(csharp); CompileToAssembly(generated); } + + [Fact] + public void InheritsDirective_RazorPages_Runtime() + { + // Arrange + AddCSharpSyntaxTree(""" + public abstract class MyBase : global::Microsoft.AspNetCore.Mvc.RazorPages.Page { + + } + """); + + // Act + var generated = CompileToCSharp(""" + @page + @inherits MyBase + """); + + // Assert + var intermediate = generated.CodeDocument.GetDocumentIntermediateNode(); + var csharp = generated.CodeDocument.GetCSharpDocument(); + AssertDocumentNodeMatchesBaseline(intermediate); + AssertCSharpDocumentMatchesBaseline(csharp); + CompileToAssembly(generated); + } + #endregion #region DesignTime @@ -1467,6 +1492,30 @@ public void RazorPageWithNoLeadingPageDirective_DesignTime() Assert.Equal("RZ3906", Assert.Single(diagnotics).Id); } + [Fact] + public void InheritsDirective_RazorPages_DesignTime() + { + // Arrange + AddCSharpSyntaxTree(""" + public abstract class MyBase : global::Microsoft.AspNetCore.Mvc.RazorPages.Page { + + } + """); + + // Act + var generated = CompileToCSharp(""" + @page + @inherits MyBase + """, designTime: true); + + // Assert + var intermediate = generated.CodeDocument.GetDocumentIntermediateNode(); + var csharp = generated.CodeDocument.GetCSharpDocument(); + AssertDocumentNodeMatchesBaseline(intermediate); + AssertCSharpDocumentMatchesBaseline(csharp); + CompileToAssembly(generated); + } + #endregion [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/razor/issues/7286")] diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ModelDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ModelDirectiveTest.cs index eaf2eebeb8f..00428fd9ef9 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ModelDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ModelDirectiveTest.cs @@ -75,7 +75,7 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -102,7 +102,7 @@ @model Type2 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -128,7 +128,7 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -153,7 +153,7 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); } [Fact] @@ -178,7 +178,7 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); @@ -208,7 +208,7 @@ @model SomeType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType); + Assert.Equal("BaseType", @class.BaseType.Content); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); 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 d60e97ead8d..f5e0becb618 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcViewDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcViewDocumentClassifierPassTest.cs @@ -97,7 +97,7 @@ public void MvcViewDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -122,7 +122,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", visitor.Class.ClassName); } 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 96a36382888..25c1adf0a3d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/RazorPageDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/RazorPageDocumentClassifierPassTest.cs @@ -224,7 +224,7 @@ public void RazorPageDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -249,7 +249,7 @@ public void RazorPageDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_c3b458108610c1a2aa6eede0a5685ede853e036732db515609b2a23ca15359e1", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_DesignTime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_DesignTime.codegen.cs new file mode 100644 index 00000000000..d20792ba397 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_DesignTime.codegen.cs @@ -0,0 +1,72 @@ +// +#pragma warning disable 1591 +namespace AspNetCoreGeneratedDocument +{ + #line default + using TModel = global::System.Object; + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : MyBase + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" +MyBase __typeHelper = default!; + +#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 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + #nullable restore +public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData!; +#nullable disable + #nullable restore +public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model!; +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_DesignTime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_DesignTime.ir.txt new file mode 100644 index 00000000000..618e2e4f579 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_DesignTime.ir.txt @@ -0,0 +1,44 @@ +Document - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - MyBase - + DesignTimeDirective - + DirectiveToken - (287:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (350:7,71 [4] ) - Html + DirectiveToken - (364:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (419:8,63 [4] ) - Json + DirectiveToken - (433:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (487:9,62 [9] ) - Component + DirectiveToken - (506:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (550:10,52 [3] ) - Url + DirectiveToken - (563:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (634:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (673:12,14 [104] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (793:13,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (904:14,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (17:1,10 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - MyBase + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + CSharpCode - + IntermediateToken - - CSharp - #nullable restore\npublic global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData!;\n#nullable disable + CSharpCode - + IntermediateToken - - CSharp - #nullable restore\npublic TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model!;\n#nullable disable diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_Runtime.codegen.cs new file mode 100644 index 00000000000..e37f62182b4 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_Runtime.codegen.cs @@ -0,0 +1,65 @@ +#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "63a5110dfeb21bc2ddd4cce5b34696f680ad9eafeb5002b4ad2fd947c2c69f61" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCoreGeneratedDocument.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.razor-page", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] +namespace AspNetCoreGeneratedDocument +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"63a5110dfeb21bc2ddd4cce5b34696f680ad9eafeb5002b4ad2fd947c2c69f61", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : +#nullable restore +#line (2,11)-(2,17) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" +MyBase + +#line default +#line hidden +#nullable disable + + #nullable disable + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + #nullable restore +public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData!; +#nullable disable + #nullable restore +public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model!; +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_Runtime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_Runtime.ir.txt new file mode 100644 index 00000000000..516a00a7e2a --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsDirective_RazorPages_Runtime.ir.txt @@ -0,0 +1,24 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - MyBase - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + CSharpCode - + IntermediateToken - - CSharp - #nullable restore\npublic global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData!;\n#nullable disable + CSharpCode - + IntermediateToken - - CSharp - #nullable restore\npublic TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model!;\n#nullable disable diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs index 7d5e59cc7ec..d086f010d6d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs @@ -18,7 +18,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel : MyBasePageForViews + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel : +#nullable restore +#line (1,11)-(1,37) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +MyBasePageForViews + +#line default +#line hidden +#nullable disable + #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs index 2615dac991c..fec2854e3a8 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs @@ -19,7 +19,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports : MyPageModel + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports : +#nullable restore +#line (1,11)-(1,30) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" +MyPageModel + +#line default +#line hidden +#nullable disable + #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableBaseType_NullableContexEnabled.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableBaseType_NullableContexEnabled.codegen.cs index a65b1147d4e..9e9a0ae7aff 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableBaseType_NullableContexEnabled.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableBaseType_NullableContexEnabled.codegen.cs @@ -24,7 +24,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : MyBasePage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : +#nullable restore +#line (3,11)-(3,33) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" +MyBasePage + +#line default +#line hidden +#nullable disable + #nullable disable { #pragma warning disable 1998 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 39604a88965..1d91493d874 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/CSharpCodeWriterTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/CSharpCodeWriterTest.cs @@ -405,7 +405,7 @@ public void CSharpCodeWriter_RespectTabSetting() using var writer = new CodeWriter(options); // Act - writer.BuildClassDeclaration(Array.Empty(), "C", "", Array.Empty(), Array.Empty(), context: null); + writer.BuildClassDeclaration(Array.Empty(), "C", IntermediateToken.CreateCSharpToken(""), Array.Empty(), Array.Empty(), context: null); writer.WriteField(Array.Empty(), Array.Empty(), "int", "f"); // Assert @@ -431,7 +431,7 @@ public void CSharpCodeWriter_RespectSpaceSetting() using var writer = new CodeWriter(options); // Act - writer.BuildClassDeclaration(Array.Empty(), "C", "", Array.Empty(), Array.Empty(), context: null); + writer.BuildClassDeclaration(Array.Empty(), "C", IntermediateToken.CreateCSharpToken(""), Array.Empty(), Array.Empty(), context: null); writer.WriteField(Array.Empty(), Array.Empty(), "int", "f"); // Assert diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs index 9a9ad5d22b3..f755f8bae94 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs @@ -181,7 +181,7 @@ public void WriteDocument_WritesClass() { "internal" }, - BaseType = "TestBase", + BaseType = IntermediateToken.CreateCSharpToken("TestBase"), Interfaces = new List { "IFoo", "IBar", }, TypeParameters = new List { @@ -228,7 +228,7 @@ public void WriteDocument_WithNullableContext_WritesClass() { "internal" }, - BaseType = "TestBase", + BaseType = IntermediateToken.CreateCSharpToken("TestBase"), Interfaces = new List { "IFoo", "IBar", }, TypeParameters = new List { @@ -281,7 +281,7 @@ public void WriteDocument_WritesClass_ConstrainedGenericTypeParameters() { "internal" }, - BaseType = "TestBase", + BaseType = IntermediateToken.CreateCSharpToken("TestBase"), Interfaces = new List { "IFoo", "IBar", }, TypeParameters = new List { 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 e23f47a8de7..d4d953c2d45 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Components/ComponentDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Components/ComponentDocumentClassifierPassTest.cs @@ -86,7 +86,7 @@ public void ComponentDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal($"global::{ComponentsApi.ComponentBase.FullTypeName}", visitor.Class.BaseType); + Assert.Equal($"global::{ComponentsApi.ComponentBase.FullTypeName}", visitor.Class.BaseType.Content); Assert.Equal(new[] { "public", "partial" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/InheritsDirectivePassTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/InheritsDirectivePassTest.cs index 926346b61ca..30b1a064cfd 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/InheritsDirectivePassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/InheritsDirectivePassTest.cs @@ -68,7 +68,7 @@ public void Execute_Inherits_SetsClassDeclarationBaseType() node => Assert.IsType(node)); var @class = (ClassDeclarationIntermediateNode)@namespace.Children[0]; - Assert.Equal("Hello", @class.BaseType); + Assert.Equal("Hello", @class.BaseType.Content); } private static DocumentIntermediateNode Lower(RazorCodeDocument codeDocument, RazorEngine engine) 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 b7c4984ce27..95f1350bddf 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -5470,6 +5470,30 @@ @preservewhitespace someVariable Assert.Collection(generated.RazorDiagnostics, d => { Assert.Equal("RZ1038", d.Id); }); } + [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/10963")] + public void InheritsDirective() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(""" + namespace Test; + + public class BaseComponent : Microsoft.AspNetCore.Components.ComponentBase + { + } + """)); + + // Act + var generated = CompileToCSharp(""" + @inherits BaseComponent + """); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/7169")] public void InheritsDirective_NullableReferenceType() { @@ -5526,9 +5550,9 @@ @inherits BaseComponent """, nullableEnable: false, expectedCSharpDiagnostics: - // (18,62): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. + // (1,31): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. // public partial class TestComponent : BaseComponent - Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(18, 62)); + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(1, 31)); // Assert Assert.Empty(generated.RazorDiagnostics); @@ -5544,9 +5568,9 @@ @inherits BaseComponent Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(14, 62) ] : [ - // (14,62): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. + // (1,31): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. // public partial class TestComponent : BaseComponent - Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(14, 62) + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(1, 31) ]); } @@ -5630,7 +5654,6 @@ @using System.Collections CompileToAssembly(generated); } - #endregion #region EventCallback diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits_Runtime.codegen.cs index 7894a068a68..b804ef4cd0a 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits_Runtime.codegen.cs @@ -18,7 +18,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inherits : foo.bar>.boz + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inherits : +#nullable restore +#line (1,11)-(1,32) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml" +foo.bar>.boz + +#line default +#line hidden +#nullable disable + #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits_Runtime.cs-diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits_Runtime.cs-diagnostics.txt index bf21394ac74..789de819c74 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits_Runtime.cs-diagnostics.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits_Runtime.cs-diagnostics.txt @@ -1,18 +1,18 @@ -// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(3,2): error CS0103: The name 'foo' does not exist in the current context +// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(1,11): error CS0246: The type or namespace name 'foo' could not be found (are you missing a using directive or an assembly reference?) +// foo.bar>.boz +Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "foo").WithArguments("foo").WithLocation(1, 11), +// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(1,19): error CS0246: The type or namespace name 'baz<>' could not be found (are you missing a using directive or an assembly reference?) +// foo.bar>.boz +Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "baz").WithArguments("baz<>").WithLocation(1, 19), +// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(1,23): error CS0246: The type or namespace name 'biz' could not be found (are you missing a using directive or an assembly reference?) +// foo.bar>.boz +Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "biz").WithArguments("biz").WithLocation(1, 23), +// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(3,2): error CS0103: The name 'foo' does not exist in the current context // foo() Diagnostic(ErrorCode.ERR_NameNotInContext, "foo").WithArguments("foo").WithLocation(3, 2), -// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(21,95): error CS0246: The type or namespace name 'foo' could not be found (are you missing a using directive or an assembly reference?) -// internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inherits : foo.bar>.boz -Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "foo").WithArguments("foo").WithLocation(21, 95), -// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(21,103): error CS0246: The type or namespace name 'baz<>' could not be found (are you missing a using directive or an assembly reference?) -// internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inherits : foo.bar>.boz -Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "baz").WithArguments("baz<>").WithLocation(21, 103), -// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(21,107): error CS0246: The type or namespace name 'biz' could not be found (are you missing a using directive or an assembly reference?) -// internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Inherits : foo.bar>.boz -Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "biz").WithArguments("biz").WithLocation(21, 107), -// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(27,13): error CS0103: The name 'WriteLiteral' does not exist in the current context +// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(35,13): error CS0103: The name 'WriteLiteral' does not exist in the current context // WriteLiteral("\r\n"); -Diagnostic(ErrorCode.ERR_NameNotInContext, "WriteLiteral").WithArguments("WriteLiteral").WithLocation(27, 13), -// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(28,13): error CS0103: The name 'Write' does not exist in the current context +Diagnostic(ErrorCode.ERR_NameNotInContext, "WriteLiteral").WithArguments("WriteLiteral").WithLocation(35, 13), +// TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Inherits.cshtml(36,13): error CS0103: The name 'Write' does not exist in the current context // Write( -Diagnostic(ErrorCode.ERR_NameNotInContext, "Write").WithArguments("Write").WithLocation(28, 13) \ No newline at end of file +Diagnostic(ErrorCode.ERR_NameNotInContext, "Write").WithArguments("Write").WithLocation(36, 13) \ No newline at end of file diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.codegen.cs new file mode 100644 index 00000000000..2079215543f --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/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 : BaseComponent + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" +BaseComponent __typeHelper = default!; + +#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/InheritsDirective/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.ir.txt new file mode 100644 index 00000000000..52c2241d32d --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.ir.txt @@ -0,0 +1,17 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [20] ) - global::System + UsingDirective - (26:2,1 [40] ) - global::System.Collections.Generic + UsingDirective - (69:3,1 [25] ) - global::System.Linq + UsingDirective - (97:4,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (136:5,1 [45] ) - global::Microsoft.AspNetCore.Components + ClassDeclaration - - public partial - TestComponent - BaseComponent - + DesignTimeDirective - + DirectiveToken - (10:0,10 [13] x:\dir\subdir\Test\TestComponent.cshtml) - BaseComponent + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.mappings.txt new file mode 100644 index 00000000000..9c60432a6e0 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/InheritsDirective/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (10:0,10 [13] x:\dir\subdir\Test\TestComponent.cshtml) +|BaseComponent| +Generated Location: (643:21,0 [13] ) +|BaseComponent| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.codegen.cs new file mode 100644 index 00000000000..767dfe04f9e --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.codegen.cs @@ -0,0 +1,32 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; + #line default + #line hidden + #nullable restore + public partial class TestComponent : +#nullable restore +#line (1,11)-(1,24) "x:\dir\subdir\Test\TestComponent.cshtml" +BaseComponent + +#line default +#line hidden +#nullable disable + + #nullable disable + { + #pragma warning disable 1998 + protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.ir.txt new file mode 100644 index 00000000000..09d8ddb6b4d --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.ir.txt @@ -0,0 +1,9 @@ +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 - BaseComponent - + MethodDeclaration - - protected override - void - BuildRenderTree diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.mappings.txt new file mode 100644 index 00000000000..876e829a99a --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (10:0,10 [13] x:\dir\subdir\Test\TestComponent.cshtml) +|BaseComponent| +Generated Location: (476:16,0 [13] ) +|BaseComponent| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType/TestComponent.codegen.cs index 367df5e8ebb..82416e64d30 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType/TestComponent.codegen.cs @@ -11,7 +11,15 @@ namespace Test #line default #line hidden #nullable restore - public partial class TestComponent : BaseComponent + public partial class TestComponent : +#nullable restore +#line (1,11)-(1,33) "x:\dir\subdir\Test\TestComponent.cshtml" +BaseComponent + +#line default +#line hidden +#nullable disable + #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType/TestComponent.mappings.txt index c872e0cfa08..5af796fcfcd 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType/TestComponent.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType/TestComponent.mappings.txt @@ -1,5 +1,10 @@ -Source Location: (61:3,2 [17] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (10:0,10 [22] x:\dir\subdir\Test\TestComponent.cshtml) +|BaseComponent| +Generated Location: (476:16,0 [22] ) +|BaseComponent| + +Source Location: (61:3,2 [17] x:\dir\subdir\Test\TestComponent.cshtml) |_field.ToString()| -Generated Location: (815:23,0 [17] ) +Generated Location: (951:31,0 [17] ) |_field.ToString()| diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType_NullableDisabled/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType_NullableDisabled/TestComponent.codegen.cs index 367df5e8ebb..82416e64d30 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType_NullableDisabled/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType_NullableDisabled/TestComponent.codegen.cs @@ -11,7 +11,15 @@ namespace Test #line default #line hidden #nullable restore - public partial class TestComponent : BaseComponent + public partial class TestComponent : +#nullable restore +#line (1,11)-(1,33) "x:\dir\subdir\Test\TestComponent.cshtml" +BaseComponent + +#line default +#line hidden +#nullable disable + #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType_NullableDisabled/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType_NullableDisabled/TestComponent.mappings.txt index c872e0cfa08..5af796fcfcd 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType_NullableDisabled/TestComponent.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/InheritsDirective_NullableReferenceType_NullableDisabled/TestComponent.mappings.txt @@ -1,5 +1,10 @@ -Source Location: (61:3,2 [17] x:\dir\subdir\Test\TestComponent.cshtml) +Source Location: (10:0,10 [22] x:\dir\subdir\Test\TestComponent.cshtml) +|BaseComponent| +Generated Location: (476:16,0 [22] ) +|BaseComponent| + +Source Location: (61:3,2 [17] x:\dir\subdir\Test\TestComponent.cshtml) |_field.ToString()| -Generated Location: (815:23,0 [17] ) +Generated Location: (951:31,0 [17] ) |_field.ToString()| 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 fee897212dd..bc1aa748671 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 @@ -470,7 +470,7 @@ public static CSharpCodeWritingScope BuildClassDeclaration( this CodeWriter writer, IList modifiers, string name, - string baseType, + IntermediateToken baseType, IList interfaces, IList typeParameters, CodeRenderingContext context, @@ -518,7 +518,7 @@ public static CSharpCodeWritingScope BuildClassDeclaration( writer.Write(">"); } - var hasBaseType = !string.IsNullOrEmpty(baseType); + var hasBaseType = !string.IsNullOrEmpty(baseType?.Content); var hasInterfaces = interfaces != null && interfaces.Count > 0; if (hasBaseType || hasInterfaces) @@ -527,7 +527,14 @@ public static CSharpCodeWritingScope BuildClassDeclaration( if (hasBaseType) { - writer.Write(baseType); + if (baseType.Source is { } source) + { + WriteWithPragma(writer, baseType.Content, context, source); + } + else + { + writer.Write(baseType.Content); + } if (hasInterfaces) { 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 407cbf24cba..745dfe64907 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 @@ -99,7 +99,7 @@ protected override void OnDocumentStructureCreated( { // We don't want component imports to be considered as real component. // But we still want to generate code for it so we can get diagnostics. - @class.BaseType = typeof(object).FullName; + @class.BaseType = IntermediateToken.CreateCSharpToken(typeof(object).FullName); method.ReturnType = "void"; method.MethodName = "Execute"; @@ -110,7 +110,7 @@ protected override void OnDocumentStructureCreated( } else { - @class.BaseType = "global::" + ComponentsApi.ComponentBase.FullTypeName; + @class.BaseType = IntermediateToken.CreateCSharpToken("global::" + ComponentsApi.ComponentBase.FullTypeName); // Constrained type parameters are only supported in Razor language versions v6.0 var razorLanguageVersion = codeDocument.GetParserOptions()?.Version ?? RazorLanguageVersion.Latest; 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 006f1889a9c..8c54701c504 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 @@ -40,7 +40,7 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte var classDecl = new ClassDeclarationIntermediateNode() { ClassName = GeneratedRenderModeAttributeName, - BaseType = $"global::{ComponentsApi.RenderModeAttribute.FullTypeName}", + BaseType = IntermediateToken.CreateCSharpToken($"global::{ComponentsApi.RenderModeAttribute.FullTypeName}"), }; classDecl.Modifiers.Add("private"); classDecl.Modifiers.Add("sealed"); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/InheritsDirectivePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/InheritsDirectivePass.cs index 044d58f5f68..0516c699090 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/InheritsDirectivePass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/InheritsDirectivePass.cs @@ -24,7 +24,8 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte var token = ((DirectiveIntermediateNode)inherits.Node).Tokens.FirstOrDefault(); if (token != null) { - @class.BaseType = token.Content; + var source = codeDocument.GetParserOptions()?.DesignTime == true ? null : token.Source; + @class.BaseType = IntermediateToken.CreateCSharpToken(token.Content, source); break; } } 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 73de32b9fb2..6c31f4c5f20 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 @@ -17,7 +17,7 @@ public sealed class ClassDeclarationIntermediateNode : MemberDeclarationIntermed public string ClassName { get; set; } - public string BaseType { get; set; } + public IntermediateToken BaseType { get; set; } public IList Interfaces { get; set; } = new List(); @@ -37,7 +37,7 @@ public override void FormatNode(IntermediateNodeFormatter formatter) { formatter.WriteContent(ClassName); - formatter.WriteProperty(nameof(BaseType), BaseType); + BaseType.FormatNode(formatter); formatter.WriteProperty(nameof(ClassName), ClassName); formatter.WriteProperty(nameof(Interfaces), string.Join(", ", Interfaces)); formatter.WriteProperty(nameof(Modifiers), string.Join(", ", Modifiers)); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateToken.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateToken.cs index e63325adbf8..d156164d5d9 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateToken.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateToken.cs @@ -19,6 +19,8 @@ public class IntermediateToken : IntermediateNode public TokenKind Kind { get; set; } = TokenKind.Unknown; + public static IntermediateToken CreateCSharpToken(string content, SourceSpan? location = null) => new IntermediateToken() { Content = content, Kind = TokenKind.CSharp, Source = location }; + public override void Accept(IntermediateNodeVisitor visitor) { if (visitor == null) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngineBuilderExtensions.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngineBuilderExtensions.cs index 63b97161199..53f4af83fac 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngineBuilderExtensions.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngineBuilderExtensions.cs @@ -94,7 +94,7 @@ public static RazorProjectEngineBuilder SetBaseType(this RazorProjectEngineBuild } var configurationFeature = GetDefaultDocumentClassifierPassFeature(builder); - configurationFeature.ConfigureClass.Add((document, @class) => @class.BaseType = baseType); + configurationFeature.ConfigureClass.Add((document, @class) => @class.BaseType = IntermediateToken.CreateCSharpToken(baseType)); return builder; } 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 c7717de751e..713bcf19890 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 @@ -39,7 +39,7 @@ protected override void OnDocumentStructureCreated( @class.ClassName = CSharpIdentifier.GetClassNameFromPath(filePath); } - @class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"; + @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"); @class.Modifiers.Clear(); @class.Modifiers.Add("public"); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/ViewComponentTagHelperTargetExtension.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/ViewComponentTagHelperTargetExtension.cs index 227dc40db08..9f0dad7174d 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/ViewComponentTagHelperTargetExtension.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/ViewComponentTagHelperTargetExtension.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X; @@ -16,7 +17,7 @@ internal class ViewComponentTagHelperTargetExtension : IViewComponentTagHelperTa { private static readonly string[] PublicModifiers = new[] { "public" }; - public string TagHelperTypeName { get; set; } = "Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"; + public IntermediateToken TagHelperTypeName { get; set; } = IntermediateToken.CreateCSharpToken("Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"); public string ViewComponentHelperTypeName { get; set; } = "global::Microsoft.AspNetCore.Mvc.IViewComponentHelper"; 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 53778ed2f94..88f340b0746 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 @@ -39,7 +39,7 @@ protected override void OnDocumentStructureCreated( @class.ClassName = CSharpIdentifier.GetClassNameFromPath(filePath); } - @class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"; + @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"); @class.Modifiers.Clear(); @class.Modifiers.Add("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 c13140067b6..caad4ef5d26 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 @@ -51,7 +51,7 @@ protected override void OnDocumentStructureCreated( @namespace.Content = "AspNetCore"; - @class.BaseType = "global::Microsoft.AspNetCore.Mvc.RazorPages.Page"; + @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); var filePath = codeDocument.Source.RelativePath ?? codeDocument.Source.FilePath; if (string.IsNullOrEmpty(filePath)) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/ViewComponentTagHelperTargetExtension.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/ViewComponentTagHelperTargetExtension.cs index 8d63ca7aa11..d963a574068 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/ViewComponentTagHelperTargetExtension.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/ViewComponentTagHelperTargetExtension.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X; @@ -16,7 +17,7 @@ internal class ViewComponentTagHelperTargetExtension : IViewComponentTagHelperTa { private static readonly string[] PublicModifiers = new[] { "public" }; - public string TagHelperTypeName { get; set; } = "Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"; + public IntermediateToken TagHelperTypeName { get; set; } = IntermediateToken.CreateCSharpToken("Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"); public string ViewComponentHelperTypeName { get; set; } = "global::Microsoft.AspNetCore.Mvc.IViewComponentHelper"; 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 8d8e6338ea4..64a835729c9 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ModelDirective.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ModelDirective.cs @@ -101,8 +101,11 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte visitor.Namespace?.Children.Insert(0, usingNode); } - var baseType = visitor.Class?.BaseType?.Replace("", "<" + modelType + ">"); - visitor.Class.BaseType = baseType; + if (visitor.Class?.BaseType is { } existingBaseType) + { + var typeName = existingBaseType.Content.Replace("", "<" + modelType + ">"); + visitor.Class.BaseType = IntermediateToken.CreateCSharpToken(typeName, existingBaseType.Source); + } } } 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 4ddbe268963..a6206871317 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/MvcViewDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/MvcViewDocumentClassifierPass.cs @@ -53,7 +53,7 @@ protected override void OnDocumentStructureCreated( { @class.ClassName = className; } - @class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"; + @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"); @class.Modifiers.Clear(); if (_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 1706d408e53..9cfd06dc360 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs @@ -79,7 +79,7 @@ protected override void OnDocumentStructureCreated( @class.ClassName = className; } - @class.BaseType = "global::Microsoft.AspNetCore.Mvc.RazorPages.Page"; + @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); @class.Modifiers.Clear(); if (_useConsolidatedMvcViews) { diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtension.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtension.cs index f8c3e34e3c7..889384902bd 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtension.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtension.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; @@ -15,7 +16,7 @@ internal class ViewComponentTagHelperTargetExtension : IViewComponentTagHelperTa { private static readonly string[] PublicModifiers = new[] { "public" }; - public string TagHelperTypeName { get; set; } = "Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"; + public IntermediateToken TagHelperTypeName { get; set; } = IntermediateToken.CreateCSharpToken("Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"); public string ViewComponentHelperTypeName { get; set; } = "global::Microsoft.AspNetCore.Mvc.IViewComponentHelper"; 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 2c53092456b..14a766df37c 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 @@ -43,7 +43,7 @@ public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node { string.Join(" ", node.Modifiers), node.ClassName, - node.BaseType, + node.BaseType?.Content, string.Join(", ", node.Interfaces ?? Array.Empty()) }; From 9415e86e071c25934969710105f0dcf2ae62a73f Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Thu, 17 Oct 2024 16:14:49 -0700 Subject: [PATCH 2/5] Ensure model directives are mapped at runtime (#11007) * Replace baseType token with a dedicated type * Track the generic portion of the baseType in the new type * Update the model portion of the baseType when the @model directive is used * Add tests + update baselines. --------- Co-authored-by: Fred Silberberg --- .../test/ModelDirectiveTest.cs | 50 ++++++++-- .../test/MvcViewDocumentClassifierPassTest.cs | 9 +- .../InjectWithModel_Runtime.codegen.cs | 8 +- .../InjectWithModel_Runtime.mappings.txt | 15 ++- .../InjectWithSemicolon_Runtime.codegen.cs | 8 +- .../InjectWithSemicolon_Runtime.mappings.txt | 23 +++-- .../test/ModelDirectiveTest.cs | 52 ++++++++-- .../test/MvcViewDocumentClassifierPassTest.cs | 9 +- .../RazorPageDocumentClassifierPassTest.cs | 4 +- .../InheritsViewModel_Runtime.codegen.cs | 19 +++- ...InheritsWithViewImports_Runtime.codegen.cs | 19 +++- .../InjectWithModel_Runtime.codegen.cs | 8 +- .../InjectWithModel_Runtime.mappings.txt | 15 ++- .../InjectWithSemicolon_Runtime.codegen.cs | 8 +- .../InjectWithSemicolon_Runtime.mappings.txt | 23 +++-- ...odelExpressionTagHelper_Runtime.codegen.cs | 8 +- .../Model_Runtime.codegen.cs | 8 +- .../Sections_Runtime.codegen.cs | 8 +- ...idatedMvcViewDocumentClassifierPassTest.cs | 9 +- .../test/ModelDirectiveTest.cs | 50 ++++++++-- .../test/MvcViewDocumentClassifierPassTest.cs | 9 +- .../RazorPageDocumentClassifierPassTest.cs | 4 +- .../BasicComponent_Runtime.codegen.cs | 10 +- .../InheritsViewModel_Runtime.codegen.cs | 25 ++++- ...InheritsWithViewImports_Runtime.codegen.cs | 25 ++++- .../InjectWithModel_Runtime.codegen.cs | 10 +- .../InjectWithModel_Runtime.mappings.txt | 15 ++- .../InjectWithSemicolon_Runtime.codegen.cs | 10 +- .../InjectWithSemicolon_Runtime.mappings.txt | 23 +++-- ...odelExpressionTagHelper_Runtime.codegen.cs | 10 +- .../Model_Runtime.codegen.cs | 10 +- ...bleModel_NullableContextEnabled.codegen.cs | 10 +- ...bleModel_NullableContextEnabled.codegen.cs | 10 +- ...Model_NullableContextNotEnabled.codegen.cs | 10 +- .../Sections_Runtime.codegen.cs | 10 +- .../CodeGeneration/CSharpCodeWriterTest.cs | 4 +- .../DefaultDocumentWriterTest.cs | 12 +-- .../ComponentDocumentClassifierPassTest.cs | 2 +- .../Extensions/InheritsDirectivePassTest.cs | 2 +- .../CodeGenerationIntegrationTest.cs | 3 + .../Implements_Multiple.cshtml | 11 +++ .../Implements_Multiple_DesignTime.codegen.cs | 98 +++++++++++++++++++ ...mplements_Multiple_DesignTime.codegen.html | 11 +++ ...ents_Multiple_DesignTime.html.mappings.txt | 35 +++++++ .../Implements_Multiple_DesignTime.ir.txt | 48 +++++++++ ...mplements_Multiple_DesignTime.mappings.txt | 32 ++++++ .../Implements_Multiple_Runtime.codegen.cs | 89 +++++++++++++++++ .../Implements_Multiple_Runtime.ir.txt | 24 +++++ .../Implements_Runtime.codegen.cs | 10 +- .../CodeGeneration/CodeWriterExtensions.cs | 45 ++++++--- .../ComponentDocumentClassifierPass.cs | 4 +- .../ComponentRenderModeDirectivePass.cs | 2 +- .../Extensions/ImplementsDirectivePass.cs | 8 +- .../Extensions/InheritsDirectivePass.cs | 2 +- .../Intermediate/BaseTypeWithModel.cs | 41 ++++++++ .../ClassDeclarationIntermediateNode.cs | 7 +- .../RazorProjectEngineBuilderExtensions.cs | 2 +- .../src/Language/SourceSpan.cs | 5 + .../MvcViewDocumentClassifierPass.cs | 3 +- .../ViewComponentTagHelperTargetExtension.cs | 4 +- .../MvcViewDocumentClassifierPass.cs | 3 +- .../RazorPageDocumentClassifierPass.cs | 2 +- .../ViewComponentTagHelperTargetExtension.cs | 4 +- .../src/Mvc/ModelDirective.cs | 17 ++-- .../src/Mvc/MvcViewDocumentClassifierPass.cs | 3 +- .../Mvc/RazorPageDocumentClassifierPass.cs | 2 +- .../ViewComponentTagHelperTargetExtension.cs | 4 +- .../IntermediateNodeWriter.cs | 12 +-- 68 files changed, 929 insertions(+), 166 deletions(-) create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.codegen.html create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.html.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.ir.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.mappings.txt create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_Runtime.codegen.cs create mode 100644 src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_Runtime.ir.txt create mode 100644 src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/BaseTypeWithModel.cs diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/ModelDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/ModelDirectiveTest.cs index fe062041e81..e1b4a486089 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/ModelDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/ModelDirectiveTest.cs @@ -75,8 +75,13 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); - Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("Type1", baseType.ModelType.Content); + Assert.NotNull(baseType.ModelType.Source); } [Fact] @@ -102,8 +107,13 @@ @model Type2 // Assert var @class = FindClassNode(irDocument); - Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("Type1", baseType.ModelType.Content); + Assert.NotNull(baseType.ModelType.Source); } [Fact] @@ -129,7 +139,13 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + // ISSUE: https://github.com/dotnet/razor/issues/10987 we don't issue a warning or emit anything for the unused model + Assert.Null(baseType.ModelType); } [Fact] @@ -154,7 +170,13 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("dynamic", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); } [Fact] @@ -179,7 +201,13 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("dynamic", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); @@ -209,7 +237,13 @@ @model SomeType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("SomeType", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); 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 da4f186211c..13f03b71c35 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 @@ -4,6 +4,7 @@ #nullable disable using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; using Roslyn.Test.Utilities; using Xunit; @@ -97,7 +98,9 @@ public void MvcViewDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); + var baseNode = Assert.IsType(visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", baseNode.BaseType.Content); + Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -122,7 +125,9 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); + var baseNode = Assert.IsType(visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", baseNode.BaseType.Content); + Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs index 3cf715a52e9..4f2333173fc 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs @@ -15,7 +15,13 @@ namespace AspNetCore #line default #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"319d5fa6f848e64d19bf7eab2f5e3339cdfc75b02a9bc6f2773eed1a40f5e9d0", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml" +MyModel + +#line default +#line hidden + > { #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt index cd9ef7be750..a157a93cdf1 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt @@ -1,20 +1,25 @@ -Source Location: (54:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +|MyModel| +Generated Location: (1359:19,0 [7] ) +|MyModel| + +Source Location: (54:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyService| -Generated Location: (1651:27,0 [9] ) +Generated Location: (1792:33,0 [9] ) |MyService| Source Location: (72:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |Html| -Generated Location: (1816:33,0 [4] ) +Generated Location: (1957:39,0 [4] ) |Html| Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyApp| -Generated Location: (2084:41,0 [5] ) +Generated Location: (2225:47,0 [5] ) |MyApp| Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyPropertyName| -Generated Location: (2236:47,0 [14] ) +Generated Location: (2377:53,0 [14] ) |MyPropertyName| diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs index 4c0d7043331..2acb01d26e8 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs @@ -15,7 +15,13 @@ namespace AspNetCore #line default #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"771acb56660727ab6e4ca50e95bde0cf2a72af8de3e9ec1cd4b72969645cb9af", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml" +MyModel + +#line default +#line hidden + > { #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt index 0c49d873fd0..aac9d34986c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt @@ -1,40 +1,45 @@ -Source Location: (129:4,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyModel| +Generated Location: (1383:19,0 [7] ) +|MyModel| + +Source Location: (129:4,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyService| -Generated Location: (1675:27,0 [9] ) +Generated Location: (1820:33,0 [9] ) |MyService| Source Location: (147:4,26 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |Html2| -Generated Location: (1844:33,0 [5] ) +Generated Location: (1989:39,0 [5] ) |Html2| Source Location: (93:3,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyApp| -Generated Location: (2117:41,0 [5] ) +Generated Location: (2262:47,0 [5] ) |MyApp| Source Location: (99:3,14 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyPropertyName2| -Generated Location: (2273:47,0 [15] ) +Generated Location: (2418:53,0 [15] ) |MyPropertyName2| Source Location: (58:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyService| -Generated Location: (2556:55,0 [9] ) +Generated Location: (2701:61,0 [9] ) |MyService| Source Location: (76:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |Html| -Generated Location: (2725:61,0 [4] ) +Generated Location: (2870:67,0 [4] ) |Html| Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyApp| -Generated Location: (2997:69,0 [5] ) +Generated Location: (3142:75,0 [5] ) |MyApp| Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyPropertyName| -Generated Location: (3153:75,0 [14] ) +Generated Location: (3298:81,0 [14] ) |MyPropertyName| diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ModelDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ModelDirectiveTest.cs index cfae203b07a..37fcf886e61 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ModelDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/ModelDirectiveTest.cs @@ -75,8 +75,13 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); - Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("Type1", baseType.ModelType.Content); + Assert.NotNull(baseType.ModelType.Source); } [Fact] @@ -102,8 +107,13 @@ @model Type2 // Assert var @class = FindClassNode(irDocument); - Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("Type1", baseType.ModelType.Content); + Assert.NotNull(baseType.ModelType.Source); } [Fact] @@ -129,7 +139,13 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + // ISSUE: https://github.com/dotnet/razor/issues/10987 we don't issue a warning or emit anything for the unused model + Assert.Null(baseType.ModelType); } [Fact] @@ -154,7 +170,13 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("dynamic", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); } [Fact] @@ -179,7 +201,13 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("dynamic", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); @@ -209,7 +237,13 @@ @model SomeType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("SomeType", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); @@ -238,7 +272,7 @@ private NamespaceDeclarationIntermediateNode FindNamespaceNode(IntermediateNode private RazorEngine CreateRuntimeEngine() { - return CreateEngineCore(); + return CreateEngineCore(designTime: false); } private RazorEngine CreateDesignTimeEngine() 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 e4a07f5c8b2..ecffebf4037 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 @@ -4,6 +4,7 @@ #nullable disable using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; using Roslyn.Test.Utilities; using Xunit; @@ -97,7 +98,9 @@ public void MvcViewDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); + var baseNode = Assert.IsType(visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", baseNode.BaseType.Content); + Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -122,7 +125,9 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); + var baseNode = Assert.IsType(visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", baseNode.BaseType.Content); + Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", visitor.Class.ClassName); } 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 a1ec9547c43..567038f341c 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 @@ -224,7 +224,7 @@ public void RazorPageDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.Content); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -249,7 +249,7 @@ public void RazorPageDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.Content); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_c3b458108610c1a2aa6eede0a5685ede853e036732db515609b2a23ca15359e1", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs index c8bba27fb80..96abb2e140d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs @@ -17,8 +17,23 @@ namespace AspNetCore #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"1ca5ae8e569aefa6575a68e8d8b2d375ed79deec6565fb893b72b89423f55abd", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml")] public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel : -#line (1,11)-(1,37) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" -MyBasePageForViews +#line (1,11)-(1,29) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +MyBasePageForViews + +#line default +#line hidden +#line (1,29)-(1,30) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +< + +#line default +#line hidden +#line (2,8)-(2,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +MyModel + +#line default +#line hidden +#line (1,36)-(1,37) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +> #line default #line hidden diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs index f0f494f719f..400c77f8c99 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs @@ -18,8 +18,23 @@ namespace AspNetCore [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"a652fac42d6a27ace9b45de079bd1bd21d47f29255b96899785aaa55a4a8e354", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml")] [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"0fd3e40bc660f76f39c803bba3ce5cbaf8ca19f7a8c1563212571e769673e06a", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/_ViewImports.cshtml")] public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports : -#line (1,11)-(1,30) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" -MyPageModel +#line (1,11)-(1,22) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" +MyPageModel + +#line default +#line hidden +#line (1,22)-(1,23) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" +< + +#line default +#line hidden +#line (2,8)-(2,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml" +MyModel + +#line default +#line hidden +#line (1,29)-(1,30) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" +> #line default #line hidden diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs index 9781fd70a54..b87188cfefd 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs @@ -16,7 +16,13 @@ namespace AspNetCore #line default #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"319d5fa6f848e64d19bf7eab2f5e3339cdfc75b02a9bc6f2773eed1a40f5e9d0", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml" +MyModel + +#line default +#line hidden + > { #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt index ad26bf27bcc..71057855dbf 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt @@ -1,20 +1,25 @@ -Source Location: (54:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +|MyModel| +Generated Location: (1619:20,0 [7] ) +|MyModel| + +Source Location: (54:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyService| -Generated Location: (1911:28,0 [9] ) +Generated Location: (2052:34,0 [9] ) |MyService| Source Location: (72:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |Html| -Generated Location: (2076:34,0 [4] ) +Generated Location: (2217:40,0 [4] ) |Html| Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyApp| -Generated Location: (2344:42,0 [5] ) +Generated Location: (2485:48,0 [5] ) |MyApp| Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyPropertyName| -Generated Location: (2496:48,0 [14] ) +Generated Location: (2637:54,0 [14] ) |MyPropertyName| diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs index 1fe06b9a386..c30e3ff8771 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs @@ -16,7 +16,13 @@ namespace AspNetCore #line default #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"771acb56660727ab6e4ca50e95bde0cf2a72af8de3e9ec1cd4b72969645cb9af", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml" +MyModel + +#line default +#line hidden + > { #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt index 698ee2083c4..0e9c19e4e57 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt @@ -1,40 +1,45 @@ -Source Location: (129:4,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyModel| +Generated Location: (1651:20,0 [7] ) +|MyModel| + +Source Location: (129:4,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyService| -Generated Location: (1943:28,0 [9] ) +Generated Location: (2088:34,0 [9] ) |MyService| Source Location: (147:4,26 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |Html2| -Generated Location: (2112:34,0 [5] ) +Generated Location: (2257:40,0 [5] ) |Html2| Source Location: (93:3,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyApp| -Generated Location: (2385:42,0 [5] ) +Generated Location: (2530:48,0 [5] ) |MyApp| Source Location: (99:3,14 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyPropertyName2| -Generated Location: (2541:48,0 [15] ) +Generated Location: (2686:54,0 [15] ) |MyPropertyName2| Source Location: (58:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyService| -Generated Location: (2824:56,0 [9] ) +Generated Location: (2969:62,0 [9] ) |MyService| Source Location: (76:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |Html| -Generated Location: (2993:62,0 [4] ) +Generated Location: (3138:68,0 [4] ) |Html| Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyApp| -Generated Location: (3265:70,0 [5] ) +Generated Location: (3410:76,0 [5] ) |MyApp| Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyPropertyName| -Generated Location: (3421:76,0 [14] ) +Generated Location: (3566:82,0 [14] ) |MyPropertyName| diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs index 65503cb77d7..36e5e3f1bb6 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs @@ -16,7 +16,13 @@ namespace AspNetCore #line default #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"b96e944bd86a2acecd5a176708eedb3cdc8eef05122fd51aa5c4fe58d4069af7", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#line (1,8)-(1,16) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml" +DateTime + +#line default +#line hidden + > { #line hidden #pragma warning disable 0649 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs index 60a8a969aca..6a00d9a6f5e 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs @@ -16,7 +16,13 @@ namespace AspNetCore #line default #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"36b79708f36f3606c2eb7c7eaf383853df55ab030280d5deb8f762fac54fd1c0", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#line (1,8)-(1,38) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml" +System.Collections.IEnumerable + +#line default +#line hidden + > { #pragma warning disable 1998 public async override global::System.Threading.Tasks.Task ExecuteAsync() diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs index d6cda67f0f4..0c353beba2c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs @@ -16,7 +16,13 @@ namespace AspNetCore #line default #line hidden [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"1ed96a957fe000fd0c80cc511def19ab692563eb64f3349a4c87c524e2ecbd60", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#line (1,8)-(1,16) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" +DateTime + +#line default +#line hidden + > { #line hidden #pragma warning disable 0649 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 ed4cafd4388..a689e3b4965 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs @@ -4,6 +4,7 @@ #nullable disable using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; using Roslyn.Test.Utilities; using Xunit; @@ -56,7 +57,9 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); + var baseNode = Assert.IsType(visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", baseNode.BaseType.Content); + Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(new[] { "internal", "sealed" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -81,7 +84,9 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); + var baseNode = Assert.IsType(visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", baseNode.BaseType.Content); + Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(new[] { "internal", "sealed" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ModelDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ModelDirectiveTest.cs index 00428fd9ef9..8769138a008 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ModelDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ModelDirectiveTest.cs @@ -74,8 +74,13 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); - Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("Type1", baseType.ModelType.Content); + Assert.NotNull(baseType.ModelType.Source); } [Fact] @@ -101,8 +106,13 @@ @model Type2 // Assert var @class = FindClassNode(irDocument); - Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("Type1", baseType.ModelType.Content); + Assert.NotNull(baseType.ModelType.Source); } [Fact] @@ -128,7 +138,13 @@ @model Type1 // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + // ISSUE: https://github.com/dotnet/razor/issues/10987 we don't issue a warning or emit anything for the unused model + Assert.Null(baseType.ModelType); } [Fact] @@ -153,7 +169,13 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("dynamic", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); } [Fact] @@ -178,7 +200,13 @@ @inherits BaseType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("dynamic", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); @@ -208,7 +236,13 @@ @model SomeType // Assert var @class = FindClassNode(irDocument); Assert.NotNull(@class); - Assert.Equal("BaseType", @class.BaseType.Content); + var baseType = @class.BaseType; + + Assert.Equal("BaseType", baseType.BaseType.Content); + Assert.NotNull(baseType.BaseType.Source); + + Assert.Equal("SomeType", baseType.ModelType.Content); + Assert.Null(baseType.ModelType.Source); var @namespace = FindNamespaceNode(irDocument); var usingNode = Assert.IsType(@namespace.Children[0]); 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 f5e0becb618..1d5631835aa 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcViewDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/MvcViewDocumentClassifierPassTest.cs @@ -4,6 +4,7 @@ #nullable disable using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; using Roslyn.Test.Utilities; using Xunit; @@ -97,7 +98,9 @@ public void MvcViewDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); + var baseNode = Assert.IsType(visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", baseNode.BaseType.Content); + Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -122,7 +125,9 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", visitor.Class.BaseType.Content); + var baseNode = Assert.IsType(visitor.Class.BaseType); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", baseNode.BaseType.Content); + Assert.Equal("TModel", baseNode.ModelType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_ec563e63d931b806184cb02f79875e4f3b21d1ca043ad06699424459128b58c0", visitor.Class.ClassName); } 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 25c1adf0a3d..fd5c60187fb 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/RazorPageDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/RazorPageDocumentClassifierPassTest.cs @@ -224,7 +224,7 @@ public void RazorPageDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.Content); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } @@ -249,7 +249,7 @@ public void RazorPageDocumentClassifierPass_NullFilePath_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.Content); + Assert.Equal("global::Microsoft.AspNetCore.Mvc.RazorPages.Page", visitor.Class.BaseType.BaseType.Content); Assert.Equal(new[] { "public" }, visitor.Class.Modifiers); AssertEx.Equal("AspNetCore_c3b458108610c1a2aa6eede0a5685ede853e036732db515609b2a23ca15359e1", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent_Runtime.codegen.cs index 8becffde010..3894dec8328 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent_Runtime.codegen.cs @@ -12,7 +12,15 @@ namespace TestFiles.IntegrationTests.CodeGenerationIntegrationTest #line default #line hidden #nullable restore - public partial class BasicComponent : global::Microsoft.AspNetCore.Components.ComponentBase, IDisposable + public partial class BasicComponent : global::Microsoft.AspNetCore.Components.ComponentBase, +#nullable restore +#line (1,13)-(1,24) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml" +IDisposable + +#line default +#line hidden +#nullable disable + #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs index d086f010d6d..1d275a341f7 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel_Runtime.codegen.cs @@ -20,8 +20,29 @@ namespace AspNetCoreGeneratedDocument #nullable restore internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsViewModel : #nullable restore -#line (1,11)-(1,37) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" -MyBasePageForViews +#line (1,11)-(1,29) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +MyBasePageForViews + +#line default +#line hidden +#nullable disable +#nullable restore +#line (1,29)-(1,30) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +< + +#line default +#line hidden +#nullable disable +#nullable restore +#line (2,8)-(2,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +MyModel + +#line default +#line hidden +#nullable disable +#nullable restore +#line (1,36)-(1,37) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsViewModel.cshtml" +> #line default #line hidden diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs index fec2854e3a8..4e1109a53a2 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports_Runtime.codegen.cs @@ -21,8 +21,29 @@ namespace AspNetCoreGeneratedDocument #nullable restore internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InheritsWithViewImports : #nullable restore -#line (1,11)-(1,30) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" -MyPageModel +#line (1,11)-(1,22) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" +MyPageModel + +#line default +#line hidden +#nullable disable +#nullable restore +#line (1,22)-(1,23) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" +< + +#line default +#line hidden +#nullable disable +#nullable restore +#line (2,8)-(2,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InheritsWithViewImports.cshtml" +MyModel + +#line default +#line hidden +#nullable disable +#nullable restore +#line (1,29)-(1,30) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\_ViewImports.cshtml" +> #line default #line hidden diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs index be636240d3d..ef2107be175 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.codegen.cs @@ -18,7 +18,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithModel : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml" +MyModel + +#line default +#line hidden +#nullable disable + > #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt index a8d413833d9..d04a02e4b5d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel_Runtime.mappings.txt @@ -1,20 +1,25 @@ -Source Location: (54:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) +|MyModel| +Generated Location: (1765:23,0 [7] ) +|MyModel| + +Source Location: (54:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyService| -Generated Location: (2080:32,0 [9] ) +Generated Location: (2259:40,0 [9] ) |MyService| Source Location: (72:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |Html| -Generated Location: (2283:40,0 [4] ) +Generated Location: (2462:48,0 [4] ) |Html| Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyApp| -Generated Location: (2611:51,0 [5] ) +Generated Location: (2790:59,0 [5] ) |MyApp| Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithModel.cshtml) |MyPropertyName| -Generated Location: (2801:59,0 [14] ) +Generated Location: (2980:67,0 [14] ) |MyPropertyName| diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs index 26d47a76b27..ef2c888868e 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.codegen.cs @@ -18,7 +18,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithSemicolon : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml" +MyModel + +#line default +#line hidden +#nullable disable + > #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt index 56b60c17d77..ddb6c6cd693 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_Runtime.mappings.txt @@ -1,40 +1,45 @@ -Source Location: (129:4,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +|MyModel| +Generated Location: (1793:23,0 [7] ) +|MyModel| + +Source Location: (129:4,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyService| -Generated Location: (2108:32,0 [9] ) +Generated Location: (2291:40,0 [9] ) |MyService| Source Location: (147:4,26 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |Html2| -Generated Location: (2315:40,0 [5] ) +Generated Location: (2498:48,0 [5] ) |Html2| Source Location: (93:3,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyApp| -Generated Location: (2648:51,0 [5] ) +Generated Location: (2831:59,0 [5] ) |MyApp| Source Location: (99:3,14 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyPropertyName2| -Generated Location: (2842:59,0 [15] ) +Generated Location: (3025:67,0 [15] ) |MyPropertyName2| Source Location: (58:2,8 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyService| -Generated Location: (3185:70,0 [9] ) +Generated Location: (3368:78,0 [9] ) |MyService| Source Location: (76:2,26 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |Html| -Generated Location: (3392:78,0 [4] ) +Generated Location: (3575:86,0 [4] ) |Html| Source Location: (24:1,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyApp| -Generated Location: (3724:89,0 [5] ) +Generated Location: (3907:97,0 [5] ) |MyApp| Source Location: (30:1,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyPropertyName| -Generated Location: (3918:97,0 [14] ) +Generated Location: (4101:105,0 [14] ) |MyPropertyName| diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs index 5bc6b0d3352..65565542415 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper_Runtime.codegen.cs @@ -18,7 +18,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_ModelExpressionTagHelper : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (1,8)-(1,16) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ModelExpressionTagHelper.cshtml" +DateTime + +#line default +#line hidden +#nullable disable + > #nullable disable { #line hidden diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs index e789c5db091..0243354b5e8 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model_Runtime.codegen.cs @@ -18,7 +18,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Model : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (1,8)-(1,38) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Model.cshtml" +System.Collections.IEnumerable + +#line default +#line hidden +#nullable disable + > #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNonNullableModel_NullableContextEnabled.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNonNullableModel_NullableContextEnabled.codegen.cs index 3528aafa6ab..53b5a83808f 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNonNullableModel_NullableContextEnabled.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNonNullableModel_NullableContextEnabled.codegen.cs @@ -24,7 +24,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (3,8)-(3,17) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" +TestModel + +#line default +#line hidden +#nullable disable + > #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableModel_NullableContextEnabled.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableModel_NullableContextEnabled.codegen.cs index a59acf74f5a..7b21b6491ee 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableModel_NullableContextEnabled.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableModel_NullableContextEnabled.codegen.cs @@ -24,7 +24,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (3,8)-(3,18) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" +TestModel? + +#line default +#line hidden +#nullable disable + > #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableModel_NullableContextNotEnabled.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableModel_NullableContextNotEnabled.codegen.cs index a59acf74f5a..7b21b6491ee 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableModel_NullableContextNotEnabled.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithNullableModel_NullableContextNotEnabled.codegen.cs @@ -24,7 +24,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (3,8)-(3,18) "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" +TestModel? + +#line default +#line hidden +#nullable disable + > #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs index 78ca6fbaf55..3cacfd32b38 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs @@ -18,7 +18,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Sections : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (1,8)-(1,16) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" +DateTime + +#line default +#line hidden +#nullable disable + > #nullable disable { #line hidden 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 1d91493d874..82da742e314 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/CSharpCodeWriterTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/CSharpCodeWriterTest.cs @@ -405,7 +405,7 @@ public void CSharpCodeWriter_RespectTabSetting() using var writer = new CodeWriter(options); // Act - writer.BuildClassDeclaration(Array.Empty(), "C", IntermediateToken.CreateCSharpToken(""), Array.Empty(), Array.Empty(), context: null); + writer.BuildClassDeclaration(Array.Empty(), "C", null, Array.Empty(), Array.Empty(), context: null); writer.WriteField(Array.Empty(), Array.Empty(), "int", "f"); // Assert @@ -431,7 +431,7 @@ public void CSharpCodeWriter_RespectSpaceSetting() using var writer = new CodeWriter(options); // Act - writer.BuildClassDeclaration(Array.Empty(), "C", IntermediateToken.CreateCSharpToken(""), Array.Empty(), Array.Empty(), context: null); + writer.BuildClassDeclaration(Array.Empty(), "C", null, Array.Empty(), Array.Empty(), context: null); writer.WriteField(Array.Empty(), Array.Empty(), "int", "f"); // Assert diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs index f755f8bae94..88ad7e5afca 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/CodeGeneration/DefaultDocumentWriterTest.cs @@ -181,8 +181,8 @@ public void WriteDocument_WritesClass() { "internal" }, - BaseType = IntermediateToken.CreateCSharpToken("TestBase"), - Interfaces = new List { "IFoo", "IBar", }, + BaseType = new BaseTypeWithModel("TestBase"), + Interfaces = [IntermediateToken.CreateCSharpToken("IFoo"), IntermediateToken.CreateCSharpToken("IBar")], TypeParameters = new List { new TypeParameter() { ParameterName = "TKey", }, @@ -228,8 +228,8 @@ public void WriteDocument_WithNullableContext_WritesClass() { "internal" }, - BaseType = IntermediateToken.CreateCSharpToken("TestBase"), - Interfaces = new List { "IFoo", "IBar", }, + BaseType = new BaseTypeWithModel("TestBase"), + Interfaces = [IntermediateToken.CreateCSharpToken("IFoo"), IntermediateToken.CreateCSharpToken("IBar")], TypeParameters = new List { new TypeParameter() { ParameterName = "TKey", }, @@ -281,8 +281,8 @@ public void WriteDocument_WritesClass_ConstrainedGenericTypeParameters() { "internal" }, - BaseType = IntermediateToken.CreateCSharpToken("TestBase"), - Interfaces = new List { "IFoo", "IBar", }, + BaseType = new BaseTypeWithModel("TestBase"), + Interfaces = [IntermediateToken.CreateCSharpToken("IFoo"), IntermediateToken.CreateCSharpToken("IBar")], TypeParameters = new List { new TypeParameter() { ParameterName = "TKey", Constraints = "where TKey : class" }, 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 d4d953c2d45..44bf56189d4 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Components/ComponentDocumentClassifierPassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Components/ComponentDocumentClassifierPassTest.cs @@ -86,7 +86,7 @@ public void ComponentDocumentClassifierPass_SetsClass() visitor.Visit(irDocument); // Assert - Assert.Equal($"global::{ComponentsApi.ComponentBase.FullTypeName}", visitor.Class.BaseType.Content); + Assert.Equal($"global::{ComponentsApi.ComponentBase.FullTypeName}",visitor.Class.BaseType.BaseType.Content); Assert.Equal(new[] { "public", "partial" }, visitor.Class.Modifiers); Assert.Equal("Test", visitor.Class.ClassName); } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/InheritsDirectivePassTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/InheritsDirectivePassTest.cs index 30b1a064cfd..8ffc724a81a 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/InheritsDirectivePassTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Extensions/InheritsDirectivePassTest.cs @@ -68,7 +68,7 @@ public void Execute_Inherits_SetsClassDeclarationBaseType() node => Assert.IsType(node)); var @class = (ClassDeclarationIntermediateNode)@namespace.Children[0]; - Assert.Equal("Hello", @class.BaseType.Content); + Assert.Equal("Hello", @class.BaseType.BaseType.Content); } private static DocumentIntermediateNode Lower(RazorCodeDocument codeDocument, RazorEngine engine) diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 6156e55f838..473f91a626e 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -276,6 +276,9 @@ public void ConditionalAttributes2() [IntegrationTestFact] public void Implements() => RunTest(); + [IntegrationTestFact] + public void Implements_Multiple() => RunTest(); + [IntegrationTestFact] public void AttributeDirective() => RunTest(); diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml new file mode 100644 index 00000000000..95003762c4e --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml @@ -0,0 +1,11 @@ +@implements IDisposable +@implements IEquatable +@implements ICloneable + +@functions { + void IDisposable.Dispose() { } + + bool IEquatable.Equals(string x) => false; + + object ICloneable.Clone() => this; +} diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.codegen.cs new file mode 100644 index 00000000000..0ba05f4a301 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.codegen.cs @@ -0,0 +1,98 @@ +// +#pragma warning disable 1591 +namespace AspNetCoreGeneratedDocument +{ + #line default + using TModel = global::System.Object; + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Implements_Multiple : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage, IDisposable, IEquatable, ICloneable + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" +IDisposable __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" +IEquatable __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 3 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" +ICloneable __typeHelper = default!; + +#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 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 +#nullable restore +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" + + void IDisposable.Dispose() { } + + bool IEquatable.Equals(string x) => false; + + object ICloneable.Clone() => this; + +#line default +#line hidden +#nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.codegen.html b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.codegen.html new file mode 100644 index 00000000000..d9de944b56f --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.codegen.html @@ -0,0 +1,11 @@ +/*~~~~~~~*/ /*~~~~~~~*/ +/*~~~~~~~*/ /*~~~~~~~~~~~~~~*/ +/*~~~~~~~*/ /*~~~~~~*/ + +/*~~~~~~*/ ~ + /**/ /*~~~~~~~~~~~~~~~~~*/ ~ ~ + + /**/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ ~~ ~~ /*~~*/ + + /*~~*/ /*~~~~~~~~~~~~~~*/ ~~ /*~*/ +~ diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.html.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.html.mappings.txt new file mode 100644 index 00000000000..849d6c1f792 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.html.mappings.txt @@ -0,0 +1,35 @@ +Source Location: (23:0,23 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +| +| +Generated Location: (23:0,23 [2] ) +| +| + +Source Location: (55:1,30 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +| +| +Generated Location: (55:1,30 [2] ) +| +| + +Source Location: (79:2,22 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +| + +| +Generated Location: (79:2,22 [4] ) +| + +| + +Source Location: (93:4,10 [1] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +| | +Generated Location: (93:4,10 [1] ) +| | + +Source Location: (234:10,1 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +| +| +Generated Location: (234:10,1 [2] ) +| +| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.ir.txt new file mode 100644 index 00000000000..3b58ecf6d0b --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.ir.txt @@ -0,0 +1,48 @@ +Document - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Implements_Multiple - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - IDisposable, IEquatable, ICloneable + DesignTimeDirective - + DirectiveToken - (287:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (350:7,71 [4] ) - Html + DirectiveToken - (364:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (419:8,63 [4] ) - Json + DirectiveToken - (433:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (487:9,62 [9] ) - Component + DirectiveToken - (506:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (550:10,52 [3] ) - Url + DirectiveToken - (563:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (634:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (673:12,14 [104] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (793:13,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (904:14,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (12:0,12 [11] Implements_Multiple.cshtml) - IDisposable + DirectiveToken - (37:1,12 [18] Implements_Multiple.cshtml) - IEquatable + DirectiveToken - (69:2,12 [10] Implements_Multiple.cshtml) - ICloneable + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + HtmlContent - (81:3,0 [2] Implements_Multiple.cshtml) + LazyIntermediateToken - (81:3,0 [2] Implements_Multiple.cshtml) - Html - \n + HtmlContent - (234:10,1 [2] Implements_Multiple.cshtml) + LazyIntermediateToken - (234:10,1 [2] Implements_Multiple.cshtml) - Html - \n + CSharpCode - (95:4,12 [138] Implements_Multiple.cshtml) + LazyIntermediateToken - (95:4,12 [138] Implements_Multiple.cshtml) - CSharp - \n void IDisposable.Dispose() { }\n\n bool IEquatable.Equals(string x) => false;\n\n object ICloneable.Clone() => this;\n + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.mappings.txt new file mode 100644 index 00000000000..fabab2dffb5 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_DesignTime.mappings.txt @@ -0,0 +1,32 @@ +Source Location: (12:0,12 [11] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +|IDisposable| +Generated Location: (1281:26,0 [11] ) +|IDisposable| + +Source Location: (37:1,12 [18] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +|IEquatable| +Generated Location: (1551:36,0 [18] ) +|IEquatable| + +Source Location: (69:2,12 [10] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +|ICloneable| +Generated Location: (1828:46,0 [10] ) +|ICloneable| + +Source Location: (95:4,12 [138] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml) +| + void IDisposable.Dispose() { } + + bool IEquatable.Equals(string x) => false; + + object ICloneable.Clone() => this; +| +Generated Location: (2414:65,12 [138] ) +| + void IDisposable.Dispose() { } + + bool IEquatable.Equals(string x) => false; + + object ICloneable.Clone() => this; +| + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_Runtime.codegen.cs new file mode 100644 index 00000000000..294a78ecc87 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_Runtime.codegen.cs @@ -0,0 +1,89 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6f296ad8bb011dd7153573d3db200852edfa16134bc762f70a7c539ef4e3d2d1" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCoreGeneratedDocument.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Implements_Multiple), @"mvc.1.0.view", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml")] +namespace AspNetCoreGeneratedDocument +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"6f296ad8bb011dd7153573d3db200852edfa16134bc762f70a7c539ef4e3d2d1", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml")] + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Implements_Multiple : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage, +#nullable restore +#line (1,13)-(1,24) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" +IDisposable + +#line default +#line hidden +#nullable disable + , +#nullable restore +#line (2,13)-(2,31) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" +IEquatable + +#line default +#line hidden +#nullable disable + , +#nullable restore +#line (3,13)-(3,23) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" +ICloneable + +#line default +#line hidden +#nullable disable + + #nullable disable + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + WriteLiteral("\r\n"); + } + #pragma warning restore 1998 +#nullable restore +#line (5,13)-(11,1) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple.cshtml" + + void IDisposable.Dispose() { } + + bool IEquatable.Equals(string x) => false; + + object ICloneable.Clone() => this; + +#line default +#line hidden +#nullable disable + + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_Runtime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_Runtime.ir.txt new file mode 100644 index 00000000000..98f9164e218 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Multiple_Runtime.ir.txt @@ -0,0 +1,24 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Implements_Multiple - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - IDisposable, IEquatable, ICloneable + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + HtmlContent - (81:3,0 [2] Implements_Multiple.cshtml) + LazyIntermediateToken - (81:3,0 [2] Implements_Multiple.cshtml) - Html - \n + CSharpCode - (95:4,12 [138] Implements_Multiple.cshtml) + LazyIntermediateToken - (95:4,12 [138] Implements_Multiple.cshtml) - CSharp - \n void IDisposable.Dispose() { }\n\n bool IEquatable.Equals(string x) => false;\n\n object ICloneable.Clone() => this;\n + Inject - + Inject - + Inject - + Inject - + Inject - diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Runtime.codegen.cs index 32c9e48e122..9cd70cdbad0 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Runtime.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements_Runtime.codegen.cs @@ -18,7 +18,15 @@ namespace AspNetCoreGeneratedDocument [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements.cshtml")] [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] #nullable restore - internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Implements : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage, IDisposable + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_Implements : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage, +#nullable restore +#line (1,13)-(1,24) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Implements.cshtml" +IDisposable + +#line default +#line hidden +#nullable disable + #nullable disable { #pragma warning disable 1998 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 bc1aa748671..9c2c36d6991 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 @@ -470,8 +470,8 @@ public static CSharpCodeWritingScope BuildClassDeclaration( this CodeWriter writer, IList modifiers, string name, - IntermediateToken baseType, - IList interfaces, + BaseTypeWithModel baseType, + IList interfaces, IList typeParameters, CodeRenderingContext context, bool useNullableContext = false) @@ -518,7 +518,7 @@ public static CSharpCodeWritingScope BuildClassDeclaration( writer.Write(">"); } - var hasBaseType = !string.IsNullOrEmpty(baseType?.Content); + var hasBaseType = !string.IsNullOrWhiteSpace(baseType?.BaseType.Content); var hasInterfaces = interfaces != null && interfaces.Count > 0; if (hasBaseType || hasInterfaces) @@ -527,14 +527,10 @@ public static CSharpCodeWritingScope BuildClassDeclaration( if (hasBaseType) { - if (baseType.Source is { } source) - { - WriteWithPragma(writer, baseType.Content, context, source); - } - else - { - writer.Write(baseType.Content); - } + WriteToken(baseType.BaseType); + WriteOptionalToken(baseType.GreaterThan); + WriteOptionalToken(baseType.ModelType); + WriteOptionalToken(baseType.LessThan); if (hasInterfaces) { @@ -544,7 +540,12 @@ public static CSharpCodeWritingScope BuildClassDeclaration( if (hasInterfaces) { - writer.Write(string.Join(", ", interfaces)); + WriteToken(interfaces[0]); + for (var i = 1; i < interfaces.Count; i++) + { + writer.Write(", "); + WriteToken(interfaces[i]); + } } } @@ -577,6 +578,26 @@ public static CSharpCodeWritingScope BuildClassDeclaration( return new CSharpCodeWritingScope(writer); + void WriteOptionalToken(IntermediateToken token) + { + if (token is not null) + { + WriteToken(token); + } + } + + void WriteToken(IntermediateToken token) + { + if (token.Source is { } source) + { + WriteWithPragma(writer, token.Content, context, source); + } + else + { + writer.Write(token.Content); + } + } + static void WriteWithPragma(CodeWriter writer, string content, CodeRenderingContext context, SourceSpan source) { if (context.Options.DesignTime) 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 745dfe64907..69079baca4d 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 @@ -99,7 +99,7 @@ protected override void OnDocumentStructureCreated( { // We don't want component imports to be considered as real component. // But we still want to generate code for it so we can get diagnostics. - @class.BaseType = IntermediateToken.CreateCSharpToken(typeof(object).FullName); + @class.BaseType = IntermediateToken.CreateCSharpToken("object"); method.ReturnType = "void"; method.MethodName = "Execute"; @@ -110,7 +110,7 @@ protected override void OnDocumentStructureCreated( } else { - @class.BaseType = IntermediateToken.CreateCSharpToken("global::" + ComponentsApi.ComponentBase.FullTypeName); + @class.BaseType = new BaseTypeWithModel("global::" + ComponentsApi.ComponentBase.FullTypeName); // Constrained type parameters are only supported in Razor language versions v6.0 var razorLanguageVersion = codeDocument.GetParserOptions()?.Version ?? RazorLanguageVersion.Latest; 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 8c54701c504..5ad73ad6de4 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 @@ -40,7 +40,7 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte var classDecl = new ClassDeclarationIntermediateNode() { ClassName = GeneratedRenderModeAttributeName, - BaseType = IntermediateToken.CreateCSharpToken($"global::{ComponentsApi.RenderModeAttribute.FullTypeName}"), + BaseType = new BaseTypeWithModel($"global::{ComponentsApi.RenderModeAttribute.FullTypeName}"), }; classDecl.Modifiers.Add("private"); classDecl.Modifiers.Add("sealed"); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/ImplementsDirectivePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/ImplementsDirectivePass.cs index 756dc7ba721..8f8997e05e1 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/ImplementsDirectivePass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/ImplementsDirectivePass.cs @@ -19,17 +19,13 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte return; } - if (@class.Interfaces == null) - { - @class.Interfaces = new List(); - } - foreach (var implements in documentNode.FindDirectiveReferences(ImplementsDirective.Directive)) { var token = ((DirectiveIntermediateNode)implements.Node).Tokens.FirstOrDefault(); if (token != null) { - @class.Interfaces.Add(token.Content); + var source = codeDocument.GetParserOptions()?.DesignTime == true ? null : token.Source; + @class.Interfaces.Add(IntermediateToken.CreateCSharpToken(token.Content, source)); } } } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/InheritsDirectivePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/InheritsDirectivePass.cs index 0516c699090..d338750f0c4 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/InheritsDirectivePass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Extensions/InheritsDirectivePass.cs @@ -25,7 +25,7 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte if (token != null) { var source = codeDocument.GetParserOptions()?.DesignTime == true ? null : token.Source; - @class.BaseType = IntermediateToken.CreateCSharpToken(token.Content, source); + @class.BaseType = new BaseTypeWithModel(token.Content, source); break; } } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/BaseTypeWithModel.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/BaseTypeWithModel.cs new file mode 100644 index 00000000000..58deca2b6c5 --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/BaseTypeWithModel.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.AspNetCore.Razor.Language.Intermediate; + +public sealed class BaseTypeWithModel +{ + const string ModelGenericParameter = ""; + + public BaseTypeWithModel(string baseType, SourceSpan? location = null) + { + if (baseType.EndsWith(ModelGenericParameter, System.StringComparison.Ordinal)) + { + BaseType = IntermediateToken.CreateCSharpToken(baseType[0..^ModelGenericParameter.Length]); + GreaterThan = IntermediateToken.CreateCSharpToken("<"); + ModelType = IntermediateToken.CreateCSharpToken("TModel"); + LessThan = IntermediateToken.CreateCSharpToken(">"); + + if (location.HasValue) + { + var openBracketPosition = baseType.Length - ModelGenericParameter.Length; + BaseType.Source = location.Value[..openBracketPosition]; + GreaterThan.Source = location.Value[openBracketPosition..(openBracketPosition + 1)]; + ModelType.Source = location.Value[(openBracketPosition + 1)..^1]; + LessThan.Source = location.Value[^1..]; + } + } + else + { + BaseType = IntermediateToken.CreateCSharpToken(baseType, location); + } + } + + public IntermediateToken BaseType { get; set; } + + public IntermediateToken? GreaterThan { get; set; } + + public IntermediateToken? ModelType { get; set; } + + public IntermediateToken? LessThan { get; set; } +} 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 6c31f4c5f20..b430a772dcb 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 @@ -17,9 +17,9 @@ public sealed class ClassDeclarationIntermediateNode : MemberDeclarationIntermed public string ClassName { get; set; } - public IntermediateToken BaseType { get; set; } + public BaseTypeWithModel BaseType { get; set; } - public IList Interfaces { get; set; } = new List(); + public IList Interfaces { get; set; } = new List(); public IList TypeParameters { get; set; } = new List(); @@ -37,9 +37,8 @@ public override void FormatNode(IntermediateNodeFormatter formatter) { formatter.WriteContent(ClassName); - BaseType.FormatNode(formatter); formatter.WriteProperty(nameof(ClassName), ClassName); - formatter.WriteProperty(nameof(Interfaces), string.Join(", ", Interfaces)); + 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.ParameterName))); } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngineBuilderExtensions.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngineBuilderExtensions.cs index 53f4af83fac..b4b4c0fccfb 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngineBuilderExtensions.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngineBuilderExtensions.cs @@ -94,7 +94,7 @@ public static RazorProjectEngineBuilder SetBaseType(this RazorProjectEngineBuild } var configurationFeature = GetDefaultDocumentClassifierPassFeature(builder); - configurationFeature.ConfigureClass.Add((document, @class) => @class.BaseType = IntermediateToken.CreateCSharpToken(baseType)); + configurationFeature.ConfigureClass.Add((document, @class) => @class.BaseType = new BaseTypeWithModel(baseType)); return builder; } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/SourceSpan.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/SourceSpan.cs index 4686220fafa..84e68fd8c03 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/SourceSpan.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/SourceSpan.cs @@ -113,6 +113,11 @@ internal readonly SourceSpan GetZeroWidthEndSpan() return new SourceSpan(FilePath, AbsoluteIndex + EndCharacterIndex, LineIndex, characterIndex: EndCharacterIndex, length: 0, lineCount: 0, EndCharacterIndex); } + internal readonly SourceSpan Slice(int startIndex, int length) + { + return new SourceSpan(FilePath, AbsoluteIndex + startIndex, LineIndex, CharacterIndex + startIndex, length, LineCount, endCharacterIndex: CharacterIndex + startIndex + length); + } + public static bool operator ==(SourceSpan left, SourceSpan right) { return left.Equals(right); 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 713bcf19890..9b43cd8579b 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 @@ -4,6 +4,7 @@ #nullable disable using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version1_X; @@ -39,7 +40,7 @@ protected override void OnDocumentStructureCreated( @class.ClassName = CSharpIdentifier.GetClassNameFromPath(filePath); } - @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"); + @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", location: null); @class.Modifiers.Clear(); @class.Modifiers.Add("public"); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/ViewComponentTagHelperTargetExtension.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/ViewComponentTagHelperTargetExtension.cs index 9f0dad7174d..ec066a4d4ae 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/ViewComponentTagHelperTargetExtension.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version1_X/ViewComponentTagHelperTargetExtension.cs @@ -17,7 +17,7 @@ internal class ViewComponentTagHelperTargetExtension : IViewComponentTagHelperTa { private static readonly string[] PublicModifiers = new[] { "public" }; - public IntermediateToken TagHelperTypeName { get; set; } = IntermediateToken.CreateCSharpToken("Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"); + public string TagHelperTypeName { get; set; } = "Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"; public string ViewComponentHelperTypeName { get; set; } = "global::Microsoft.AspNetCore.Mvc.IViewComponentHelper"; @@ -66,7 +66,7 @@ public void WriteViewComponentTagHelper(CodeRenderingContext context, ViewCompon using (context.CodeWriter.BuildClassDeclaration( PublicModifiers, node.ClassName, - TagHelperTypeName, + new BaseTypeWithModel(TagHelperTypeName), interfaces: null, typeParameters: null, context)) 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 88f340b0746..c7e4cfe6f3b 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 @@ -4,6 +4,7 @@ #nullable disable using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X; @@ -39,7 +40,7 @@ protected override void OnDocumentStructureCreated( @class.ClassName = CSharpIdentifier.GetClassNameFromPath(filePath); } - @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"); + @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", location: null); @class.Modifiers.Clear(); @class.Modifiers.Add("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 caad4ef5d26..f72783914ea 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 @@ -51,7 +51,7 @@ protected override void OnDocumentStructureCreated( @namespace.Content = "AspNetCore"; - @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); + @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); var filePath = codeDocument.Source.RelativePath ?? codeDocument.Source.FilePath; if (string.IsNullOrEmpty(filePath)) diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/ViewComponentTagHelperTargetExtension.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/ViewComponentTagHelperTargetExtension.cs index d963a574068..3d8f4117fdd 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/ViewComponentTagHelperTargetExtension.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc.Version2_X/ViewComponentTagHelperTargetExtension.cs @@ -17,7 +17,7 @@ internal class ViewComponentTagHelperTargetExtension : IViewComponentTagHelperTa { private static readonly string[] PublicModifiers = new[] { "public" }; - public IntermediateToken TagHelperTypeName { get; set; } = IntermediateToken.CreateCSharpToken("Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"); + public string TagHelperTypeName { get; set; } = "Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"; public string ViewComponentHelperTypeName { get; set; } = "global::Microsoft.AspNetCore.Mvc.IViewComponentHelper"; @@ -66,7 +66,7 @@ public void WriteViewComponentTagHelper(CodeRenderingContext context, ViewCompon using (context.CodeWriter.BuildClassDeclaration( PublicModifiers, node.ClassName, - TagHelperTypeName, + new BaseTypeWithModel(TagHelperTypeName), interfaces: null, typeParameters: null, context)) 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 64a835729c9..206d2d7efc0 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ModelDirective.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ModelDirective.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; @@ -43,10 +44,10 @@ public static string GetModelType(DocumentIntermediateNode document) } var visitor = new Visitor(); - return GetModelType(document, visitor); + return GetModelType(document, visitor).Content; } - private static string GetModelType(DocumentIntermediateNode document, Visitor visitor) + private static IntermediateToken GetModelType(DocumentIntermediateNode document, Visitor visitor) { visitor.Visit(document); @@ -57,17 +58,17 @@ private static string GetModelType(DocumentIntermediateNode document, Visitor vi var tokens = directive.Tokens.ToArray(); if (tokens.Length >= 1) { - return tokens[0].Content; + return IntermediateToken.CreateCSharpToken(tokens[0].Content, tokens[0].Source); } } if (document.DocumentKind == RazorPageDocumentClassifierPass.RazorPageDocumentKind) { - return visitor.Class.ClassName; + return IntermediateToken.CreateCSharpToken(visitor.Class.ClassName); } else { - return "dynamic"; + return IntermediateToken.CreateCSharpToken("dynamic"); } } @@ -99,12 +100,12 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte }; visitor.Namespace?.Children.Insert(0, usingNode); + modelType.Source = null; } - if (visitor.Class?.BaseType is { } existingBaseType) + if (visitor.Class?.BaseType is BaseTypeWithModel { ModelType: not null } existingBaseType) { - var typeName = existingBaseType.Content.Replace("", "<" + modelType + ">"); - visitor.Class.BaseType = IntermediateToken.CreateCSharpToken(typeName, existingBaseType.Source); + existingBaseType.ModelType = modelType; } } } 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 a6206871317..fd80aa0b4ff 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/MvcViewDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/MvcViewDocumentClassifierPass.cs @@ -4,6 +4,7 @@ #nullable disable using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Extensions; using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; @@ -53,7 +54,7 @@ protected override void OnDocumentStructureCreated( { @class.ClassName = className; } - @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"); + @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.Razor.RazorPage", location: null); @class.Modifiers.Clear(); if (_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 9cfd06dc360..0cab4df6007 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorPageDocumentClassifierPass.cs @@ -79,7 +79,7 @@ protected override void OnDocumentStructureCreated( @class.ClassName = className; } - @class.BaseType = IntermediateToken.CreateCSharpToken("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); + @class.BaseType = new BaseTypeWithModel("global::Microsoft.AspNetCore.Mvc.RazorPages.Page"); @class.Modifiers.Clear(); if (_useConsolidatedMvcViews) { diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtension.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtension.cs index 889384902bd..212bdd87437 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtension.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/ViewComponentTagHelperTargetExtension.cs @@ -16,7 +16,7 @@ internal class ViewComponentTagHelperTargetExtension : IViewComponentTagHelperTa { private static readonly string[] PublicModifiers = new[] { "public" }; - public IntermediateToken TagHelperTypeName { get; set; } = IntermediateToken.CreateCSharpToken("Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"); + public string TagHelperTypeName { get; set; } = "Microsoft.AspNetCore.Razor.TagHelpers.TagHelper"; public string ViewComponentHelperTypeName { get; set; } = "global::Microsoft.AspNetCore.Mvc.IViewComponentHelper"; @@ -69,7 +69,7 @@ public void WriteViewComponentTagHelper(CodeRenderingContext context, ViewCompon using (context.CodeWriter.BuildClassDeclaration( PublicModifiers, node.ClassName, - TagHelperTypeName, + new BaseTypeWithModel(TagHelperTypeName), interfaces: null, typeParameters: null, context)) 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 14a766df37c..a69b24b522b 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 @@ -40,12 +40,12 @@ public override void VisitDefault(IntermediateNode node) public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) { var entries = new List() - { - string.Join(" ", node.Modifiers), - node.ClassName, - node.BaseType?.Content, - string.Join(", ", node.Interfaces ?? Array.Empty()) - }; + { + string.Join(" ", node.Modifiers), + node.ClassName, + node.BaseType is { } baseType ? $"{baseType.BaseType.Content}{baseType.GreaterThan?.Content}{baseType.ModelType?.Content}{baseType.LessThan?.Content}" : "", + string.Join(", ", node.Interfaces.Select(i => i.Content)) + }; // Avoid adding the type parameters to the baseline if they aren't present. if (node.TypeParameters != null && node.TypeParameters.Count > 0) From ee0c9b1fe73d16e61fb8d2e43027a18af6386ded Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Fri, 18 Oct 2024 13:24:05 -0700 Subject: [PATCH 3/5] Update src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs Fixup bad merge --- .../src/Language/Components/ComponentDocumentClassifierPass.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 69079baca4d..dabd354eb9b 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 @@ -99,7 +99,7 @@ protected override void OnDocumentStructureCreated( { // We don't want component imports to be considered as real component. // But we still want to generate code for it so we can get diagnostics. - @class.BaseType = IntermediateToken.CreateCSharpToken("object"); + @class.BaseType = new BaseTypeWithModel("object"); method.ReturnType = "void"; method.MethodName = "Execute"; From b9a14b769a0378dcece5148c3596597cb7778b45 Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Fri, 18 Oct 2024 16:17:14 -0700 Subject: [PATCH 4/5] Fix merge to 17.12 version --- .../src/Language/Components/ComponentDocumentClassifierPass.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dabd354eb9b..7e5ea8c04e4 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 @@ -99,7 +99,7 @@ protected override void OnDocumentStructureCreated( { // We don't want component imports to be considered as real component. // But we still want to generate code for it so we can get diagnostics. - @class.BaseType = new BaseTypeWithModel("object"); + @class.BaseType = new BaseTypeWithModel(typeof(object).FullName); method.ReturnType = "void"; method.MethodName = "Execute"; From 9b20f1ea9a5a96e95acc297b94c23306704b2c09 Mon Sep 17 00:00:00 2001 From: Andrew Hall Date: Fri, 18 Oct 2024 17:36:23 -0700 Subject: [PATCH 5/5] Update src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs --- .../src/Language/Components/ComponentDocumentClassifierPass.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7e5ea8c04e4..dabd354eb9b 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 @@ -99,7 +99,7 @@ protected override void OnDocumentStructureCreated( { // We don't want component imports to be considered as real component. // But we still want to generate code for it so we can get diagnostics. - @class.BaseType = new BaseTypeWithModel(typeof(object).FullName); + @class.BaseType = new BaseTypeWithModel("object"); method.ReturnType = "void"; method.MethodName = "Execute";