From 6645b874603ea5f6f62626b8fd430a659a820554 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Wed, 3 Feb 2021 14:04:15 -0800 Subject: [PATCH 01/10] tmp --- .../CodeGenerationIntegrationTest.cs | 28 ++++++++- .../View_WithCssScope.codegen.cs | 47 +++++++++++++++ .../View_WithCssScope.ir.txt | 59 +++++++++++++++++++ .../src/Components/ComponentCssScopePass.cs | 46 ++++++++++++--- .../src/RazorProjectEngine.cs | 7 ++- .../IntegrationTests/IntegrationTestBase.cs | 9 +-- 6 files changed, 180 insertions(+), 16 deletions(-) create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 0fa87ec5f795..8a17dd7a2cab 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -1,6 +1,9 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.IntegrationTests; @@ -47,6 +50,29 @@ public void UsingDirectives_Runtime() Assert.Equal("The using directive for 'System' appeared previously in this namespace", Assert.Single(diagnostics).GetMessage()); } + [Fact] + public void View_WithCssScope() + { + // Arrange + // Act + // This test case attempts to use all syntaxes that might interact with auto-generated attributes + var generated = CompileToCSharp(@"@page +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + ViewData[""Title""] = ""Home page""; +} +
+

Welcome

+

Learn about building Web apps with ASP.NET Core.

+
+", cssScope: "TestCssScope"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument.GetDocumentIntermediateNode()); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument.GetCSharpDocument()); + CompileToAssembly(generated); + } + [Fact] public void InvalidNamespaceAtEOF_Runtime() { diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs new file mode 100644 index 000000000000..40b6feb2900c --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs @@ -0,0 +1,47 @@ +#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "0d0437912d83146daedd58004c059383d0ee66c5" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.razor-page", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] +[assembly:global::Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.RazorPageAttribute(@"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml", typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), null)] +namespace AspNetCore +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Rendering; + using Microsoft.AspNetCore.Mvc.ViewFeatures; + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"0d0437912d83146daedd58004c059383d0ee66c5", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.RazorPages.Page + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#line 2 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" + + ViewData["Title"] = "Home page"; + +#line default +#line hidden + BeginContext(52, 191, true); + WriteLiteral("
\r\n

Welcome

\r\n

Learn about building Web apps with ASP.NET Core.

\r\n
\r\n"); + EndContext(); + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; + public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt new file mode 100644 index 000000000000..58aaabbd6116 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt @@ -0,0 +1,59 @@ +Document - + RazorCompiledItemAttribute - + CSharpCode - + IntermediateToken - - CSharp - [assembly:global::Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.RazorPageAttribute(@"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml", typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), null)] + NamespaceDeclaration - - AspNetCore + UsingDirective - (1:0,1 [14] ) - System + UsingDirective - (16:1,1 [34] ) - System.Collections.Generic + UsingDirective - (51:2,1 [19] ) - System.Linq + UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.RazorPages.Page - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - (9:1,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (9:1,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - \n ViewData["Title"] = "Home page";\n + CSharpCode - + IntermediateToken - - CSharp - BeginContext(52, 191, true); + HtmlContent - (52:4,0 [191] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (52:4,0 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
+ LazyIntermediateToken - (77:4,25 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (83:5,4 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (105:5,26 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Welcome + LazyIntermediateToken - (112:5,33 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (117:5,38 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (123:6,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (126:6,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Learn about + LazyIntermediateToken - (137:6,18 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (188:6,69 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - building Web apps with ASP.NET Core + LazyIntermediateToken - (224:6,105 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (228:6,109 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - . + LazyIntermediateToken - (229:6,110 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (233:6,114 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (235:7,0 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
+ LazyIntermediateToken - (241:7,6 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + CSharpCode - + IntermediateToken - - CSharp - EndContext(); + Inject - + Inject - + Inject - + Inject - + Inject - + CSharpCode - + IntermediateToken - - CSharp - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; + CSharpCode - + IntermediateToken - - CSharp - public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs index 9192f23e692f..e45aaa044832 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -14,21 +14,51 @@ internal class ComponentCssScopePass : ComponentIntermediateNodePassBase, IRazor protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) { - if (!IsComponentDocument(documentNode)) + var cssScope = codeDocument.GetCssScope(); + if (string.IsNullOrEmpty(cssScope)) { return; } - var cssScope = codeDocument.GetCssScope(); - if (string.IsNullOrEmpty(cssScope)) + if (IsComponentDocument(documentNode)) { - return; + var nodes = documentNode.FindDescendantNodes(); + for (var i = 0; i < nodes.Count; i++) + { + ProcessElement(nodes[i], cssScope); + } } + else + { + System.Diagnostics.Debugger.Launch(); + var nodes = documentNode.FindDescendantNodes(); + for (var i = 0; i < nodes.Count; i++) + { + ProcessElement(nodes[i], cssScope); + } + } + } - var nodes = documentNode.FindDescendantNodes(); - for (var i = 0; i < nodes.Count; i++) + private void ProcessElement(HtmlContentIntermediateNode node, string cssScope) + { + cssScope = " " + cssScope; + // Add a minimized attribute whose name is simply the CSS scope + for (var i = 0; i < node.Children.Count; i++) { - ProcessElement(nodes[i], cssScope); + var child = node.Children[i]; + if (child is IntermediateToken token && token.IsHtml) + { + var content = token.Content; + if (content.StartsWith("<") && !content.StartsWith(" cssScope, + Kind = TokenKind.Html, + Source = null + }); + i++; + } + } } } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorProjectEngine.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorProjectEngine.cs index 1d664e8028eb..78f7350eee0a 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorProjectEngine.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorProjectEngine.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -54,7 +54,7 @@ public virtual RazorCodeDocument ProcessDesignTime(RazorSourceDocument source, s { throw new NotImplementedException(); } - + public virtual RazorCodeDocument ProcessDesignTime(RazorProjectItem projectItem) { if (projectItem == null) @@ -172,6 +172,7 @@ private static void AddDefaultFeatures(ICollection features) features.Add(new DefaultTagHelperOptimizationPass()); features.Add(new PreallocatedTagHelperAttributeOptimizationPass()); features.Add(new EliminateMethodBodyPass()); + features.Add(new ComponentCssScopePass()); // Default Code Target Extensions var targetExtensionFeature = new DefaultRazorTargetExtensionFeature(); @@ -228,7 +229,7 @@ private static void AddComponentFeatures(RazorProjectEngineBuilder builder, Razo // Directive Classifier builder.Features.Add(new ComponentWhitespacePass()); - + // Optimization builder.Features.Add(new ComponentComplexAttributeContentPass()); builder.Features.Add(new ComponentLoweringPass()); diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs index 02024ecb1d49..2b724538a808 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/IntegrationTestBase.cs @@ -133,7 +133,7 @@ protected RazorProjectItem AddProjectItemFromText(string text, string filePath = return projectItem; } - private RazorProjectItem CreateProjectItemFromText(string text, string filePath) + private RazorProjectItem CreateProjectItemFromText(string text, string filePath, string? cssScope = null) { // Consider the file path to be relative to the 'FileName' of the test. var workingDirectory = Path.GetDirectoryName(FileName); @@ -158,7 +158,8 @@ private RazorProjectItem CreateProjectItemFromText(string text, string filePath) basePath: basePath, filePath: filePath, physicalPath: physicalPath, - relativePhysicalPath: relativePhysicalPath) + relativePhysicalPath: relativePhysicalPath, + cssScope: cssScope) { Content = text, }; @@ -212,9 +213,9 @@ protected RazorProjectItem CreateProjectItemFromFile(string? filePath = null, st return projectItem; } - protected CompiledCSharpCode CompileToCSharp(string text, string path = "test.cshtml", bool? designTime = null) + protected CompiledCSharpCode CompileToCSharp(string text, string path = "test.cshtml", bool? designTime = null, string? cssScope = null) { - var projectItem = CreateProjectItemFromText(text, path); + var projectItem = CreateProjectItemFromText(text, path, cssScope); return CompileToCSharp(projectItem, designTime); } From 850a3a024e9ef1e9d83360fc3a29404b98356660 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 4 Feb 2021 08:46:33 -0800 Subject: [PATCH 02/10] tmp --- .../CodeGenerationIntegrationTest.cs | 23 ---- .../CodeGenerationIntegrationTest.cs | 45 +++++++- .../View_WithCssScope.codegen.cs | 102 ++++++++++++++++++ .../View_WithCssScope.ir.txt | 82 ++++++++++++++ .../src/Components/ComponentCssScopePass.cs | 1 - .../src/Extensions/ViewCssScopePass.cs | 70 ++++++++++++ .../src/RazorProjectEngine.cs | 2 +- 7 files changed, 299 insertions(+), 26 deletions(-) create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 8a17dd7a2cab..507b03d23b11 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -50,29 +50,6 @@ public void UsingDirectives_Runtime() Assert.Equal("The using directive for 'System' appeared previously in this namespace", Assert.Single(diagnostics).GetMessage()); } - [Fact] - public void View_WithCssScope() - { - // Arrange - // Act - // This test case attempts to use all syntaxes that might interact with auto-generated attributes - var generated = CompileToCSharp(@"@page -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers -@{ - ViewData[""Title""] = ""Home page""; -} -
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

-
-", cssScope: "TestCssScope"); - - // Assert - AssertDocumentNodeMatchesBaseline(generated.CodeDocument.GetDocumentIntermediateNode()); - AssertCSharpDocumentMatchesBaseline(generated.CodeDocument.GetCSharpDocument()); - CompileToAssembly(generated); - } - [Fact] public void InvalidNamespaceAtEOF_Runtime() { diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 6acb3d4bf4d3..bcbce014b987 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; @@ -525,6 +525,49 @@ public void RazorPageWithNoLeadingPageDirective_Runtime() var diagnotics = compiled.CodeDocument.GetCSharpDocument().Diagnostics; Assert.Equal("RZ3906", Assert.Single(diagnotics).Id); } + + [Fact] + public void View_WithCssScope() + { + // Arrange + AddCSharpSyntaxTree($@" +[{typeof(HtmlTargetElementAttribute).FullName}({"\"all\""})] +public class AllTagHelper : {typeof(TagHelper).FullName} +{{ + public string Bar {{ get; set; }} +}} + +[{typeof(HtmlTargetElementAttribute).FullName}({"\"form\""})] +public class FormTagHelper : {typeof(TagHelper).FullName} +{{ +}} +"); + + // Act + // This test case attempts to use all syntaxes that might interact with auto-generated attributes + var generated = CompileToCSharp(@"@page +@addTagHelper *, AppCode +@{ + ViewData[""Title""] = ""Home page""; +} +
+

Welcome

+

Learn about building Web apps with ASP.NET Core.

+
+ +
+ +
+", cssScope: "TestCssScope"); + + // Assert + var intermediate = generated.CodeDocument.GetDocumentIntermediateNode(); + var csharp = generated.CodeDocument.GetCSharpDocument(); + AssertDocumentNodeMatchesBaseline(intermediate); + AssertCSharpDocumentMatchesBaseline(csharp); + CompileToAssembly(generated); + } + #endregion #region DesignTime diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs new file mode 100644 index 000000000000..47c51e7662e3 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs @@ -0,0 +1,102 @@ +#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "49d2096aaab8b6d729072d0a3bd7f0417de686ed" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.razor-page", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] +namespace AspNetCore +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Rendering; + using Microsoft.AspNetCore.Mvc.ViewFeatures; + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"49d2096aaab8b6d729072d0a3bd7f0417de686ed", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.RazorPages.Page + { + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_0 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("Bar", "Foo", global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_1 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("asp-route", new global::Microsoft.AspNetCore.Html.HtmlString("register"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_2 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("method", new global::Microsoft.AspNetCore.Html.HtmlString("post"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + #line hidden + #pragma warning disable 0649 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext; + #pragma warning restore 0649 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner(); + #pragma warning disable 0169 + private string __tagHelperStringValueBuffer; + #pragma warning restore 0169 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null; + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager + { + get + { + if (__backed__tagHelperScopeManager == null) + { + __backed__tagHelperScopeManager = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope); + } + return __backed__tagHelperScopeManager; + } + } + private global::AllTagHelper __AllTagHelper; + private global::FormTagHelper __FormTagHelper; + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#nullable restore +#line 3 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" + + ViewData["Title"] = "Home page"; + +#line default +#line hidden +#nullable disable + WriteLiteral("
\r\n

Welcome

\r\n

Learn about building Web apps with ASP.NET Core.

\r\n
\r\n"); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("all", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + } + ); + __AllTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__AllTagHelper); + __AllTagHelper.Bar = (string)__tagHelperAttribute_0.Value; + __tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_0); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + WriteLiteral("\r\n"); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("form", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + WriteLiteral("\r\n \r\n"); + } + ); + __FormTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__FormTagHelper); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + WriteLiteral("\r\n"); + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; + public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt new file mode 100644 index 000000000000..41fd3f52e026 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt @@ -0,0 +1,82 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCore + UsingDirective - (1:0,1 [14] ) - System + UsingDirective - (16:1,1 [34] ) - System.Collections.Generic + UsingDirective - (51:2,1 [19] ) - System.Linq + UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.RazorPages.Page - + PreallocatedTagHelperPropertyValue - - __tagHelperAttribute_0 - Bar - Foo - HtmlAttributeValueStyle.DoubleQuotes + PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_1 - asp-route - register - HtmlAttributeValueStyle.DoubleQuotes + PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_2 - method - post - HtmlAttributeValueStyle.DoubleQuotes + DefaultTagHelperRuntime - + FieldDeclaration - - private - global::AllTagHelper - __AllTagHelper + FieldDeclaration - - private - global::FormTagHelper - __FormTagHelper + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - \n ViewData["Title"] = "Home page";\n + HtmlContent - (78:5,0 [191] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (78:5,0 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
+ LazyIntermediateToken - (103:5,25 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (109:6,4 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (131:6,26 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Welcome + LazyIntermediateToken - (138:6,33 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (143:6,38 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (149:7,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (152:7,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Learn about + LazyIntermediateToken - (163:7,18 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (214:7,69 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - building Web apps with ASP.NET Core + LazyIntermediateToken - (250:7,105 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (254:7,109 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - . + LazyIntermediateToken - (255:7,110 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (259:7,114 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (261:8,0 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
+ LazyIntermediateToken - (267:8,6 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + TagHelper - (269:9,0 [21] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - all - TagMode.StartTagAndEndTag + DefaultTagHelperBody - + DefaultTagHelperCreate - - AllTagHelper + PreallocatedTagHelperProperty - (279:9,10 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - __tagHelperAttribute_0 - Bar - Bar + DefaultTagHelperExecute - + HtmlContent - (290:9,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (290:9,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + TagHelper - (292:10,0 [84] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - form - TagMode.StartTagAndEndTag + DefaultTagHelperBody - + HtmlContent - (333:10,41 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (333:10,41 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (337:11,2 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (367:11,32 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + DefaultTagHelperCreate - - FormTagHelper + PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_1 + PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_2 + DefaultTagHelperExecute - + HtmlContent - (376:12,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (376:12,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - + CSharpCode - + IntermediateToken - - CSharp - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; + CSharpCode - + IntermediateToken - - CSharp - public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs index e45aaa044832..b053d519f473 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs @@ -30,7 +30,6 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte } else { - System.Diagnostics.Debugger.Launch(); var nodes = documentNode.FindDescendantNodes(); for (var i = 0; i < nodes.Count; i++) { diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs new file mode 100644 index 000000000000..70cd7f8064cd --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs @@ -0,0 +1,70 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Razor.Language.Extensions +{ + internal class ViewCssScopePass : IntermediateNodePassBase, IRazorOptimizationPass + { + // Runs after components/bind, since it's preferable for the auto-generated attribute to appear later + // in the DOM than developer-written ones + public override int Order => 110; + + protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) + { + var cssScope = codeDocument.GetCssScope(); + if (string.IsNullOrEmpty(cssScope)) + { + return; + } + + if (!string.Equals(documentNode.DocumentKind, "mvc.1.0.view", StringComparison.Ordinal)) + { + return; + } + + var nodes = documentNode.FindDescendantNodes(); + for (var i = 0; i < nodes.Count; i++) + { + ProcessElement(nodes[i], cssScope); + } + } + + private void ProcessElement(HtmlContentIntermediateNode node, string cssScope) + { + cssScope = " " + cssScope; + // Add a minimized attribute whose name is simply the CSS scope + for (var i = 0; i < node.Children.Count; i++) + { + var child = node.Children[i]; + if (child is IntermediateToken token && token.IsHtml) + { + var content = token.Content; + if (content.StartsWith("<") && !content.StartsWith(" features) features.Add(new DefaultTagHelperOptimizationPass()); features.Add(new PreallocatedTagHelperAttributeOptimizationPass()); features.Add(new EliminateMethodBodyPass()); - features.Add(new ComponentCssScopePass()); + features.Add(new ViewCssScopePass()); // Default Code Target Extensions var targetExtensionFeature = new DefaultRazorTargetExtensionFeature(); From 26bbc50b1b0b54b2b5e6642afc5d7e9396d0d1a1 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 4 Feb 2021 08:48:56 -0800 Subject: [PATCH 03/10] Undo unwanted changes --- .../CodeGenerationIntegrationTest.cs | 5 +- .../View_WithCssScope.codegen.cs | 47 --------------- .../View_WithCssScope.ir.txt | 59 ------------------- .../src/Components/ComponentCssScopePass.cs | 45 +++----------- 4 files changed, 9 insertions(+), 147 deletions(-) delete mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs delete mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 507b03d23b11..0fa87ec5f795 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -1,9 +1,6 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.IntegrationTests; diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs deleted file mode 100644 index 40b6feb2900c..000000000000 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs +++ /dev/null @@ -1,47 +0,0 @@ -#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "0d0437912d83146daedd58004c059383d0ee66c5" -// -#pragma warning disable 1591 -[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.razor-page", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] -[assembly:global::Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.RazorPageAttribute(@"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml", typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), null)] -namespace AspNetCore -{ - #line hidden - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using Microsoft.AspNetCore.Mvc; - using Microsoft.AspNetCore.Mvc.Rendering; - using Microsoft.AspNetCore.Mvc.ViewFeatures; - [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"0d0437912d83146daedd58004c059383d0ee66c5", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.RazorPages.Page - { - #pragma warning disable 1998 - public async override global::System.Threading.Tasks.Task ExecuteAsync() - { -#line 2 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" - - ViewData["Title"] = "Home page"; - -#line default -#line hidden - BeginContext(52, 191, true); - WriteLiteral("
\r\n

Welcome

\r\n

Learn about building Web apps with ASP.NET Core.

\r\n
\r\n"); - EndContext(); - } - #pragma warning restore 1998 - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; - public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; - } -} -#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt deleted file mode 100644 index 58aaabbd6116..000000000000 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions.Version2_X/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt +++ /dev/null @@ -1,59 +0,0 @@ -Document - - RazorCompiledItemAttribute - - CSharpCode - - IntermediateToken - - CSharp - [assembly:global::Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.RazorPageAttribute(@"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml", typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), null)] - NamespaceDeclaration - - AspNetCore - UsingDirective - (1:0,1 [14] ) - System - UsingDirective - (16:1,1 [34] ) - System.Collections.Generic - UsingDirective - (51:2,1 [19] ) - System.Linq - UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks - UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc - UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering - UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures - RazorSourceChecksumAttribute - - ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.RazorPages.Page - - MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync - CSharpCode - (9:1,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - LazyIntermediateToken - (9:1,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - \n ViewData["Title"] = "Home page";\n - CSharpCode - - IntermediateToken - - CSharp - BeginContext(52, 191, true); - HtmlContent - (52:4,0 [191] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - LazyIntermediateToken - (52:4,0 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
- LazyIntermediateToken - (77:4,25 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - LazyIntermediateToken - (83:5,4 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

- LazyIntermediateToken - (105:5,26 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Welcome - LazyIntermediateToken - (112:5,33 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

- LazyIntermediateToken - (117:5,38 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - LazyIntermediateToken - (123:6,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

- LazyIntermediateToken - (126:6,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Learn about - LazyIntermediateToken - (137:6,18 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - - LazyIntermediateToken - (188:6,69 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - building Web apps with ASP.NET Core - LazyIntermediateToken - (224:6,105 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - - LazyIntermediateToken - (228:6,109 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - . - LazyIntermediateToken - (229:6,110 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

- LazyIntermediateToken - (233:6,114 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - LazyIntermediateToken - (235:7,0 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
- LazyIntermediateToken - (241:7,6 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - CSharpCode - - IntermediateToken - - CSharp - EndContext(); - Inject - - Inject - - Inject - - Inject - - Inject - - CSharpCode - - IntermediateToken - - CSharp - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; - CSharpCode - - IntermediateToken - - CSharp - public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs index b053d519f473..9192f23e692f 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentCssScopePass.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -14,50 +14,21 @@ internal class ComponentCssScopePass : ComponentIntermediateNodePassBase, IRazor protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) { - var cssScope = codeDocument.GetCssScope(); - if (string.IsNullOrEmpty(cssScope)) + if (!IsComponentDocument(documentNode)) { return; } - if (IsComponentDocument(documentNode)) - { - var nodes = documentNode.FindDescendantNodes(); - for (var i = 0; i < nodes.Count; i++) - { - ProcessElement(nodes[i], cssScope); - } - } - else + var cssScope = codeDocument.GetCssScope(); + if (string.IsNullOrEmpty(cssScope)) { - var nodes = documentNode.FindDescendantNodes(); - for (var i = 0; i < nodes.Count; i++) - { - ProcessElement(nodes[i], cssScope); - } + return; } - } - private void ProcessElement(HtmlContentIntermediateNode node, string cssScope) - { - cssScope = " " + cssScope; - // Add a minimized attribute whose name is simply the CSS scope - for (var i = 0; i < node.Children.Count; i++) + var nodes = documentNode.FindDescendantNodes(); + for (var i = 0; i < nodes.Count; i++) { - var child = node.Children[i]; - if (child is IntermediateToken token && token.IsHtml) - { - var content = token.Content; - if (content.StartsWith("<") && !content.StartsWith(" cssScope, - Kind = TokenKind.Html, - Source = null - }); - i++; - } - } + ProcessElement(nodes[i], cssScope); } } From f9159b70c7b24ee982f06edc30918efa2cdf89ea Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 4 Feb 2021 08:50:43 -0800 Subject: [PATCH 04/10] Cleanup --- .../src/Extensions/ViewCssScopePass.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs index 70cd7f8064cd..132cf9835394 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs @@ -8,8 +8,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { internal class ViewCssScopePass : IntermediateNodePassBase, IRazorOptimizationPass { - // Runs after components/bind, since it's preferable for the auto-generated attribute to appear later - // in the DOM than developer-written ones + // Runs after taghelpers are bound public override int Order => 110; protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) From fbc96ab12c5fe31226baac2b466ab37d614dd278 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 4 Feb 2021 10:10:18 -0800 Subject: [PATCH 05/10] Fix test --- .../View_WithCssScope.ir.txt | 10 +++++----- .../src/Extensions/ViewCssScopePass.cs | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt index 41fd3f52e026..1422496c1a2a 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt @@ -21,23 +21,23 @@ Document - LazyIntermediateToken - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - \n ViewData["Title"] = "Home page";\n HtmlContent - (78:5,0 [191] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) LazyIntermediateToken - (78:5,0 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
LazyIntermediateToken - (103:5,25 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n LazyIntermediateToken - (109:6,4 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

LazyIntermediateToken - (131:6,26 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Welcome LazyIntermediateToken - (138:6,33 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

LazyIntermediateToken - (143:6,38 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n LazyIntermediateToken - (149:7,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

LazyIntermediateToken - (152:7,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Learn about LazyIntermediateToken - (163:7,18 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - @@ -60,7 +60,7 @@ Document - HtmlContent - (333:10,41 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) LazyIntermediateToken - (333:10,41 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n LazyIntermediateToken - (337:11,2 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs index 132cf9835394..fba91b4eb4c9 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs @@ -19,7 +19,8 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte return; } - if (!string.Equals(documentNode.DocumentKind, "mvc.1.0.view", StringComparison.Ordinal)) + if (!string.Equals(documentNode.DocumentKind, "mvc.1.0.view", StringComparison.Ordinal) && + !string.Equals(documentNode.DocumentKind, "mvc.1.0.razor-page", StringComparison.Ordinal)) { return; } From 59c364938085d10cbeb5e8c03d04761af0282394 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 4 Feb 2021 10:22:57 -0800 Subject: [PATCH 06/10] Add test for views --- .../CodeGenerationIntegrationTest.cs | 43 +++++++- .../RazorPage_WithCssScope.codegen.cs | 102 ++++++++++++++++++ .../RazorPage_WithCssScope.ir.txt | 82 ++++++++++++++ .../RazorView_WithCssScope.codegen.cs | 100 +++++++++++++++++ .../RazorView_WithCssScope.ir.txt | 78 ++++++++++++++ 5 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPage_WithCssScope.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPage_WithCssScope.ir.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithCssScope.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithCssScope.ir.txt diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs index bcbce014b987..49d5f463f7c2 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -527,7 +527,7 @@ public void RazorPageWithNoLeadingPageDirective_Runtime() } [Fact] - public void View_WithCssScope() + public void RazorPage_WithCssScope() { // Arrange AddCSharpSyntaxTree($@" @@ -568,6 +568,47 @@ public class FormTagHelper : {typeof(TagHelper).FullName} CompileToAssembly(generated); } + [Fact] + public void RazorView_WithCssScope() + { + // Arrange + AddCSharpSyntaxTree($@" +[{typeof(HtmlTargetElementAttribute).FullName}({"\"all\""})] +public class AllTagHelper : {typeof(TagHelper).FullName} +{{ + public string Bar {{ get; set; }} +}} + +[{typeof(HtmlTargetElementAttribute).FullName}({"\"form\""})] +public class FormTagHelper : {typeof(TagHelper).FullName} +{{ +}} +"); + + // Act + // This test case attempts to use all syntaxes that might interact with auto-generated attributes + var generated = CompileToCSharp(@"@addTagHelper *, AppCode +@{ + ViewData[""Title""] = ""Home page""; +} +

+ +
+ +
+", cssScope: "TestCssScope"); + + // Assert + var intermediate = generated.CodeDocument.GetDocumentIntermediateNode(); + var csharp = generated.CodeDocument.GetCSharpDocument(); + AssertDocumentNodeMatchesBaseline(intermediate); + AssertCSharpDocumentMatchesBaseline(csharp); + CompileToAssembly(generated); + } + #endregion #region DesignTime diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPage_WithCssScope.codegen.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPage_WithCssScope.codegen.cs new file mode 100644 index 000000000000..47c51e7662e3 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPage_WithCssScope.codegen.cs @@ -0,0 +1,102 @@ +#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "49d2096aaab8b6d729072d0a3bd7f0417de686ed" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.razor-page", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] +namespace AspNetCore +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Rendering; + using Microsoft.AspNetCore.Mvc.ViewFeatures; + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"49d2096aaab8b6d729072d0a3bd7f0417de686ed", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.RazorPages.Page + { + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_0 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("Bar", "Foo", global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_1 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("asp-route", new global::Microsoft.AspNetCore.Html.HtmlString("register"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_2 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("method", new global::Microsoft.AspNetCore.Html.HtmlString("post"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + #line hidden + #pragma warning disable 0649 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext; + #pragma warning restore 0649 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner(); + #pragma warning disable 0169 + private string __tagHelperStringValueBuffer; + #pragma warning restore 0169 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null; + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager + { + get + { + if (__backed__tagHelperScopeManager == null) + { + __backed__tagHelperScopeManager = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope); + } + return __backed__tagHelperScopeManager; + } + } + private global::AllTagHelper __AllTagHelper; + private global::FormTagHelper __FormTagHelper; + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#nullable restore +#line 3 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" + + ViewData["Title"] = "Home page"; + +#line default +#line hidden +#nullable disable + WriteLiteral("
\r\n

Welcome

\r\n

Learn about building Web apps with ASP.NET Core.

\r\n
\r\n"); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("all", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + } + ); + __AllTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__AllTagHelper); + __AllTagHelper.Bar = (string)__tagHelperAttribute_0.Value; + __tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_0); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + WriteLiteral("\r\n"); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("form", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + WriteLiteral("\r\n \r\n"); + } + ); + __FormTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__FormTagHelper); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + WriteLiteral("\r\n"); + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; + public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPage_WithCssScope.ir.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPage_WithCssScope.ir.txt new file mode 100644 index 000000000000..1422496c1a2a --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorPage_WithCssScope.ir.txt @@ -0,0 +1,82 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCore + UsingDirective - (1:0,1 [14] ) - System + UsingDirective - (16:1,1 [34] ) - System.Collections.Generic + UsingDirective - (51:2,1 [19] ) - System.Linq + UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.RazorPages.Page - + PreallocatedTagHelperPropertyValue - - __tagHelperAttribute_0 - Bar - Foo - HtmlAttributeValueStyle.DoubleQuotes + PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_1 - asp-route - register - HtmlAttributeValueStyle.DoubleQuotes + PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_2 - method - post - HtmlAttributeValueStyle.DoubleQuotes + DefaultTagHelperRuntime - + FieldDeclaration - - private - global::AllTagHelper - __AllTagHelper + FieldDeclaration - - private - global::FormTagHelper - __FormTagHelper + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - \n ViewData["Title"] = "Home page";\n + HtmlContent - (78:5,0 [191] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (78:5,0 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
+ LazyIntermediateToken - (103:5,25 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (109:6,4 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (131:6,26 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Welcome + LazyIntermediateToken - (138:6,33 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (143:6,38 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (149:7,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (152:7,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Learn about + LazyIntermediateToken - (163:7,18 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (214:7,69 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - building Web apps with ASP.NET Core + LazyIntermediateToken - (250:7,105 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (254:7,109 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - . + LazyIntermediateToken - (255:7,110 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (259:7,114 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (261:8,0 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
+ LazyIntermediateToken - (267:8,6 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + TagHelper - (269:9,0 [21] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - all - TagMode.StartTagAndEndTag + DefaultTagHelperBody - + DefaultTagHelperCreate - - AllTagHelper + PreallocatedTagHelperProperty - (279:9,10 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - __tagHelperAttribute_0 - Bar - Bar + DefaultTagHelperExecute - + HtmlContent - (290:9,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (290:9,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + TagHelper - (292:10,0 [84] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - form - TagMode.StartTagAndEndTag + DefaultTagHelperBody - + HtmlContent - (333:10,41 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (333:10,41 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (337:11,2 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (367:11,32 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + DefaultTagHelperCreate - - FormTagHelper + PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_1 + PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_2 + DefaultTagHelperExecute - + HtmlContent - (376:12,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (376:12,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - + CSharpCode - + IntermediateToken - - CSharp - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; + CSharpCode - + IntermediateToken - - CSharp - public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithCssScope.codegen.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithCssScope.codegen.cs new file mode 100644 index 000000000000..e51167c1f7e0 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithCssScope.codegen.cs @@ -0,0 +1,100 @@ +#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "1df3059703826ccbcf3c807ea436c462bbd7c760" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.view", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] +namespace AspNetCore +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Rendering; + using Microsoft.AspNetCore.Mvc.ViewFeatures; + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"1df3059703826ccbcf3c807ea436c462bbd7c760", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] + public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + { + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_0 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("Bar", "Foo", global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_1 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("asp-route", new global::Microsoft.AspNetCore.Html.HtmlString("register"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_2 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("method", new global::Microsoft.AspNetCore.Html.HtmlString("post"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); + #line hidden + #pragma warning disable 0649 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext; + #pragma warning restore 0649 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner(); + #pragma warning disable 0169 + private string __tagHelperStringValueBuffer; + #pragma warning restore 0169 + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null; + private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager + { + get + { + if (__backed__tagHelperScopeManager == null) + { + __backed__tagHelperScopeManager = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope); + } + return __backed__tagHelperScopeManager; + } + } + private global::AllTagHelper __AllTagHelper; + private global::FormTagHelper __FormTagHelper; + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { +#nullable restore +#line 2 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" + + ViewData["Title"] = "Home page"; + +#line default +#line hidden +#nullable disable + WriteLiteral("
\r\n

Welcome

\r\n

Learn about building Web apps with ASP.NET Core.

\r\n
\r\n"); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("all", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + } + ); + __AllTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__AllTagHelper); + __AllTagHelper.Bar = (string)__tagHelperAttribute_0.Value; + __tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_0); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + WriteLiteral("\r\n"); + __tagHelperExecutionContext = __tagHelperScopeManager.Begin("form", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { + WriteLiteral("\r\n \r\n"); + } + ); + __FormTagHelper = CreateTagHelper(); + __tagHelperExecutionContext.Add(__FormTagHelper); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1); + __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2); + await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); + if (!__tagHelperExecutionContext.Output.IsContentModified) + { + await __tagHelperExecutionContext.SetOutputContentAsync(); + } + Write(__tagHelperExecutionContext.Output); + __tagHelperExecutionContext = __tagHelperScopeManager.End(); + WriteLiteral("\r\n"); + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithCssScope.ir.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithCssScope.ir.txt new file mode 100644 index 000000000000..ceb10cb442a6 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorView_WithCssScope.ir.txt @@ -0,0 +1,78 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCore + UsingDirective - (1:0,1 [14] ) - System + UsingDirective - (16:1,1 [34] ) - System.Collections.Generic + UsingDirective - (51:2,1 [19] ) - System.Linq + UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks + UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc + UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + PreallocatedTagHelperPropertyValue - - __tagHelperAttribute_0 - Bar - Foo - HtmlAttributeValueStyle.DoubleQuotes + PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_1 - asp-route - register - HtmlAttributeValueStyle.DoubleQuotes + PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_2 - method - post - HtmlAttributeValueStyle.DoubleQuotes + DefaultTagHelperRuntime - + FieldDeclaration - - private - global::AllTagHelper - __AllTagHelper + FieldDeclaration - - private - global::FormTagHelper - __FormTagHelper + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + CSharpCode - (28:1,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (28:1,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - \n ViewData["Title"] = "Home page";\n + HtmlContent - (71:4,0 [191] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (71:4,0 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
+ LazyIntermediateToken - (96:4,25 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (102:5,4 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (124:5,26 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Welcome + LazyIntermediateToken - (131:5,33 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (136:5,38 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (142:6,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (145:6,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Learn about + LazyIntermediateToken - (156:6,18 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (207:6,69 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - building Web apps with ASP.NET Core + LazyIntermediateToken - (243:6,105 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (247:6,109 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - . + LazyIntermediateToken - (248:6,110 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

+ LazyIntermediateToken - (252:6,114 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (254:7,0 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
+ LazyIntermediateToken - (260:7,6 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + TagHelper - (262:8,0 [21] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - all - TagMode.StartTagAndEndTag + DefaultTagHelperBody - + DefaultTagHelperCreate - - AllTagHelper + PreallocatedTagHelperProperty - (272:8,10 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - __tagHelperAttribute_0 - Bar - Bar + DefaultTagHelperExecute - + HtmlContent - (283:8,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (283:8,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + TagHelper - (285:9,0 [84] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - form - TagMode.StartTagAndEndTag + DefaultTagHelperBody - + HtmlContent - (326:9,41 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (326:9,41 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + LazyIntermediateToken - (330:10,2 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - + LazyIntermediateToken - (360:10,32 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + DefaultTagHelperCreate - - FormTagHelper + PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_1 + PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_2 + DefaultTagHelperExecute - + HtmlContent - (369:11,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) + LazyIntermediateToken - (369:11,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n + Inject - + Inject - + Inject - + Inject - + Inject - From c77ebca5761682d7e2824b198fcf3ebc9d0beac0 Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 4 Feb 2021 10:25:26 -0800 Subject: [PATCH 07/10] remove unnecessary files --- .../View_WithCssScope.codegen.cs | 102 ------------------ .../View_WithCssScope.ir.txt | 82 -------------- 2 files changed, 184 deletions(-) delete mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs delete mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs deleted file mode 100644 index 47c51e7662e3..000000000000 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.codegen.cs +++ /dev/null @@ -1,102 +0,0 @@ -#pragma checksum "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "49d2096aaab8b6d729072d0a3bd7f0417de686ed" -// -#pragma warning disable 1591 -[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCore.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test), @"mvc.1.0.razor-page", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] -namespace AspNetCore -{ - #line hidden - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using Microsoft.AspNetCore.Mvc; - using Microsoft.AspNetCore.Mvc.Rendering; - using Microsoft.AspNetCore.Mvc.ViewFeatures; - [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"49d2096aaab8b6d729072d0a3bd7f0417de686ed", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/test.cshtml")] - public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test : global::Microsoft.AspNetCore.Mvc.RazorPages.Page - { - private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_0 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("Bar", "Foo", global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); - private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_1 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("asp-route", new global::Microsoft.AspNetCore.Html.HtmlString("register"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); - private static readonly global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute __tagHelperAttribute_2 = new global::Microsoft.AspNetCore.Razor.TagHelpers.TagHelperAttribute("method", new global::Microsoft.AspNetCore.Html.HtmlString("post"), global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes); - #line hidden - #pragma warning disable 0649 - private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext __tagHelperExecutionContext; - #pragma warning restore 0649 - private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner(); - #pragma warning disable 0169 - private string __tagHelperStringValueBuffer; - #pragma warning restore 0169 - private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __backed__tagHelperScopeManager = null; - private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager - { - get - { - if (__backed__tagHelperScopeManager == null) - { - __backed__tagHelperScopeManager = new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope); - } - return __backed__tagHelperScopeManager; - } - } - private global::AllTagHelper __AllTagHelper; - private global::FormTagHelper __FormTagHelper; - #pragma warning disable 1998 - public async override global::System.Threading.Tasks.Task ExecuteAsync() - { -#nullable restore -#line 3 "TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml" - - ViewData["Title"] = "Home page"; - -#line default -#line hidden -#nullable disable - WriteLiteral("
\r\n

Welcome

\r\n

Learn about building Web apps with ASP.NET Core.

\r\n
\r\n"); - __tagHelperExecutionContext = __tagHelperScopeManager.Begin("all", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { - } - ); - __AllTagHelper = CreateTagHelper(); - __tagHelperExecutionContext.Add(__AllTagHelper); - __AllTagHelper.Bar = (string)__tagHelperAttribute_0.Value; - __tagHelperExecutionContext.AddTagHelperAttribute(__tagHelperAttribute_0); - await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); - if (!__tagHelperExecutionContext.Output.IsContentModified) - { - await __tagHelperExecutionContext.SetOutputContentAsync(); - } - Write(__tagHelperExecutionContext.Output); - __tagHelperExecutionContext = __tagHelperScopeManager.End(); - WriteLiteral("\r\n"); - __tagHelperExecutionContext = __tagHelperScopeManager.Begin("form", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { - WriteLiteral("\r\n \r\n"); - } - ); - __FormTagHelper = CreateTagHelper(); - __tagHelperExecutionContext.Add(__FormTagHelper); - __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_1); - __tagHelperExecutionContext.AddHtmlAttribute(__tagHelperAttribute_2); - await __tagHelperRunner.RunAsync(__tagHelperExecutionContext); - if (!__tagHelperExecutionContext.Output.IsContentModified) - { - await __tagHelperExecutionContext.SetOutputContentAsync(); - } - Write(__tagHelperExecutionContext.Output); - __tagHelperExecutionContext = __tagHelperScopeManager.End(); - WriteLiteral("\r\n"); - } - #pragma warning restore 1998 - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } - [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] - public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; - public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; - } -} -#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt deleted file mode 100644 index 1422496c1a2a..000000000000 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/View_WithCssScope.ir.txt +++ /dev/null @@ -1,82 +0,0 @@ -Document - - RazorCompiledItemAttribute - - NamespaceDeclaration - - AspNetCore - UsingDirective - (1:0,1 [14] ) - System - UsingDirective - (16:1,1 [34] ) - System.Collections.Generic - UsingDirective - (51:2,1 [19] ) - System.Linq - UsingDirective - (71:3,1 [30] ) - System.Threading.Tasks - UsingDirective - (102:4,1 [32] ) - Microsoft.AspNetCore.Mvc - UsingDirective - (135:5,1 [42] ) - Microsoft.AspNetCore.Mvc.Rendering - UsingDirective - (178:6,1 [45] ) - Microsoft.AspNetCore.Mvc.ViewFeatures - RazorSourceChecksumAttribute - - ClassDeclaration - - public - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test - global::Microsoft.AspNetCore.Mvc.RazorPages.Page - - PreallocatedTagHelperPropertyValue - - __tagHelperAttribute_0 - Bar - Foo - HtmlAttributeValueStyle.DoubleQuotes - PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_1 - asp-route - register - HtmlAttributeValueStyle.DoubleQuotes - PreallocatedTagHelperHtmlAttributeValue - - __tagHelperAttribute_2 - method - post - HtmlAttributeValueStyle.DoubleQuotes - DefaultTagHelperRuntime - - FieldDeclaration - - private - global::AllTagHelper - __AllTagHelper - FieldDeclaration - - private - global::FormTagHelper - __FormTagHelper - MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync - CSharpCode - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - LazyIntermediateToken - (35:2,2 [40] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - CSharp - \n ViewData["Title"] = "Home page";\n - HtmlContent - (78:5,0 [191] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - LazyIntermediateToken - (78:5,0 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
- LazyIntermediateToken - (103:5,25 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - LazyIntermediateToken - (109:6,4 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

- LazyIntermediateToken - (131:6,26 [7] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Welcome - LazyIntermediateToken - (138:6,33 [5] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

- LazyIntermediateToken - (143:6,38 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - LazyIntermediateToken - (149:7,4 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

- LazyIntermediateToken - (152:7,7 [11] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - Learn about - LazyIntermediateToken - (163:7,18 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - - LazyIntermediateToken - (214:7,69 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - building Web apps with ASP.NET Core - LazyIntermediateToken - (250:7,105 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - - LazyIntermediateToken - (254:7,109 [1] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - . - LazyIntermediateToken - (255:7,110 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -

- LazyIntermediateToken - (259:7,114 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - LazyIntermediateToken - (261:8,0 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html -
- LazyIntermediateToken - (267:8,6 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - TagHelper - (269:9,0 [21] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - all - TagMode.StartTagAndEndTag - DefaultTagHelperBody - - DefaultTagHelperCreate - - AllTagHelper - PreallocatedTagHelperProperty - (279:9,10 [3] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - __tagHelperAttribute_0 - Bar - Bar - DefaultTagHelperExecute - - HtmlContent - (290:9,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - LazyIntermediateToken - (290:9,21 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - TagHelper - (292:10,0 [84] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - form - TagMode.StartTagAndEndTag - DefaultTagHelperBody - - HtmlContent - (333:10,41 [36] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - LazyIntermediateToken - (333:10,41 [4] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - LazyIntermediateToken - (337:11,2 [6] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - - LazyIntermediateToken - (367:11,32 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - DefaultTagHelperCreate - - FormTagHelper - PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_1 - PreallocatedTagHelperHtmlAttribute - - __tagHelperAttribute_2 - DefaultTagHelperExecute - - HtmlContent - (376:12,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - LazyIntermediateToken - (376:12,7 [2] TestFiles\IntegrationTests\CodeGenerationIntegrationTest\test.cshtml) - Html - \n - Inject - - Inject - - Inject - - Inject - - Inject - - CSharpCode - - IntermediateToken - - CSharp - public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary)PageContext?.ViewData; - CSharpCode - - IntermediateToken - - CSharp - public TestFiles_IntegrationTests_CodeGenerationIntegrationTest_test Model => ViewData.Model; From bcc74370b9bcbe05a4ddd4f94513a353046c863b Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Thu, 4 Feb 2021 11:38:16 -0800 Subject: [PATCH 08/10] Fix broken test --- .../test/RazorProjectEngineTest.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/RazorProjectEngineTest.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/RazorProjectEngineTest.cs index d483472fa4ac..6b21818edca8 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/RazorProjectEngineTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/RazorProjectEngineTest.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Linq; @@ -83,7 +83,8 @@ private static void AssertDefaultFeatures(RazorProjectEngine engine) feature => Assert.IsType(feature), feature => Assert.IsType(feature), feature => Assert.IsType(feature), - feature => Assert.IsType(feature)); + feature => Assert.IsType(feature), + feature => Assert.IsType(feature)); } private static void AssertDefaultDirectives(RazorProjectEngine engine) From 4fc281f02ad76c43ba85b19e6ac5d8a57ce8215d Mon Sep 17 00:00:00 2001 From: Javier Calvarro Nelson Date: Tue, 16 Feb 2021 10:44:38 -0800 Subject: [PATCH 09/10] PR feedback + cleanup --- .../src/Extensions/ViewCssScopePass.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs index fba91b4eb4c9..c17844a438bb 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Extensions/ViewCssScopePass.cs @@ -25,16 +25,16 @@ protected override void ExecuteCore(RazorCodeDocument codeDocument, DocumentInte return; } + var scopeWithSeparator = " " + cssScope; var nodes = documentNode.FindDescendantNodes(); for (var i = 0; i < nodes.Count; i++) { - ProcessElement(nodes[i], cssScope); + ProcessElement(nodes[i], scopeWithSeparator); } } private void ProcessElement(HtmlContentIntermediateNode node, string cssScope) { - cssScope = " " + cssScope; // Add a minimized attribute whose name is simply the CSS scope for (var i = 0; i < node.Children.Count; i++) { @@ -42,7 +42,7 @@ private void ProcessElement(HtmlContentIntermediateNode node, string cssScope) if (child is IntermediateToken token && token.IsHtml) { var content = token.Content; - if (content.StartsWith("<") && !content.StartsWith(" Date: Tue, 16 Feb 2021 10:48:05 -0800 Subject: [PATCH 10/10] Activate feature only for 6.0 and onwards --- .../src/RazorProjectEngine.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorProjectEngine.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorProjectEngine.cs index 9da1a159a7a2..9d074110dc2a 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorProjectEngine.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorProjectEngine.cs @@ -112,6 +112,11 @@ public static RazorProjectEngine Create( AddDefaultPhases(builder.Phases); AddDefaultFeatures(builder.Features); + if (configuration.LanguageVersion.CompareTo(RazorLanguageVersion.Version_5_0) >= 0) + { + builder.Features.Add(new ViewCssScopePass()); + } + if (configuration.LanguageVersion.CompareTo(RazorLanguageVersion.Version_3_0) >= 0) { FunctionsDirective.Register(builder); @@ -172,7 +177,6 @@ private static void AddDefaultFeatures(ICollection features) features.Add(new DefaultTagHelperOptimizationPass()); features.Add(new PreallocatedTagHelperAttributeOptimizationPass()); features.Add(new EliminateMethodBodyPass()); - features.Add(new ViewCssScopePass()); // Default Code Target Extensions var targetExtensionFeature = new DefaultRazorTargetExtensionFeature();