From 876ad7ce234873db95b392cec3ec6df5f4eb16dd Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Wed, 26 Aug 2020 17:45:57 +0100 Subject: [PATCH 1/3] Write minimized attribute values explicitly for older language version --- .../src/Components/ComponentRuntimeNodeWriter.cs | 9 +++++++++ .../src/DefaultRazorCodeGenerationOptions.cs | 8 ++++++-- .../src/DefaultRazorCodeGenerationOptionsBuilder.cs | 7 +++++-- .../src/RazorCodeGenerationOptions.cs | 13 ++++++++++--- .../src/RazorCodeGenerationOptionsBuilder.cs | 7 ++++++- .../src/RazorProjectEngineBuilderExtensions.cs | 12 ++++++++---- 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentRuntimeNodeWriter.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentRuntimeNodeWriter.cs index 93df99a41eb5..005941d9156f 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentRuntimeNodeWriter.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentRuntimeNodeWriter.cs @@ -852,11 +852,20 @@ protected override void WriteReferenceCaptureInnards(CodeRenderingContext contex private void WriteAttribute(CodeRenderingContext context, string key, IList value) { BeginWriteAttribute(context, key); + if (value.Count > 0) { context.CodeWriter.WriteParameterSeparator(); WriteAttributeValue(context, value); } + else if (!context.Options.OmitMinimizedComponentAttributeValues) + { + // In version 5+, there's no need to supply a value for a minimized attribute. + // But for older language versions, minimized attributes were represented as "true". + context.CodeWriter.WriteParameterSeparator(); + context.CodeWriter.WriteBooleanLiteral(true); + } + context.CodeWriter.WriteEndMethodInvocation(); } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorCodeGenerationOptions.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorCodeGenerationOptions.cs index 5addb92cf21b..0b1441b945ac 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorCodeGenerationOptions.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorCodeGenerationOptions.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. namespace Microsoft.AspNetCore.Razor.Language @@ -13,7 +13,8 @@ public DefaultRazorCodeGenerationOptions( bool suppressChecksum, bool suppressMetadataAttributes, bool suppressPrimaryMethodBody, - bool suppressNullabilityEnforcement) + bool suppressNullabilityEnforcement, + bool omitMinimizedComponentAttributeValues) { IndentWithTabs = indentWithTabs; IndentSize = indentSize; @@ -23,6 +24,7 @@ public DefaultRazorCodeGenerationOptions( SuppressMetadataAttributes = suppressMetadataAttributes; SuppressPrimaryMethodBody = suppressPrimaryMethodBody; SuppressNullabilityEnforcement = suppressNullabilityEnforcement; + OmitMinimizedComponentAttributeValues = omitMinimizedComponentAttributeValues; } public override bool DesignTime { get; } @@ -36,5 +38,7 @@ public DefaultRazorCodeGenerationOptions( public override bool SuppressChecksum { get; } public override bool SuppressNullabilityEnforcement { get; } + + public override bool OmitMinimizedComponentAttributeValues { get; } } } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorCodeGenerationOptionsBuilder.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorCodeGenerationOptionsBuilder.cs index 12f2f119c44a..1422b410ff41 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorCodeGenerationOptionsBuilder.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorCodeGenerationOptionsBuilder.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; @@ -39,6 +39,8 @@ public DefaultRazorCodeGenerationOptionsBuilder(bool designTime) public override bool SuppressNullabilityEnforcement { get; set; } + public override bool OmitMinimizedComponentAttributeValues { get; set; } + public override RazorCodeGenerationOptions Build() { return new DefaultRazorCodeGenerationOptions( @@ -49,7 +51,8 @@ public override RazorCodeGenerationOptions Build() SuppressChecksum, SuppressMetadataAttributes, SuppressPrimaryMethodBody, - SuppressNullabilityEnforcement); + SuppressNullabilityEnforcement, + OmitMinimizedComponentAttributeValues); } public override void SetDesignTime(bool designTime) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorCodeGenerationOptions.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorCodeGenerationOptions.cs index 36a8499ba966..b481dfeb07a6 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorCodeGenerationOptions.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorCodeGenerationOptions.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; @@ -17,7 +17,8 @@ public static RazorCodeGenerationOptions CreateDefault() rootNamespace: null, suppressMetadataAttributes: false, suppressPrimaryMethodBody: false, - suppressNullabilityEnforcement: false); + suppressNullabilityEnforcement: false, + omitMinimizedComponentAttributeValues: false); } public static RazorCodeGenerationOptions CreateDesignTimeDefault() @@ -30,7 +31,8 @@ public static RazorCodeGenerationOptions CreateDesignTimeDefault() suppressChecksum: false, suppressMetadataAttributes: true, suppressPrimaryMethodBody: false, - suppressNullabilityEnforcement: false); + suppressNullabilityEnforcement: false, + omitMinimizedComponentAttributeValues: false); } public static RazorCodeGenerationOptions Create(Action configure) @@ -114,5 +116,10 @@ public static RazorCodeGenerationOptions CreateDesignTime(Action public virtual bool SuppressNullabilityEnforcement { get; } + + /// + /// Gets a value that determines if the components code writer may omit values for minimized attributes. + /// + public virtual bool OmitMinimizedComponentAttributeValues { get; } } } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorCodeGenerationOptionsBuilder.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorCodeGenerationOptionsBuilder.cs index ed6914aebebb..48d725b6145f 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorCodeGenerationOptionsBuilder.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorCodeGenerationOptionsBuilder.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. namespace Microsoft.AspNetCore.Razor.Language @@ -59,6 +59,11 @@ public abstract class RazorCodeGenerationOptionsBuilder /// public virtual bool SuppressNullabilityEnforcement { get; set; } + /// + /// Gets or sets a value that determines if the components code writer may omit values for minimized attributes. + /// + public virtual bool OmitMinimizedComponentAttributeValues { get; set; } + public abstract RazorCodeGenerationOptions Build(); public virtual void SetDesignTime(bool designTime) diff --git a/src/Razor/Microsoft.CodeAnalysis.Razor/src/RazorProjectEngineBuilderExtensions.cs b/src/Razor/Microsoft.CodeAnalysis.Razor/src/RazorProjectEngineBuilderExtensions.cs index e49264372367..aa07cd9cf6ad 100644 --- a/src/Razor/Microsoft.CodeAnalysis.Razor/src/RazorProjectEngineBuilderExtensions.cs +++ b/src/Razor/Microsoft.CodeAnalysis.Razor/src/RazorProjectEngineBuilderExtensions.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; @@ -64,10 +64,8 @@ public void Configure(RazorCodeGenerationOptionsBuilder options) { // Prior to 3.0 there were no C# version specific controlled features. Suppress nullability enforcement. options.SuppressNullabilityEnforcement = true; - return; } - - if (CSharpLanguageVersion < LanguageVersion.CSharp8) + else if (CSharpLanguageVersion < LanguageVersion.CSharp8) { // Having nullable flags < C# 8.0 would cause compile errors. options.SuppressNullabilityEnforcement = true; @@ -85,6 +83,12 @@ public void Configure(RazorCodeGenerationOptionsBuilder options) // Roslyn project and acquires the effective C# version at that point. options.SuppressNullabilityEnforcement = false; } + + if (options.Configuration?.LanguageVersion.Major >= 5) + { + // This is a useful optimization but isn't supported by older framework versions + options.OmitMinimizedComponentAttributeValues = true; + } } } } From 2dd49f08471d57c0d777225aa94d5b1869dde004 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 27 Aug 2020 12:40:56 +0100 Subject: [PATCH 2/3] Add tests --- .../ComponentCodeGenerationTestBase.cs | 36 +++++++++++++++++++ .../RazorIntegrationTestBase.cs | 4 +-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index 0308fe46c4b1..c0b3fd708e1a 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -9,10 +9,14 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests { public abstract class ComponentCodeGenerationTestBase : RazorBaselineIntegrationTestBase { + private RazorConfiguration _configuration; + internal override string FileKind => FileKinds.Component; internal override bool UseTwoPhaseCompilation => true; + internal override RazorConfiguration Configuration => _configuration ?? base.Configuration; + protected ComponentCodeGenerationTestBase() : base(generateBaselines: null) { @@ -364,6 +368,38 @@ public void MarkupComment_IsNotIncluded() CompileToAssembly(generated); } + [Fact] + public void OmitsMinimizedAttributeValueParameter() + { + // Act + var generated = CompileToCSharp(@" +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + + [Fact] + public void IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5() + { + // Arrange + _configuration = RazorConfiguration.Create( + RazorLanguageVersion.Version_3_0, + base.Configuration.ConfigurationName, + base.Configuration.Extensions); + + // Act + var generated = CompileToCSharp(@" +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [Fact] public void Component_WithFullyQualifiedTagNames() { diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs index ddd1b5dbd1c4..07f4572c5b01 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs @@ -189,7 +189,7 @@ protected CompileToCSharpResult CompileToCSharp(string cshtmlRelativePath, strin { // The first phase won't include any metadata references for component discovery. This mirrors // what the build does. - var projectEngine = CreateProjectEngine(RazorConfiguration.Default, Array.Empty()); + var projectEngine = CreateProjectEngine(Configuration, Array.Empty()); RazorCodeDocument codeDocument; foreach (var item in AdditionalRazorItems) @@ -218,7 +218,7 @@ protected CompileToCSharpResult CompileToCSharp(string cshtmlRelativePath, strin // Add the 'temp' compilation as a metadata reference var references = BaseCompilation.References.Concat(new[] { tempAssembly.Compilation.ToMetadataReference() }).ToArray(); - projectEngine = CreateProjectEngine(RazorConfiguration.Default, references); + projectEngine = CreateProjectEngine(Configuration, references); // Now update the any additional files foreach (var item in AdditionalRazorItems) From eebc670f5aa5d568a75b779416a48a02b31c0aa6 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 27 Aug 2020 12:41:09 +0100 Subject: [PATCH 3/3] Add baselines for new tests --- .../TestComponent.codegen.cs | 36 +++++++++++++++++++ .../TestComponent.ir.txt | 22 ++++++++++++ .../TestComponent.mappings.txt | 5 +++ .../TestComponent.codegen.cs | 36 +++++++++++++++++++ .../TestComponent.ir.txt | 22 ++++++++++++ .../TestComponent.mappings.txt | 5 +++ .../TestComponent.codegen.cs | 33 +++++++++++++++++ .../TestComponent.ir.txt | 15 ++++++++ .../TestComponent.codegen.cs | 33 +++++++++++++++++ .../TestComponent.ir.txt | 15 ++++++++ 10 files changed, 222 insertions(+) create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.ir.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.mappings.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.ir.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.mappings.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.ir.txt create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.codegen.cs create mode 100644 src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.ir.txt diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.codegen.cs new file mode 100644 index 000000000000..1024b82fc9aa --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.codegen.cs @@ -0,0 +1,36 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Components; + public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __o = +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + "val" + +#line default +#line hidden +#nullable disable + ; + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.ir.txt new file mode 100644 index 000000000000..ef767a96b4e1 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.ir.txt @@ -0,0 +1,22 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components + ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - + DesignTimeDirective - + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + MarkupElement - (0:0,0 [73] x:\dir\subdir\Test\TestComponent.cshtml) - elem + HtmlAttribute - (5:0,5 [23] x:\dir\subdir\Test\TestComponent.cshtml) - normal-attr=" - " + CSharpExpressionAttributeValue - (19:0,19 [8] x:\dir\subdir\Test\TestComponent.cshtml) - + LazyIntermediateToken - (21:0,21 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "val" + HtmlAttribute - (28:0,28 [15] x:\dir\subdir\Test\TestComponent.cshtml) - minimized-attr - + HtmlAttribute - (43:0,43 [22] x:\dir\subdir\Test\TestComponent.cshtml) - empty-string-atttr=" - " diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.mappings.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.mappings.txt new file mode 100644 index 000000000000..35f1e0834bea --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (21:0,21 [5] x:\dir\subdir\Test\TestComponent.cshtml) +|"val"| +Generated Location: (893:25,21 [5] ) +|"val"| + diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.codegen.cs new file mode 100644 index 000000000000..1024b82fc9aa --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.codegen.cs @@ -0,0 +1,36 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Components; + public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static System.Object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __o = +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + "val" + +#line default +#line hidden +#nullable disable + ; + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.ir.txt new file mode 100644 index 000000000000..ef767a96b4e1 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.ir.txt @@ -0,0 +1,22 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [12] ) - System + UsingDirective - (18:2,1 [32] ) - System.Collections.Generic + UsingDirective - (53:3,1 [17] ) - System.Linq + UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components + ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - + DesignTimeDirective - + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static System.Object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - protected override - void - BuildRenderTree + MarkupElement - (0:0,0 [73] x:\dir\subdir\Test\TestComponent.cshtml) - elem + HtmlAttribute - (5:0,5 [23] x:\dir\subdir\Test\TestComponent.cshtml) - normal-attr=" - " + CSharpExpressionAttributeValue - (19:0,19 [8] x:\dir\subdir\Test\TestComponent.cshtml) - + LazyIntermediateToken - (21:0,21 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "val" + HtmlAttribute - (28:0,28 [15] x:\dir\subdir\Test\TestComponent.cshtml) - minimized-attr - + HtmlAttribute - (43:0,43 [22] x:\dir\subdir\Test\TestComponent.cshtml) - empty-string-atttr=" - " diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.mappings.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.mappings.txt new file mode 100644 index 000000000000..35f1e0834bea --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.mappings.txt @@ -0,0 +1,5 @@ +Source Location: (21:0,21 [5] x:\dir\subdir\Test\TestComponent.cshtml) +|"val"| +Generated Location: (893:25,21 [5] ) +|"val"| + diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.codegen.cs new file mode 100644 index 000000000000..c99a988b7609 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.codegen.cs @@ -0,0 +1,33 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Components; + public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __builder.OpenElement(0, "elem"); + __builder.AddAttribute(1, "normal-attr", +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + "val" + +#line default +#line hidden +#nullable disable + ); + __builder.AddAttribute(2, "minimized-attr", true); + __builder.AddAttribute(3, "empty-string-atttr", true); + __builder.CloseElement(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.ir.txt new file mode 100644 index 000000000000..77da360ab01a --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/IncludesMinimizedAttributeValueParameterBeforeLanguageVersion5/TestComponent.ir.txt @@ -0,0 +1,15 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components + ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree + MarkupElement - (0:0,0 [73] x:\dir\subdir\Test\TestComponent.cshtml) - elem + HtmlAttribute - (5:0,5 [23] x:\dir\subdir\Test\TestComponent.cshtml) - normal-attr=" - " + CSharpExpressionAttributeValue - (19:0,19 [8] x:\dir\subdir\Test\TestComponent.cshtml) - + LazyIntermediateToken - (21:0,21 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "val" + HtmlAttribute - (28:0,28 [15] x:\dir\subdir\Test\TestComponent.cshtml) - minimized-attr - + HtmlAttribute - (43:0,43 [22] x:\dir\subdir\Test\TestComponent.cshtml) - empty-string-atttr=" - " diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.codegen.cs new file mode 100644 index 000000000000..81d863fb9207 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.codegen.cs @@ -0,0 +1,33 @@ +// +#pragma warning disable 1591 +namespace Test +{ + #line hidden + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Components; + public partial class TestComponent : Microsoft.AspNetCore.Components.ComponentBase + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) + { + __builder.OpenElement(0, "elem"); + __builder.AddAttribute(1, "normal-attr", +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + "val" + +#line default +#line hidden +#nullable disable + ); + __builder.AddAttribute(2, "minimized-attr"); + __builder.AddAttribute(3, "empty-string-atttr"); + __builder.CloseElement(); + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.ir.txt new file mode 100644 index 000000000000..77da360ab01a --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/OmitsMinimizedAttributeValueParameter/TestComponent.ir.txt @@ -0,0 +1,15 @@ +Document - + NamespaceDeclaration - - Test + UsingDirective - (3:1,1 [14] ) - System + UsingDirective - (18:2,1 [34] ) - System.Collections.Generic + UsingDirective - (53:3,1 [19] ) - System.Linq + UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks + UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components + ClassDeclaration - - public partial - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree + MarkupElement - (0:0,0 [73] x:\dir\subdir\Test\TestComponent.cshtml) - elem + HtmlAttribute - (5:0,5 [23] x:\dir\subdir\Test\TestComponent.cshtml) - normal-attr=" - " + CSharpExpressionAttributeValue - (19:0,19 [8] x:\dir\subdir\Test\TestComponent.cshtml) - + LazyIntermediateToken - (21:0,21 [5] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "val" + HtmlAttribute - (28:0,28 [15] x:\dir\subdir\Test\TestComponent.cshtml) - minimized-attr - + HtmlAttribute - (43:0,43 [22] x:\dir\subdir\Test\TestComponent.cshtml) - empty-string-atttr=" - "