diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorIntermediateNodeLoweringPhase.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorIntermediateNodeLoweringPhase.cs index e573f61001..cfefed3b4a 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorIntermediateNodeLoweringPhase.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorIntermediateNodeLoweringPhase.cs @@ -473,7 +473,7 @@ namespace Microsoft.AspNetCore.Razor.Language var name = node.Name.GetContent(); if (name.StartsWith("data-", StringComparison.OrdinalIgnoreCase) && - !_featureFlags.EXPERIMENTAL_AllowConditionalDataDashAttributes) + !_featureFlags.AllowConditionalDataDashAttributes) { Visit(prefix); Visit(node.Value); @@ -518,7 +518,7 @@ namespace Microsoft.AspNetCore.Razor.Language { var name = node.Name.GetContent(); if (name.StartsWith("data-", StringComparison.OrdinalIgnoreCase) && - !_featureFlags.EXPERIMENTAL_AllowConditionalDataDashAttributes) + !_featureFlags.AllowConditionalDataDashAttributes) { base.VisitMarkupMinimizedAttributeBlock(node); return; diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorParserOptions.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorParserOptions.cs index b6156641b5..0966f0eb74 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorParserOptions.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorParserOptions.cs @@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Razor.Language DesignTime = designTime; ParseLeadingDirectives = parseLeadingDirectives; Version = version; - FeatureFlags = RazorParserFeatureFlags.Create(Version); + FeatureFlags = RazorParserFeatureFlags.Create(Version, fileKind); FileKind = fileKind; } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorParserOptionsBuilder.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorParserOptionsBuilder.cs index e19a4d1660..6ba46844b8 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorParserOptionsBuilder.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/DefaultRazorParserOptionsBuilder.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Razor.Language public override RazorParserOptions Build() { - return new DefaultRazorParserOptions(Directives.ToArray(), DesignTime, ParseLeadingDirectives, LanguageVersion, FileKind); + return new DefaultRazorParserOptions(Directives.ToArray(), DesignTime, ParseLeadingDirectives, LanguageVersion, FileKind ?? FileKinds.Legacy); } public override void SetDesignTime(bool designTime) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/HtmlMarkupParser.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/HtmlMarkupParser.cs index e66b9c531c..8e58813518 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/HtmlMarkupParser.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Legacy/HtmlMarkupParser.cs @@ -1923,10 +1923,17 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy private bool IsConditionalAttributeName(string name) { - var attributeCanBeConditional = - Context.FeatureFlags.EXPERIMENTAL_AllowConditionalDataDashAttributes || - !name.StartsWith("data-", StringComparison.OrdinalIgnoreCase); - return attributeCanBeConditional; + if (Context.FeatureFlags.AllowConditionalDataDashAttributes) + { + return true; + } + + if (!name.StartsWith("data-", StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + return false; } private void NestingBlock(in SyntaxListBuilder builder, Tuple nestingSequences) diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorParserFeatureFlags.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorParserFeatureFlags.cs index b32eee459b..9c8fd6276f 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorParserFeatureFlags.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorParserFeatureFlags.cs @@ -1,18 +1,25 @@ // 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; + namespace Microsoft.AspNetCore.Razor.Language { internal abstract class RazorParserFeatureFlags { - public static RazorParserFeatureFlags Create(RazorLanguageVersion version) + public static RazorParserFeatureFlags Create(RazorLanguageVersion version, string fileKind) { + if (fileKind == null) + { + throw new ArgumentNullException(nameof(fileKind)); + } + var allowMinimizedBooleanTagHelperAttributes = false; var allowHtmlCommentsInTagHelpers = false; var allowComponentFileKind = false; var allowRazorInAllCodeBlocks = false; var allowUsingVariableDeclarations = false; - var experimental_AllowConditionalDataDashAttributes = false; + var allowConditionalDataDashAttributes = false; if (version.CompareTo(RazorLanguageVersion.Version_2_1) >= 0) { @@ -29,9 +36,14 @@ namespace Microsoft.AspNetCore.Razor.Language allowUsingVariableDeclarations = true; } + if (FileKinds.IsComponent(fileKind)) + { + allowConditionalDataDashAttributes = true; + } + if (version.CompareTo(RazorLanguageVersion.Experimental) >= 0) { - experimental_AllowConditionalDataDashAttributes = true; + allowConditionalDataDashAttributes = true; } return new DefaultRazorParserFeatureFlags( @@ -40,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Language allowComponentFileKind, allowRazorInAllCodeBlocks, allowUsingVariableDeclarations, - experimental_AllowConditionalDataDashAttributes); + allowConditionalDataDashAttributes); } public abstract bool AllowMinimizedBooleanTagHelperAttributes { get; } @@ -53,7 +65,7 @@ namespace Microsoft.AspNetCore.Razor.Language public abstract bool AllowUsingVariableDeclarations { get; } - public abstract bool EXPERIMENTAL_AllowConditionalDataDashAttributes { get; } + public abstract bool AllowConditionalDataDashAttributes { get; } private class DefaultRazorParserFeatureFlags : RazorParserFeatureFlags { @@ -63,14 +75,14 @@ namespace Microsoft.AspNetCore.Razor.Language bool allowComponentFileKind, bool allowRazorInAllCodeBlocks, bool allowUsingVariableDeclarations, - bool experimental_AllowConditionalDataDashAttributes) + bool allowConditionalDataDashAttributesInComponents) { AllowMinimizedBooleanTagHelperAttributes = allowMinimizedBooleanTagHelperAttributes; AllowHtmlCommentsInTagHelpers = allowHtmlCommentsInTagHelpers; AllowComponentFileKind = allowComponentFileKind; AllowRazorInAllCodeBlocks = allowRazorInAllCodeBlocks; AllowUsingVariableDeclarations = allowUsingVariableDeclarations; - EXPERIMENTAL_AllowConditionalDataDashAttributes = experimental_AllowConditionalDataDashAttributes; + AllowConditionalDataDashAttributes = allowConditionalDataDashAttributesInComponents; } public override bool AllowMinimizedBooleanTagHelperAttributes { get; } @@ -83,7 +95,7 @@ namespace Microsoft.AspNetCore.Razor.Language public override bool AllowUsingVariableDeclarations { get; } - public override bool EXPERIMENTAL_AllowConditionalDataDashAttributes { get; } + public override bool AllowConditionalDataDashAttributes { get; } } } } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorParserOptions.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorParserOptions.cs index cb0781b666..f59d8fd797 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorParserOptions.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/src/RazorParserOptions.cs @@ -15,12 +15,12 @@ namespace Microsoft.AspNetCore.Razor.Language designTime: false, parseLeadingDirectives: false, version: RazorLanguageVersion.Latest, - fileKind: null); + fileKind: FileKinds.Legacy); } public static RazorParserOptions Create(Action configure) { - return Create(configure, fileKind: null); + return Create(configure, fileKind: FileKinds.Legacy); } public static RazorParserOptions Create(Action configure, string fileKind) @@ -30,7 +30,7 @@ namespace Microsoft.AspNetCore.Razor.Language throw new ArgumentNullException(nameof(configure)); } - var builder = new DefaultRazorParserOptionsBuilder(designTime: false, version: RazorLanguageVersion.Latest, fileKind); + var builder = new DefaultRazorParserOptionsBuilder(designTime: false, version: RazorLanguageVersion.Latest, fileKind ?? FileKinds.Legacy); configure(builder); var options = builder.Build(); @@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Razor.Language throw new ArgumentNullException(nameof(configure)); } - var builder = new DefaultRazorParserOptionsBuilder(designTime: true, version: RazorLanguageVersion.Latest, fileKind); + var builder = new DefaultRazorParserOptionsBuilder(designTime: true, version: RazorLanguageVersion.Latest, fileKind ?? FileKinds.Legacy); configure(builder); var options = builder.Build(); 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 43381c1a29..7f76f8cdd4 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -2852,6 +2852,27 @@ namespace Test.Shared CompileToAssembly(generated); } + [Fact] + public void Element_WithRef_AndOtherAttributes() + { + // Arrange/Act + var generated = CompileToCSharp(@" + + +@functions { + private ElementRef _element; + + [Parameter] protected int Min { get; set; } + public void Foo() { System.GC.KeepAlive(_element); } + } +"); + + // Assert + AssertDocumentNodeMatchesBaseline(generated.CodeDocument); + AssertCSharpDocumentMatchesBaseline(generated.CodeDocument); + CompileToAssembly(generated); + } + [Fact] public void Component_WithRef() { diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/Legacy/TagHelperBlockRewriterTest.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/Legacy/TagHelperBlockRewriterTest.cs index c2a2e7356c..82b69cddbc 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/Legacy/TagHelperBlockRewriterTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/Legacy/TagHelperBlockRewriterTest.cs @@ -2161,14 +2161,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy bool allowComponentFileKind = false, bool allowRazorInCodeBlockDirectives = false, bool allowUsingVariableDeclarations = false, - bool experimental_AllowConditionalDataDashAttributes = false) + bool allowConditionalDataDashAttributesInComponents = false) { AllowMinimizedBooleanTagHelperAttributes = allowMinimizedBooleanTagHelperAttributes; AllowHtmlCommentsInTagHelpers = allowHtmlCommentsInTagHelper; AllowComponentFileKind = allowComponentFileKind; AllowRazorInAllCodeBlocks = allowRazorInCodeBlockDirectives; AllowUsingVariableDeclarations = allowUsingVariableDeclarations; - EXPERIMENTAL_AllowConditionalDataDashAttributes = experimental_AllowConditionalDataDashAttributes; + AllowConditionalDataDashAttributes = allowConditionalDataDashAttributesInComponents; } public override bool AllowMinimizedBooleanTagHelperAttributes { get; } @@ -2181,7 +2181,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy public override bool AllowUsingVariableDeclarations { get; } - public override bool EXPERIMENTAL_AllowConditionalDataDashAttributes { get; } + public override bool AllowConditionalDataDashAttributes { get; } } } } diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/Legacy/TagHelperParseTreeRewriterTest.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/Legacy/TagHelperParseTreeRewriterTest.cs index e68eed561a..ef3603fa90 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/Legacy/TagHelperParseTreeRewriterTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/Legacy/TagHelperParseTreeRewriterTest.cs @@ -734,7 +734,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy EvaluateData( descriptors, document, - featureFlags: RazorParserFeatureFlags.Create(RazorLanguageVersion.Version_2_0)); + featureFlags: RazorParserFeatureFlags.Create(RazorLanguageVersion.Version_2_0, FileKinds.Legacy)); } [Fact] diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/RazorParserFeatureFlagsTest.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/RazorParserFeatureFlagsTest.cs index cfdb9f023d..f693b4261a 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/RazorParserFeatureFlagsTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/RazorParserFeatureFlagsTest.cs @@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Razor.Language public void Create_LatestVersion_AllowsMinimizedBooleanTagHelperAttributes() { // Arrange & Act - var context = RazorParserFeatureFlags.Create(RazorLanguageVersion.Version_2_1); + var context = RazorParserFeatureFlags.Create(RazorLanguageVersion.Version_2_1, FileKinds.Legacy); // Assert Assert.True(context.AllowMinimizedBooleanTagHelperAttributes); @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Razor.Language public void Create_OlderVersion_DoesNotAllowMinimizedBooleanTagHelperAttributes() { // Arrange & Act - var context = RazorParserFeatureFlags.Create(RazorLanguageVersion.Version_1_1); + var context = RazorParserFeatureFlags.Create(RazorLanguageVersion.Version_1_1, FileKinds.Legacy); // Assert Assert.False(context.AllowMinimizedBooleanTagHelperAttributes); diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/DataDashAttribute_ExplicitExpression/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/DataDashAttribute_ExplicitExpression/TestComponent.ir.txt index b5c72064d4..d46e2e25e2 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/DataDashAttribute_ExplicitExpression/TestComponent.ir.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/DataDashAttribute_ExplicitExpression/TestComponent.ir.txt @@ -18,8 +18,10 @@ Document - IntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n var myValue = "Expression value";\n MarkupElement - (45:3,0 [55] x:\dir\subdir\Test\TestComponent.cshtml) - elem HtmlAttribute - (50:3,5 [25] x:\dir\subdir\Test\TestComponent.cshtml) - data-abc=" - " - HtmlAttributeValue - (61:3,16 [13] x:\dir\subdir\Test\TestComponent.cshtml) - - IntermediateToken - (61:3,16 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Literal value + HtmlAttributeValue - (61:3,16 [7] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (61:3,16 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Literal + HtmlAttributeValue - (68:3,23 [6] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (69:3,24 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - value HtmlAttribute - (75:3,30 [22] x:\dir\subdir\Test\TestComponent.cshtml) - data-def=" - " CSharpExpressionAttributeValue - (86:3,41 [10] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (88:3,43 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - myValue diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/DataDashAttribute_ImplicitExpression/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/DataDashAttribute_ImplicitExpression/TestComponent.ir.txt index 71b7af99e9..afb6766d6a 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/DataDashAttribute_ImplicitExpression/TestComponent.ir.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/DataDashAttribute_ImplicitExpression/TestComponent.ir.txt @@ -18,8 +18,10 @@ Document - IntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n var myValue = "Expression value";\n MarkupElement - (45:3,0 [53] x:\dir\subdir\Test\TestComponent.cshtml) - elem HtmlAttribute - (50:3,5 [25] x:\dir\subdir\Test\TestComponent.cshtml) - data-abc=" - " - HtmlAttributeValue - (61:3,16 [13] x:\dir\subdir\Test\TestComponent.cshtml) - - IntermediateToken - (61:3,16 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Literal value + HtmlAttributeValue - (61:3,16 [7] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (61:3,16 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Literal + HtmlAttributeValue - (68:3,23 [6] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (69:3,24 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - value HtmlAttribute - (75:3,30 [20] x:\dir\subdir\Test\TestComponent.cshtml) - data-def=" - " CSharpExpressionAttributeValue - (86:3,41 [8] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (87:3,42 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - myValue diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.codegen.cs new file mode 100644 index 0000000000..c641fbe40a --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.codegen.cs @@ -0,0 +1,55 @@ +// +#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 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.RenderTree.RenderTreeBuilder builder) + { + __o = +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + Min + +#line default +#line hidden +#nullable disable + ; +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + _element = default(Microsoft.AspNetCore.Components.ElementRef); + +#line default +#line hidden +#nullable disable + } + #pragma warning restore 1998 +#nullable restore +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + private ElementRef _element; + + [Parameter] protected int Min { get; set; } + public void Foo() { System.GC.KeepAlive(_element); } + + +#line default +#line hidden +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.ir.txt new file mode 100644 index 0000000000..1272ebf797 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.ir.txt @@ -0,0 +1,30 @@ +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 - 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 [60] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - - type=" - " + HtmlAttributeValue - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - text + HtmlAttribute - - data-slider-min=" - " + CSharpExpressionAttributeValue - (36:0,36 [4] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (37:0,37 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Min + ReferenceCapture - (48:0,48 [8] x:\dir\subdir\Test\TestComponent.cshtml) - _element + HtmlContent - (60:0,60 [4] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (60:0,60 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n + HtmlContent - (238:7,5 [2] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (238:7,5 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n + CSharpCode - (76:2,12 [161] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (76:2,12 [161] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private ElementRef _element;\n\n [Parameter] protected int Min { get; set; }\n public void Foo() { System.GC.KeepAlive(_element); }\n diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.mappings.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.mappings.txt new file mode 100644 index 0000000000..4e1d9dd4ab --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.mappings.txt @@ -0,0 +1,25 @@ +Source Location: (37:0,37 [3] x:\dir\subdir\Test\TestComponent.cshtml) +|Min| +Generated Location: (900:25,37 [3] ) +|Min| + +Source Location: (48:0,48 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|_element| +Generated Location: (1088:33,48 [8] ) +|_element| + +Source Location: (76:2,12 [161] x:\dir\subdir\Test\TestComponent.cshtml) +| + private ElementRef _element; + + [Parameter] protected int Min { get; set; } + public void Foo() { System.GC.KeepAlive(_element); } + | +Generated Location: (1334:42,12 [161] ) +| + private ElementRef _element; + + [Parameter] protected int Min { get; set; } + public void Foo() { System.GC.KeepAlive(_element); } + | + diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/DataDashAttribute_ExplicitExpression/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/DataDashAttribute_ExplicitExpression/TestComponent.ir.txt index 14ed266826..854427f5fd 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/DataDashAttribute_ExplicitExpression/TestComponent.ir.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/DataDashAttribute_ExplicitExpression/TestComponent.ir.txt @@ -11,8 +11,10 @@ Document - IntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n var myValue = "Expression value";\n MarkupElement - (45:3,0 [55] x:\dir\subdir\Test\TestComponent.cshtml) - elem HtmlAttribute - (50:3,5 [25] x:\dir\subdir\Test\TestComponent.cshtml) - data-abc=" - " - HtmlAttributeValue - (61:3,16 [13] x:\dir\subdir\Test\TestComponent.cshtml) - - IntermediateToken - (61:3,16 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Literal value + HtmlAttributeValue - (61:3,16 [7] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (61:3,16 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Literal + HtmlAttributeValue - (68:3,23 [6] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (69:3,24 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - value HtmlAttribute - (75:3,30 [22] x:\dir\subdir\Test\TestComponent.cshtml) - data-def=" - " CSharpExpressionAttributeValue - (86:3,41 [10] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (88:3,43 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - myValue diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/DataDashAttribute_ImplicitExpression/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/DataDashAttribute_ImplicitExpression/TestComponent.ir.txt index 9e4677a6ca..0ccf3f8fed 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/DataDashAttribute_ImplicitExpression/TestComponent.ir.txt +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/DataDashAttribute_ImplicitExpression/TestComponent.ir.txt @@ -11,8 +11,10 @@ Document - IntermediateToken - (2:0,2 [40] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n var myValue = "Expression value";\n MarkupElement - (45:3,0 [53] x:\dir\subdir\Test\TestComponent.cshtml) - elem HtmlAttribute - (50:3,5 [25] x:\dir\subdir\Test\TestComponent.cshtml) - data-abc=" - " - HtmlAttributeValue - (61:3,16 [13] x:\dir\subdir\Test\TestComponent.cshtml) - - IntermediateToken - (61:3,16 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Literal value + HtmlAttributeValue - (61:3,16 [7] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (61:3,16 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Literal + HtmlAttributeValue - (68:3,23 [6] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (69:3,24 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - value HtmlAttribute - (75:3,30 [20] x:\dir\subdir\Test\TestComponent.cshtml) - data-def=" - " CSharpExpressionAttributeValue - (86:3,41 [8] x:\dir\subdir\Test\TestComponent.cshtml) - IntermediateToken - (87:3,42 [7] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - myValue diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.codegen.cs b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.codegen.cs new file mode 100644 index 0000000000..cd5160e5d0 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.codegen.cs @@ -0,0 +1,54 @@ +// +#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 class TestComponent : Microsoft.AspNetCore.Components.ComponentBase + { + #pragma warning disable 1998 + protected override void BuildRenderTree(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder) + { + builder.OpenElement(0, "input"); + builder.AddAttribute(1, "type", "text"); + builder.AddAttribute(2, "data-slider-min", +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + Min + +#line default +#line hidden +#nullable disable + ); + builder.AddElementReferenceCapture(3, (__value) => { +#nullable restore +#line 1 "x:\dir\subdir\Test\TestComponent.cshtml" + _element = __value; + +#line default +#line hidden +#nullable disable + } + ); + builder.CloseElement(); + } + #pragma warning restore 1998 +#nullable restore +#line 3 "x:\dir\subdir\Test\TestComponent.cshtml" + + private ElementRef _element; + + [Parameter] protected int Min { get; set; } + public void Foo() { System.GC.KeepAlive(_element); } + + +#line default +#line hidden +#nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.ir.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.ir.txt new file mode 100644 index 0000000000..ccb80d69fd --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.ir.txt @@ -0,0 +1,19 @@ +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 - TestComponent - Microsoft.AspNetCore.Components.ComponentBase - + MethodDeclaration - - protected override - void - BuildRenderTree + MarkupElement - (0:0,0 [60] x:\dir\subdir\Test\TestComponent.cshtml) - input + HtmlAttribute - - type=" - " + HtmlAttributeValue - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - text + HtmlAttribute - - data-slider-min=" - " + CSharpExpressionAttributeValue - (36:0,36 [4] x:\dir\subdir\Test\TestComponent.cshtml) - + IntermediateToken - (37:0,37 [3] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - Min + ReferenceCapture - (48:0,48 [8] x:\dir\subdir\Test\TestComponent.cshtml) - _element + CSharpCode - (76:2,12 [161] x:\dir\subdir\Test\TestComponent.cshtml) + IntermediateToken - (76:2,12 [161] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - \n private ElementRef _element;\n\n [Parameter] protected int Min { get; set; }\n public void Foo() { System.GC.KeepAlive(_element); }\n diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.mappings.txt b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.mappings.txt new file mode 100644 index 0000000000..d89985d042 --- /dev/null +++ b/src/Razor/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/Element_WithRef_AndOtherAttributes/TestComponent.mappings.txt @@ -0,0 +1,20 @@ +Source Location: (48:0,48 [8] x:\dir\subdir\Test\TestComponent.cshtml) +|_element| +Generated Location: (1024:29,48 [8] ) +|_element| + +Source Location: (76:2,12 [161] x:\dir\subdir\Test\TestComponent.cshtml) +| + private ElementRef _element; + + [Parameter] protected int Min { get; set; } + public void Foo() { System.GC.KeepAlive(_element); } + | +Generated Location: (1294:41,12 [161] ) +| + private ElementRef _element; + + [Parameter] protected int Min { get; set; } + public void Foo() { System.GC.KeepAlive(_element); } + | + diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/Legacy/ParserTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/Legacy/ParserTestBase.cs index 15b9138276..8ed5fc2121 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/Legacy/ParserTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/Legacy/ParserTestBase.cs @@ -254,12 +254,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy designTime, parseLeadingDirectives: false, version: version, + fileKind: FileKinds.Legacy, featureFlags: featureFlags); } private class TestRazorParserOptions : RazorParserOptions { - public TestRazorParserOptions(DirectiveDescriptor[] directives, bool designTime, bool parseLeadingDirectives, RazorLanguageVersion version, RazorParserFeatureFlags featureFlags = null) + public TestRazorParserOptions(DirectiveDescriptor[] directives, bool designTime, bool parseLeadingDirectives, RazorLanguageVersion version, string fileKind, RazorParserFeatureFlags featureFlags = null) { if (directives == null) { @@ -270,11 +271,14 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy DesignTime = designTime; ParseLeadingDirectives = parseLeadingDirectives; Version = version; - FeatureFlags = featureFlags ?? RazorParserFeatureFlags.Create(Version); + FileKind = fileKind; + FeatureFlags = featureFlags ?? RazorParserFeatureFlags.Create(Version, fileKind); } public override bool DesignTime { get; } + internal override string FileKind { get; } + public override IReadOnlyCollection Directives { get; } public override bool ParseLeadingDirectives { get; }